-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from partik03/oracle_tests
Added Oracle unit tests
- Loading branch information
Showing
17 changed files
with
2,266 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
926 changes: 926 additions & 0 deletions
926
generator/test/generators/oracle/dummyData/invalidDataset_1/sdkFile.txt
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
generator/test/generators/oracle/dummyData/invalidDataset_1/serviceClass.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
12 changes: 12 additions & 0 deletions
12
generator/test/generators/oracle/dummyData/invalidDataset_2/sdkFile.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
7 changes: 7 additions & 0 deletions
7
generator/test/generators/oracle/dummyData/invalidDataset_2/serviceClass.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
926
generator/test/generators/oracle/dummyData/validDataset/sdkFile.txt
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
generator/test/generators/oracle/dummyData/validDataset/serviceClass.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); | ||
} | ||
}); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
generator/test/transformers/oracle/dummyData/invalidDataset_1/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
11 changes: 11 additions & 0 deletions
11
generator/test/transformers/oracle/dummyData/invalidDataset_1/sourceFile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
16 changes: 16 additions & 0 deletions
16
generator/test/transformers/oracle/dummyData/invalidDataset_2/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} | ||
] | ||
} |
20 changes: 20 additions & 0 deletions
20
generator/test/transformers/oracle/dummyData/invalidDataset_2/sourceFile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
54 changes: 54 additions & 0 deletions
54
generator/test/transformers/oracle/dummyData/validDataset/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.