Skip to content

Commit c9f7a93

Browse files
authored
Merge pull request #100 from mbcse/generator_testing
Added tests for Digital Ocean generator
2 parents de656e0 + 065878a commit c9f7a93

File tree

7 files changed

+298
-0
lines changed

7 files changed

+298
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import RequestHelper from "../request-helper";
2+
import { BaseModule } from "./base-module";
3+
import { ClusterNodePool, ClusterNodePoolUpdateOptions, NewClusterRequest } from "../types/kubernetes";
4+
export default class Kubernetes extends BaseModule {
5+
private basePath;
6+
private baseOptions;
7+
constructor(pageSize: number, requestHelper: RequestHelper);
8+
/**
9+
* Get the Kubernetes Feature Availability
10+
* @returns Promise
11+
*/
12+
getAvailability(): Promise<any>;
13+
/**
14+
* Get all Kubernetes Clusters
15+
* @param [includeAll] return all Kubernetes Clusters, paginated (optional)
16+
* @param [page] the specific page of Kubernetes Clusters to return (optional)
17+
* @param [pageSize] the number of Kubernetes Clusters to return per page (optional)
18+
* @returns Promise
19+
*/
20+
getClusters(includeAll?: boolean, page?: number, pageSize?: number): Promise<any>;
21+
/**
22+
* Create a new Kubernetes Cluster
23+
* @param options the options for the new Kubernetes Cluster
24+
* @returns Promise
25+
*/
26+
create(options: NewClusterRequest): Promise<any>;
27+
/**
28+
* Get a Kubernetes Cluster by its identifier
29+
* @param clusterId the identifier of the Cluster
30+
* @returns Promise
31+
*/
32+
getById(clusterId: string): Promise<any>;
33+
/**
34+
* Get the kubeconfig for a Kubernetes Cluster
35+
* @param clusterId the identifier of the Cluster
36+
* @returns Promise
37+
*/
38+
getKubeconfig(clusterId: string): Promise<any>;
39+
/**
40+
* Delete a Kubernetes Cluster by its identifier
41+
* @param clusterId the identifier of the Cluster
42+
* @returns Promise
43+
*/
44+
delete(clusterId: string): Promise<any>;
45+
/**
46+
* Get the Node Pools for a Kubernetes Cluster
47+
* @param clusterId the Cluster identifier
48+
* @param [includeAll] return all Node Pools, paginated (optional)
49+
* @param [page] the specific page of Node Pools to return (optional)
50+
* @param [pageSize] the number of Node Pools to return per page (optional)
51+
* @returns Promise
52+
*/
53+
getNodePools(clusterId: string, includeAll?: boolean, page?: number, pageSize?: number): Promise<any>;
54+
/**
55+
* Get a specific Node Pool for a Kubernetes Cluster
56+
* @param clusterId the identifier of the Cluster
57+
* @param nodePoolId the identifier of the Node Pool
58+
* @returns Promise
59+
*/
60+
getNodePoolById(clusterId: string, nodePoolId: string): Promise<any>;
61+
/**
62+
* Add a Node Pool to a Kubernetes Cluster
63+
* @param clusterId the identifier of the Cluster
64+
* @param nodePool the Node Pool configuration options
65+
* @returns Promise
66+
*/
67+
addNodePool(clusterId: string, nodePool: ClusterNodePool): Promise<any>;
68+
/**
69+
* Update a specific Node Pool for a Kubernetes Cluster
70+
* @param clusterId the identifier of the Cluster
71+
* @param nodePoolId the identifier of the Node Pool
72+
* @param nodePoolOptions the Node Pool options
73+
* @returns Promise
74+
*/
75+
updateNodePool(clusterId: string, nodePoolId: string, nodePoolOptions: ClusterNodePoolUpdateOptions): Promise<any>;
76+
/**
77+
* Delete a Node Pool for a Kubernetes Cluster
78+
* @param clusterId the identifier of the Cluster
79+
* @param nodePoolId the identifier of the Node Pool
80+
* @returns Promise
81+
*/
82+
deleteNodePool(clusterId: string, nodePoolId: string): Promise<any>;
83+
/**
84+
* Recycle a Node Pool on a Cluster
85+
* @param clusterId the identifier of the Cluster
86+
* @param nodePoolId the identifier of the Node Pool
87+
* @returns Promise
88+
*/
89+
recycleNodePool(clusterId: string, nodePoolId: string): Promise<any>;
90+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"create": "kubernetes.d.ts create",
3+
"delete": "kubernetes.d.ts",
4+
"listClusters": "kubernetes.d.ts getClusters",
5+
"createNodeGroup": "kubernetes.d.ts addNodePool",
6+
"deleteNodegroup":" kubernetes.d.ts deleteNodePool",
7+
"listNodegroups": "kubernetes.d.ts getNodePools"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import RequestHelper from "../request-helper";
2+
import { BaseModule } from "./base-module";
3+
import { ClusterNodePool, ClusterNodePoolUpdateOptions, NewClusterRequest } from "../types/kubernetes";
4+
export default class Kubernetes extends BaseModule {
5+
}
6+
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"create": "kubernetes.d.ts create",
3+
"delete": "kubernetes.d.ts delete",
4+
"listClusters": "kubernetes.d.ts getClusters",
5+
"createNodeGroup": "kubernetes.d.ts addNodePool",
6+
"deleteNodegroup":" kubernetes.d.ts deleteNodePool",
7+
"listNodegroups": "kubernetes.d.ts getNodePools"
8+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import RequestHelper from "../request-helper";
2+
import { BaseModule } from "./base-module";
3+
import { ClusterNodePool, ClusterNodePoolUpdateOptions, NewClusterRequest } from "../types/kubernetes";
4+
export default class Kubernetes extends BaseModule {
5+
private basePath;
6+
private baseOptions;
7+
constructor(pageSize: number, requestHelper: RequestHelper);
8+
/**
9+
* Get the Kubernetes Feature Availability
10+
* @returns Promise
11+
*/
12+
getAvailability(): Promise<any>;
13+
/**
14+
* Get all Kubernetes Clusters
15+
* @param [includeAll] return all Kubernetes Clusters, paginated (optional)
16+
* @param [page] the specific page of Kubernetes Clusters to return (optional)
17+
* @param [pageSize] the number of Kubernetes Clusters to return per page (optional)
18+
* @returns Promise
19+
*/
20+
getClusters(includeAll?: boolean, page?: number, pageSize?: number): Promise<any>;
21+
/**
22+
* Create a new Kubernetes Cluster
23+
* @param options the options for the new Kubernetes Cluster
24+
* @returns Promise
25+
*/
26+
create(options: NewClusterRequest): Promise<any>;
27+
/**
28+
* Get a Kubernetes Cluster by its identifier
29+
* @param clusterId the identifier of the Cluster
30+
* @returns Promise
31+
*/
32+
getById(clusterId: string): Promise<any>;
33+
/**
34+
* Get the kubeconfig for a Kubernetes Cluster
35+
* @param clusterId the identifier of the Cluster
36+
* @returns Promise
37+
*/
38+
getKubeconfig(clusterId: string): Promise<any>;
39+
/**
40+
* Delete a Kubernetes Cluster by its identifier
41+
* @param clusterId the identifier of the Cluster
42+
* @returns Promise
43+
*/
44+
delete(clusterId: string): Promise<any>;
45+
/**
46+
* Get the Node Pools for a Kubernetes Cluster
47+
* @param clusterId the Cluster identifier
48+
* @param [includeAll] return all Node Pools, paginated (optional)
49+
* @param [page] the specific page of Node Pools to return (optional)
50+
* @param [pageSize] the number of Node Pools to return per page (optional)
51+
* @returns Promise
52+
*/
53+
getNodePools(clusterId: string, includeAll?: boolean, page?: number, pageSize?: number): Promise<any>;
54+
/**
55+
* Get a specific Node Pool for a Kubernetes Cluster
56+
* @param clusterId the identifier of the Cluster
57+
* @param nodePoolId the identifier of the Node Pool
58+
* @returns Promise
59+
*/
60+
getNodePoolById(clusterId: string, nodePoolId: string): Promise<any>;
61+
/**
62+
* Add a Node Pool to a Kubernetes Cluster
63+
* @param clusterId the identifier of the Cluster
64+
* @param nodePool the Node Pool configuration options
65+
* @returns Promise
66+
*/
67+
addNodePool(clusterId: string, nodePool: ClusterNodePool): Promise<any>;
68+
/**
69+
* Update a specific Node Pool for a Kubernetes Cluster
70+
* @param clusterId the identifier of the Cluster
71+
* @param nodePoolId the identifier of the Node Pool
72+
* @param nodePoolOptions the Node Pool options
73+
* @returns Promise
74+
*/
75+
updateNodePool(clusterId: string, nodePoolId: string, nodePoolOptions: ClusterNodePoolUpdateOptions): Promise<any>;
76+
/**
77+
* Delete a Node Pool for a Kubernetes Cluster
78+
* @param clusterId the identifier of the Cluster
79+
* @param nodePoolId the identifier of the Node Pool
80+
* @returns Promise
81+
*/
82+
deleteNodePool(clusterId: string, nodePoolId: string): Promise<any>;
83+
/**
84+
* Recycle a Node Pool on a Cluster
85+
* @param clusterId the identifier of the Cluster
86+
* @param nodePoolId the identifier of the Node Pool
87+
* @returns Promise
88+
*/
89+
recycleNodePool(clusterId: string, nodePoolId: string): Promise<any>;
90+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"create": "kubernetes.d.ts create",
3+
"delete": "kubernetes.d.ts delete",
4+
"listClusters": "kubernetes.d.ts getClusters",
5+
"createNodeGroup": "kubernetes.d.ts addNodePool",
6+
"deleteNodegroup":" kubernetes.d.ts deleteNodePool",
7+
"listNodegroups": "kubernetes.d.ts getNodePools"
8+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { expect } from "chai";
2+
import { extractSDKData } from "../../../generators/do/generator";
3+
import { readSourceFile, readJsonData } from "../lib/helper";
4+
import { SyntaxKind } from "typescript";
5+
6+
describe("Digital Ocean generator extractSDKData", () => {
7+
context("with valid methods and valid AST", () => {
8+
it("should return extracted class data", async () => {
9+
const sdkFile: any = await readSourceFile("validDataset", "do");
10+
const data: any = await readJsonData(
11+
"validDataset",
12+
"do",
13+
"serviceClass"
14+
);
15+
let cloned = null;
16+
sdkFile.forEachChild(child => {
17+
if (SyntaxKind[child.kind] === "ClassDeclaration") {
18+
cloned = Object.assign({}, child);
19+
}
20+
});
21+
22+
if (cloned) {
23+
const result = extractSDKData(cloned, data);
24+
expect(result).to.be.an("object");
25+
expect(result.functions).to.be.an("array");
26+
expect(result.className).to.be.string;
27+
28+
} else {
29+
console.error("Error in cloning class");
30+
}
31+
});
32+
});
33+
34+
context("with invalid method data:missing method name", () => {
35+
it("should drop invalid method", async () => {
36+
const sdkFile: any = await readSourceFile("invalidDataset_1", "do");
37+
const data: any = await readJsonData(
38+
"invalidDataset_1",
39+
"do",
40+
"serviceClass"
41+
);
42+
let cloned = null;
43+
sdkFile.forEachChild(child => {
44+
if (SyntaxKind[child.kind] === "ClassDeclaration") {
45+
cloned = Object.assign({}, child);
46+
}
47+
});
48+
49+
if (cloned) {
50+
expect(
51+
extractSDKData(cloned, data).functions.length <
52+
Object.keys(data).length
53+
).to.be.true;
54+
} else {
55+
console.error("Error in cloning class");
56+
}
57+
});
58+
});
59+
60+
context("Digital Ocean with no functions", () => {
61+
it("should return empty array of methods", async () => {
62+
const sdkFile: any = await readSourceFile("invalidDataset_2", "do");
63+
const data: any = await readJsonData(
64+
"invalidDataset_2",
65+
"do",
66+
"serviceClass"
67+
);
68+
let cloned = null;
69+
sdkFile.forEachChild(child => {
70+
if (SyntaxKind[child.kind] === "ClassDeclaration") {
71+
cloned = Object.assign({}, child);
72+
}
73+
});
74+
75+
if (cloned) {
76+
const result = extractSDKData(cloned, data);
77+
expect(result).to.be.an("object");
78+
expect(result.functions).to.be.an("array");
79+
expect(result.className).to.be.string;
80+
expect(result.functions.length).to.eql(0);
81+
} else {
82+
console.error("Error in cloning class");
83+
}
84+
});
85+
});
86+
});

0 commit comments

Comments
 (0)