Skip to content

Commit e170b2a

Browse files
committed
Add network-area-route TypeScript unit tests
Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent 0a70c69 commit e170b2a

8 files changed

Lines changed: 8039 additions & 229 deletions

File tree

package-lock.json

Lines changed: 4010 additions & 229 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"affinitygroup_unit_test": "file:tests/ts/iaas/affinityGroups",
1313
"image_unit_test": "file:tests/ts/iaas/image",
1414
"key_pair_unit_test": "file:tests/ts/iaas/key-pair",
15+
"network_area_route_unit_test": "file:tests/ts/iaas/network-area-route",
1516
"network_area_unit_test": "file:tests/ts/iaas/network-area"
1617
}
1718
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: network_area_route_unit_test
2+
description: A minimal TypeScript Pulumi program
3+
runtime:
4+
name: nodejs
5+
options:
6+
packagemanager: npm
7+
config:
8+
pulumi:tags:
9+
value:
10+
pulumi:template: typescript
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as pulumi from "@pulumi/pulumi";
2+
import * as stackit from "@stackitcloud/pulumi-stackit";
3+
4+
export const networkAreaRouteOrganizationId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
5+
export const networkAreaId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx1";
6+
export const networkAreaRouteLabelKey = "unit-test";
7+
export const networkAreaRouteLabelValue = "test-label-value";
8+
export const networkAreaRoutePrefix = "192.168.0.0/24";
9+
export const networkAreaRouteNextHop = "192.168.1.0/24";
10+
11+
// datasource
12+
export const networkAreaRouteId = "networkAreaRoute-id-to-read";
13+
14+
export const exampleNetworkAreaRoute = new stackit.NetworkAreaRoute("example_networkAreaRoute", {
15+
organizationId: networkAreaRouteOrganizationId,
16+
networkAreaId: networkAreaId,
17+
prefix: networkAreaRoutePrefix,
18+
nextHop: networkAreaRouteNextHop,
19+
labels: {[networkAreaRouteLabelKey]:networkAreaRouteLabelValue},
20+
});
21+
22+
export const networkAreaRouteDatasource = stackit.getNetworkAreaRouteOutput({
23+
organizationId: networkAreaRouteOrganizationId,
24+
networkAreaRouteId: networkAreaRouteId,
25+
networkAreaId: networkAreaId,
26+
});

tests/ts/iaas/network-area-route/package-lock.json

