Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Oracle unit tests #181

Merged
merged 4 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions generator/generators/oracle/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ exports.generateOracleClass = exports.extractSDKData = void 0;
var fs = require('fs');
var typescript_1 = require('typescript');
var parser_1 = require('../../parsers/oracle/parser');
var helper_1 = require('../lib/helper');
var transformer_1 = require('../../transformers/oracle/transformer');
var helper_1 = require('../lib/helper');
var dummyFile = process.cwd() + '/dummyClasses/oracle.js';
var dummyAst = typescript_1.createSourceFile(
dummyFile,
Expand Down Expand Up @@ -197,14 +197,12 @@ function extractSDKData(sdkClassAst, serviceClass) {
functions: methods,
serviceName: null,
};
console.log(classData);
return classData;
}
exports.extractSDKData = extractSDKData;
function generateOracleClass(serviceClass, serviceName) {
var _this = this;
var sdkFile = serviceClass[Object.keys(serviceClass)[0]].split(' ')[0];
console.log(sdkFile);
parser_1.getAST(sdkFile).then(function(result) {
return __awaiter(_this, void 0, void 0, function() {
var sdkClassAst, classData, output, filePath, dir, error_1;
Expand All @@ -217,6 +215,7 @@ function generateOracleClass(serviceClass, serviceName) {
_a.trys.push([1, 3, , 4]);
classData = extractSDKData(sdkClassAst, serviceClass);
classData.serviceName = serviceName;
console.log(JSON.stringify(classData));
return [
4 /*yield*/,
transformer_1.transform(dummyAst, classData),
Expand Down
4 changes: 3 additions & 1 deletion generator/generators/oracle/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export function extractSDKData(sdkClassAst, serviceClass) {

export function generateOracleClass(serviceClass, serviceName) {
const sdkFile = serviceClass[Object.keys(serviceClass)[0]].split(' ')[0];
console.log(sdkFile);
getAST(sdkFile).then(async result => {
const sdkClassAst = result;
try {
Expand All @@ -91,7 +90,10 @@ export function generateOracleClass(serviceClass, serviceName) {
serviceClass
);
classData.serviceName = serviceName;
console.log(JSON.stringify(classData));

const output = await transform(dummyAst, classData);

let filePath;
const dir = getDir(serviceName);
if (
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"create": "loadbalancer createLoadBalancer",
"delete": "loadbalancer",
"get": "loadbalancer getLoadBalancer",
"update": "loadbalancer updateLoadBalancer",
"list": "loadbalancer listLoadBalancers"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import common = require("oci-common");
import * as requests from "./request";
import * as model from "./model";
import * as responses from "./response";
import { LoadBalancerWaiter } from "./loadbalancer-waiter";
export declare enum LoadBalancerApiKeys {
}
/**
* This service client uses {@link common.CircuitBreaker.DefaultConfiguration} for all the operations by default if no circuit breaker configuration is defined by the user.
*/
export declare class LoadBalancerClient {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"create": "loadbalancer createLoadBalancer",
"delete": "loadbalancer deleteLoadBalancer",
"get": "loadbalancer getLoadBalancer",
"update": "loadbalancer updateLoadBalancer",
"list": "loadbalancer listLoadBalancers"
}
926 changes: 926 additions & 0 deletions generator/test/generators/oracle/dummyData/validDataset/sdkFile.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"create": "loadbalancer createLoadBalancer",
"delete": "loadbalancer deleteLoadBalancer",
"get": "loadbalancer getLoadBalancer",
"update": "loadbalancer updateLoadBalancer",
"list": "loadbalancer listLoadBalancers"
}
92 changes: 92 additions & 0 deletions generator/test/generators/oracle/generator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { expect } from 'chai';
import { SyntaxKind } from 'typescript';

import { extractSDKData } from '../../../generators/oracle/generator';
import { readJsonData, readSourceFile } from '../lib/helper';

describe('Oracle generator extractSDKData', () => {
context('with valid methods and valid AST', () => {
it('should return extracted class data', async () => {
const sdkFile: any = await readSourceFile('validDataset', 'oracle');
const data: any = await readJsonData(
'validDataset',
'oracle',
'serviceClass'
);
let cloned = null;
sdkFile.forEachChild(child => {
if (SyntaxKind[child.kind] === 'ClassDeclaration') {
cloned = Object.assign({}, child);
}
});

if (cloned) {
const result = extractSDKData(cloned, data);
expect(result).to.be.an('object');
expect(result.functions).to.be.an('array');
expect(result.className).to.be.string;
} else {
console.error('Error in cloning class');
}
});
});

context('with invalid method data:missing method name', () => {
it('should drop invalid method', async () => {
const sdkFile: any = await readSourceFile(
'invalidDataset_1',
'oracle'
);
const data: any = await readJsonData(
'invalidDataset_1',
'oracle',
'serviceClass'
);
let cloned = null;
sdkFile.forEachChild(child => {
if (SyntaxKind[child.kind] === 'ClassDeclaration') {
cloned = Object.assign({}, child);
}
});

if (cloned) {
expect(
extractSDKData(cloned, data).functions.length <
Object.keys(data).length
).to.be.true;
} else {
console.error('Error in cloning class');
}
});
});

context('Oracle with no functions', () => {
it('should return empty array of methods', async () => {
const sdkFile: any = await readSourceFile(
'invalidDataset_2',
'oracle'
);
const data: any = await readJsonData(
'invalidDataset_2',
'oracle',
'serviceClass'
);
let cloned = null;
sdkFile.forEachChild(child => {
if (SyntaxKind[child.kind] === 'ClassDeclaration') {
cloned = Object.assign({}, child);
}
});

if (cloned) {
const result = extractSDKData(cloned, data);
expect(result).to.be.an('object');
expect(result.functions).to.be.an('array');
expect(result.className).to.be.string;
expect(result.functions.length).to.eql(0);
} else {
console.error('Error in cloning class');
}
});
});
});
35 changes: 35 additions & 0 deletions generator/test/parsers/oracle/parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect } from 'chai';
import { SyntaxKind } from 'typescript';

import { getAST } from '../../../parsers/oracle/parser';

describe('Oracle Cloud parser getAST', () => {
context('With existing file', () => {
it('Should return Abstract syntax tree of the class', async () => {
const ast: any = await getAST('objectstorage');
expect(ast).to.be.an('object');
expect(SyntaxKind[ast.kind] === 'ClassDeclaration').to.be.true;
});
});

context('With non-existing file', () => {
it('should return File not found Error', async () => {
try {
await getAST('unknown');
} catch (error) {
expect(error.message).to.eql('File not found!');
}
});
});

context('With wrong format file', () => {
it('Should return class not found Error', async () => {
try {
await getAST('objectstorage');
// `../../../node_modules/oci-${sdkFileName.toLowerCase()}/lib/client.d.ts`
} catch (error) {
expect(error.message).to.eql('Class not found!');
}
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"className": "ObjectStorageClient",
"functions": [
{
"functionName": "create",
"SDKFunctionName": "createBucket",
"params": [
{
"name": "createBucketRequest",
"optional": false,
"type": "TypeReference",
"typeName": "CreateBucketRequest"
}
]
},
{
"functionName": "delete",
"SDKFunctionName": "deleteBucket",
"params": [
{
"name": "deleteBucketRequest",
"optional": false,
"type": "TypeReference",
"typeName": "DeleteBucketRequest"
}
]
},
{
"functionName": "list",
"SDKFunctionName": "listBuckets",
"params": [
{
"name": "listBucketsRequest",
"optional": false,
"type": "TypeReference",
"typeName": "ListBucketsRequest"
}
]
},
{
"functionName": "update",
"SDKFunctionName": "updateBucket",
"params": [
{
"name": "updateBucketRequest",
"optional": false,
"type": "TypeReference",
"typeName": "UpdateBucketRequest"
}
]
}
],
"serviceName": "ArchivalStorage"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ClassName {
constructor(ocisdk, params, clientConfiguration) {
this._oci = ocisdk;
this._sdkclassName = this._oci.SDKClassName(
params,
clientConfiguration
);
}
}

module.exports = ClassName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"functions": [
{
"functionName": "create",
"SDKFunctionName": "createBucket",
"params": [
{
"name": "createBucketRequest",
"optional": false,
"type": "TypeReference",
"typeName": "CreateBucketRequest"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ClassName {
constructor(ocisdk, params, clientConfiguration) {
this._oci = ocisdk;
this._sdkclassName = this._oci.SDKClassName(
params,
clientConfiguration
);
}

function() {
return new Promise((resolve, reject) => {
this._sdkClassName
.SDKFunctionName()
.then(data => resolve(data))
.catch(err => reject(err));
});
}
}

module.exports = ClassName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"className": "ObjectStorageClient",
"functions": [
{
"functionName": "create",
"SDKFunctionName": "createBucket",
"params": [
{
"name": "createBucketRequest",
"optional": false,
"type": "TypeReference",
"typeName": "CreateBucketRequest"
}
]
},
{
"functionName": "delete",
"SDKFunctionName": "deleteBucket",
"params": [
{
"name": "deleteBucketRequest",
"optional": false,
"type": "TypeReference",
"typeName": "DeleteBucketRequest"
}
]
},
{
"functionName": "list",
"SDKFunctionName": "listBuckets",
"params": [
{
"name": "listBucketsRequest",
"optional": false,
"type": "TypeReference",
"typeName": "ListBucketsRequest"
}
]
},
{
"functionName": "update",
"SDKFunctionName": "updateBucket",
"params": [
{
"name": "updateBucketRequest",
"optional": false,
"type": "TypeReference",
"typeName": "UpdateBucketRequest"
}
]
}
],
"serviceName": "ArchivalStorage"
}
Loading