Skip to content

Commit 2f53021

Browse files
committed
Merge remote-tracking branch 'upstream/generator-do' into do_examples
2 parents 49c5b68 + 7fe0457 commit 2f53021

File tree

15 files changed

+664
-0
lines changed

15 files changed

+664
-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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
} else {
28+
console.error("Error in cloning class");
29+
}
30+
});
31+
});
32+
33+
context("with invalid method data:missing method name", () => {
34+
it("should drop invalid method", async () => {
35+
const sdkFile: any = await readSourceFile("invalidDataset_1", "do");
36+
const data: any = await readJsonData(
37+
"invalidDataset_1",
38+
"do",
39+
"serviceClass"
40+
);
41+
let cloned = null;
42+
sdkFile.forEachChild(child => {
43+
if (SyntaxKind[child.kind] === "ClassDeclaration") {
44+
cloned = Object.assign({}, child);
45+
}
46+
});
47+
48+
if (cloned) {
49+
expect(
50+
extractSDKData(cloned, data).functions.length <
51+
Object.keys(data).length
52+
).to.be.true;
53+
} else {
54+
console.error("Error in cloning class");
55+
}
56+
});
57+
});
58+
59+
context("Digital Ocean with no functions", () => {
60+
it("should return empty array of methods", async () => {
61+
const sdkFile: any = await readSourceFile("invalidDataset_2", "do");
62+
const data: any = await readJsonData(
63+
"invalidDataset_2",
64+
"do",
65+
"serviceClass"
66+
);
67+
let cloned = null;
68+
sdkFile.forEachChild(child => {
69+
if (SyntaxKind[child.kind] === "ClassDeclaration") {
70+
cloned = Object.assign({}, child);
71+
}
72+
});
73+
74+
if (cloned) {
75+
const result = extractSDKData(cloned, data);
76+
expect(result).to.be.an("object");
77+
expect(result.functions).to.be.an("array");
78+
expect(result.className).to.be.string;
79+
expect(result.functions.length).to.eql(0);
80+
} else {
81+
console.error("Error in cloning class");
82+
}
83+
});
84+
});
85+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { expect } from "chai";
2+
import { getAST } from "../../../parsers/do/parser";
3+
import { SyntaxKind } from "typescript";
4+
5+
describe("Digital Ocean parser getAST", () => {
6+
context("With existing file", () => {
7+
it("Should return Abstract syntax tree of the class", async () => {
8+
const ast: any = await getAST("droplets.d.ts");
9+
expect(ast).to.be.an("object");
10+
expect(SyntaxKind[ast.kind] === "ClassDeclaration").to.be.true;
11+
});
12+
});
13+
14+
context("With non-existing file", () => {
15+
it("should return File not found Error", async () => {
16+
try {
17+
await getAST("unknown.d.ts");
18+
} catch (error) {
19+
expect(error.message).to.eql("File not found!");
20+
}
21+
});
22+
});
23+
24+
context("With wrong format file", () => {
25+
it("Should return class not found Error", async () => {
26+
try {
27+
await getAST("../types/common.d.ts");
28+
} catch (error) {
29+
expect(error.message).to.eql("Class not found!");
30+
}
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)