Lines changed: 3715 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "network_area_route_unit_test",
3+
"main": "index.ts",
4+
"devDependencies": {
5+
"@types/mocha": "^10.0.10",
6+
"@types/node": "^18",
7+
"mocha": "^11.7.5",
8+
"ts-node": "^10.9.2",
9+
"typescript": "^5.0.0"
10+
},
11+
"dependencies": {
12+
"@pulumi/pulumi": "^3.113.0",
13+
"@stackitcloud/pulumi-stackit": "file:../../../../sdk/nodejs/bin"
14+
},
15+
"scripts": {
16+
"test": "mocha -r ts-node/register test.ts"
17+
}
18+
}
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
import * as assert from "assert";
2+
import * as pulumi from "@pulumi/pulumi";
3+
import "mocha";
4+
import { exampleNetworkAreaRoute, networkAreaId, networkAreaRouteId, networkAreaRouteLabelKey, networkAreaRouteLabelValue, networkAreaRouteNextHop, networkAreaRouteOrganizationId, networkAreaRoutePrefix } from "./index";
5+
6+
pulumi.runtime.setMocks({
7+
newResource: function(args: pulumi.runtime.MockResourceArgs): {id: string, state: any} {
8+
return {
9+
id: args.inputs.name + "_id",
10+
state: args.inputs,
11+
};
12+
},
13+
call: function(args: pulumi.runtime.MockCallArgs) {
14+
// We check the token to identify which data source is being called.
15+
if (args.token === "stackit:index/getNetworkAreaRoute:getNetworkAreaRoute") {
16+
// Check if the input parameters were passed correctly
17+
if (args.inputs.organizationId !== networkAreaRouteOrganizationId || args.inputs.networkAreaId !== networkAreaId || args.inputs.networkAreaRouteId !== networkAreaRouteId) {
18+
throw new Error("getNetworkAreaRoute call received incorrect input parameters.");
19+
}
20+
// Return the complete object
21+
return { ...exampleNetworkAreaRoute, ...args.inputs };
22+
}
23+
return args.inputs;
24+
},
25+
},
26+
"project",
27+
"stack",
28+
false, // Sets the flag `dryRun`, which indicates if pulumi is running in preview mode.
29+
);
30+
31+
describe("exampleNetworkAreaRoute", () => {
32+
let infra: typeof import("./index");
33+
34+
before(async function() {
35+
// It's important to import the program _after_ the mocks are defined.
36+
infra = await import("./index");
37+
})
38+
39+
it("networkAreaRoute must have a organization id", function(done) {
40+
pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute]).apply(([urn, exampleNetworkAreaRoute]) => {
41+
if (!exampleNetworkAreaRoute?.organizationId) {
42+
done(new Error(`Missing organization tag on exampleNetworkAreaRoute ${urn}`));
43+
} else {
44+
done();
45+
}
46+
});
47+
});
48+
49+
it("networkAreaRoute must have a areaId", function(done) {
50+
pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute]).apply(([urn, exampleNetworkAreaRoute]) => {
51+
if (!exampleNetworkAreaRoute?.networkAreaId) {
52+
done(new Error(`Missing a areaId tag on exampleNetworkAreaRoute ${urn}`));
53+
} else {
54+
done();
55+
}
56+
});
57+
});
58+
59+
it("networkAreaRoute must have a prefix", function(done) {
60+
pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute]).apply(([urn, exampleNetworkAreaRoute]) => {
61+
if (!exampleNetworkAreaRoute?.prefix) {
62+
done(new Error(`Missing a prefix tag on exampleNetworkAreaRoute ${urn}`));
63+
} else {
64+
done();
65+
}
66+
});
67+
});
68+
69+
it("networkAreaRoute must have a nextHop", function(done) {
70+
pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute]).apply(([urn, exampleNetworkAreaRoute]) => {
71+
if (!exampleNetworkAreaRoute?.nextHop) {
72+
done(new Error(`Missing a nextHop tag on exampleNetworkAreaRoute ${urn}`));
73+
} else {
74+
done();
75+
}
76+
});
77+
});
78+
79+
it("check if organization id was correctly set", function(done) {
80+
pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute.organizationId]).apply(([urn, organizationId]) => {
81+
if (organizationId === networkAreaRouteOrganizationId) {
82+
done();
83+
} else {
84+
done(new Error(`Provided organization id ${organizationId} was not set correctly on exampleNetworkAreaRoute ${urn}`));
85+
}
86+
});
87+
});
88+
89+
it("check if areaId was correctly set", function(done) {
90+
pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute.networkAreaId]).apply(([urn, areaId]) => {
91+
if (areaId === networkAreaId) {
92+
done();
93+
} else {
94+
done(new Error(`Provided areaId ${areaId} was not set correctly on exampleNetworkAreaRoute ${urn}`));
95+
}
96+
});
97+
});
98+
99+
it("check if prefix was correctly set", function(done) {
100+
pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute.prefix]).apply(([urn, prefix]) => {
101+
if (prefix === networkAreaRoutePrefix) {
102+
done();
103+
} else {
104+
done(new Error(`Provided prefix ${prefix} was not set correctly on exampleNetworkAreaRoute ${urn}`));
105+
}
106+
});
107+
});
108+
109+
it("check if nextHop was correctly set", function(done) {
110+
pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute.nextHop]).apply(([urn, nextHop]) => {
111+
if (nextHop === networkAreaRouteNextHop) {
112+
done();
113+
} else {
114+
done(new Error(`Provided nextHop ${nextHop} was not set correctly on exampleNetworkAreaRoute ${urn}`));
115+
}
116+
});
117+
});
118+
119+
it("check if the 'labels' map contains the correct key and value", function(done) {
120+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.labels]).apply(([urn, labels]) => {
121+
const actualValue = labels ? labels[networkAreaRouteLabelKey] : undefined;
122+
if (actualValue === networkAreaRouteLabelValue) {
123+
done();
124+
} else {
125+
done(new Error(`Label '${networkAreaRouteLabelKey}' was not set correctly. Actual: ${actualValue}, Expected: ${networkAreaRouteLabelValue} on datasource ${urn}`));
126+
}
127+
});
128+
});
129+
130+
});
131+
132+
// datasource
133+
describe("networkAreaRoute datasource test", () => {
134+
let infra: typeof import("./index");
135+
136+
// It's important to import the program _after_ the mocks are defined.
137+
before(async function() {
138+
infra = await import("./index");
139+
})
140+
141+
it("networkAreaRoute must have a organization id", function(done) {
142+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource]).apply(([urn, networkAreaRouteDatasource]) => {
143+
if (!networkAreaRouteDatasource?.organizationId) {
144+
done(new Error(`Missing organization tag on networkAreaRouteDatasource ${urn}`));
145+
} else {
146+
done();
147+
}
148+
});
149+
});
150+
151+
it("networkAreaRoute must have a areaId", function(done) {
152+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource]).apply(([urn, networkAreaRouteDatasource]) => {
153+
if (!networkAreaRouteDatasource?.networkAreaId) {
154+
done(new Error(`Missing a areaId tag on networkAreaRouteDatasource ${urn}`));
155+
} else {
156+
done();
157+
}
158+
});
159+
});
160+
161+
it("check if networkAreaRouteId was correctly set", function(done) {
162+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.networkAreaRouteId]).apply(([urn, networkAreaRouteId]) => {
163+
if (networkAreaRouteId === infra.networkAreaRouteId) {
164+
done();
165+
} else {
166+
done(new Error(`Provided networkAreaRouteId ${networkAreaRouteId} was not set correctly on networkAreaRouteDatasource ${urn}`));
167+
}
168+
});
169+
});
170+
171+
it("networkAreaRoute must have a prefix", function(done) {
172+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource]).apply(([urn, networkAreaRouteDatasource]) => {
173+
if (!networkAreaRouteDatasource?.prefix) {
174+
done(new Error(`Missing a prefix tag on networkAreaRouteDatasource ${urn}`));
175+
} else {
176+
done();
177+
}
178+
});
179+
});
180+
181+
it("networkAreaRoute must have a nextHop", function(done) {
182+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource]).apply(([urn, networkAreaRouteDatasource]) => {
183+
if (!networkAreaRouteDatasource?.nextHop) {
184+
done(new Error(`Missing a nextHop tag on networkAreaRouteDatasource ${urn}`));
185+
} else {
186+
done();
187+
}
188+
});
189+
});
190+
191+
it("check if organization id was correctly set", function(done) {
192+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.organizationId]).apply(([urn, organizationId]) => {
193+
if (organizationId === networkAreaRouteOrganizationId) {
194+
done();
195+
} else {
196+
done(new Error(`Provided organization id ${organizationId} was not set correctly on networkAreaRouteDatasource ${urn}`));
197+
}
198+
});
199+
});
200+
201+
it("check if areaId was correctly set", function(done) {
202+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.networkAreaId]).apply(([urn, areaId]) => {
203+
if (areaId === networkAreaId) {
204+
done();
205+
} else {
206+
done(new Error(`Provided areaId ${areaId} was not set correctly on networkAreaRouteDatasource ${urn}`));
207+
}
208+
});
209+
});
210+
211+
it("check if prefix was correctly set", function(done) {
212+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.prefix]).apply(([urn, prefix]) => {
213+
if (prefix === networkAreaRoutePrefix) {
214+
done();
215+
} else {
216+
done(new Error(`Provided prefix ${prefix} was not set correctly on networkAreaRouteDatasource ${urn}`));
217+
}
218+
});
219+
});
220+
221+
it("check if nextHop was correctly set", function(done) {
222+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.nextHop]).apply(([urn, nextHop]) => {
223+
if (nextHop === networkAreaRouteNextHop) {
224+
done();
225+
} else {
226+
done(new Error(`Provided nextHop ${nextHop} was not set correctly on networkAreaRouteDatasource ${urn}`));
227+
}
228+
});
229+
});
230+
231+
it("check if the 'labels' map contains the correct key and value", function(done) {
232+
pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.labels]).apply(([urn, labels]) => {
233+
const actualValue = labels ? labels[networkAreaRouteLabelKey] : undefined;
234+
if (actualValue === networkAreaRouteLabelValue) {
235+
done();
236+
} else {
237+
done(new Error(`Label '${networkAreaRouteLabelKey}' was not set correctly. Actual: ${actualValue}, Expected: ${networkAreaRouteLabelValue} on datasource ${urn}`));
238+
}
239+
});
240+
});
241+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"outDir": "bin",
5+
"target": "es2020",
6+
"module": "commonjs",
7+
"moduleResolution": "node",
8+
"sourceMap": true,
9+
"experimentalDecorators": true,
10+
"pretty": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"noImplicitReturns": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.ts"
17+
]
18+
}

0 commit comments

Comments
 (0)