Skip to content
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
4,372 changes: 446 additions & 3,926 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"network_area_unit_test": "file:tests/ts/iaas/network-area",
"network_interface_unit_test": "file:tests/ts/iaas/network-interface",
"network_unit_test": "file:tests/ts/iaas/network",
"project_unit_test": "file:tests/ts/resourcemanager/project",
"public_ip_unit_test": "file:tests/ts/iaas/public_ip",
"routing_table_unit_test": "file:tests/ts/iaas/routingTable",
"securitygroup_unit_test": "file:tests/ts/iaas/securityGroup",
Expand Down
10 changes: 10 additions & 0 deletions tests/ts/resourcemanager/project/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: project_unit_test
description: A minimal TypeScript Pulumi program
runtime:
name: nodejs
options:
packagemanager: npm
config:
pulumi:tags:
value:
pulumi:template: typescript
24 changes: 24 additions & 0 deletions tests/ts/resourcemanager/project/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as pulumi from "@pulumi/pulumi";
import * as stackit from "@stackitcloud/pulumi-stackit";

export const projectParentContainerId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
export const projectName = "example-project-name";
export const projectOwnerEmail = "john.doe@stackit.cloud";

export const projectLabelKey = "unit-test";
export const projectLabelValue = "test-label-value";

// datasource
export const projectId = "project-id-to-read";

export const exampleProjectOnlyRequired = new stackit.ResourcemanagerProject("example_project_req", {
parentContainerId: projectParentContainerId,
name: projectName,
labels: {[projectLabelKey]:projectLabelValue},
ownerEmail: projectOwnerEmail,
});

// datasource
export const projectDatasource = stackit.getResourcemanagerProjectOutput({
projectId: projectId,
});
3,715 changes: 3,715 additions & 0 deletions tests/ts/resourcemanager/project/package-lock.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions tests/ts/resourcemanager/project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "project_unit_test",
"main": "index.ts",
"devDependencies": {
"@types/mocha": "^10.0.10",
"@types/node": "^18",
"mocha": "^11.7.5",
"ts-node": "^10.9.2",
"typescript": "^5.0.0"
},
"dependencies": {
"@pulumi/pulumi": "^3.113.0",
"@stackitcloud/pulumi-stackit": "file:../../../../sdk/nodejs/bin"
},
"scripts": {
"test": "mocha -r ts-node/register test.ts"
}
}
143 changes: 143 additions & 0 deletions tests/ts/resourcemanager/project/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import * as assert from "assert";
import * as pulumi from "@pulumi/pulumi";
import "mocha";
import { projectName, projectLabelKey, projectLabelValue, projectId, projectDatasource, exampleProjectOnlyRequired, projectParentContainerId, projectOwnerEmail } from "./index";

pulumi.runtime.setMocks({
newResource: function(args: pulumi.runtime.MockResourceArgs): {id: string, state: any} {
return {
id: args.inputs.name + "_id",
state: args.inputs,
};
},
call: function(args: pulumi.runtime.MockCallArgs) {
// We check the token to identify which data source is being called.
if (args.token === "stackit:index/getResourcemanagerProject:getResourcemanagerProject") {
// Check if the input parameters were passed correctly
if (args.inputs.projectId !== projectId) {
throw new Error("getResourcemanagerProject call received incorrect input parameters.");
}
// Return the complete object
return { ...exampleProjectOnlyRequired, ...args.inputs };
}
return args.inputs;
},
},
"project",
"stack",
false, // Sets the flag `dryRun`, which indicates if pulumi is running in preview mode.
);


describe("exampleProjectOnlyRequired", () => {
let infra: typeof import("./index");

before(async function() {
// It's important to import the program _after_ the mocks are defined.
infra = await import("./index");
})

it("project must have a parentContainerId", function(done) {
pulumi.all([infra.exampleProjectOnlyRequired.urn, infra.exampleProjectOnlyRequired]).apply(([urn, exampleProjectOnlyRequired]) => {
if (!exampleProjectOnlyRequired?.parentContainerId) {
done(new Error(`Missing parentContainerId tag on exampleProjectOnlyRequired ${urn}`));
} else {
done();
}
});
});

it("project must have a name", function(done) {
pulumi.all([infra.exampleProjectOnlyRequired.urn, infra.exampleProjectOnlyRequired]).apply(([urn, exampleProjectOnlyRequired]) => {
if (!exampleProjectOnlyRequired?.name) {
done(new Error(`Missing a name tag on exampleProjectOnlyRequired ${urn}`));
} else {
done();
}
});
});

it("check if parentContainerId was correctly set", function(done) {
pulumi.all([infra.exampleProjectOnlyRequired.urn, infra.exampleProjectOnlyRequired.parentContainerId]).apply(([urn, parentContainerId]) => {
if (parentContainerId === projectParentContainerId) {
done();
} else {
done(new Error(`Provided parentContainerId ${parentContainerId} was not set correctly on exampleProjectOnlyRequired ${urn}`));
}
});
});

it("check if name was correctly set", function(done) {
pulumi.all([infra.exampleProjectOnlyRequired.urn, infra.exampleProjectOnlyRequired.name]).apply(([urn, name]) => {
if (name === projectName) {
done();
} else {
done(new Error(`Provided name ${name} was not set correctly on exampleProjectOnlyRequired ${urn}`));
}
});
});

it("check if ownerEmail was correctly set", function(done) {
pulumi.all([infra.exampleProjectOnlyRequired.urn, infra.exampleProjectOnlyRequired.ownerEmail]).apply(([urn, ownerEmail]) => {
if (ownerEmail === projectOwnerEmail) {
done();
} else {
done(new Error(`Provided ownerEmail ${ownerEmail} was not set correctly on exampleProjectOnlyRequired ${urn}`));
}
});
});

it("check if the 'labels' map contains the correct key and value", function(done) {
pulumi.all([infra.exampleProjectOnlyRequired.urn, infra.exampleProjectOnlyRequired.labels]).apply(([urn, labels]) => {
const actualValue = labels?.[projectLabelKey];
if (actualValue === projectLabelValue) {
done();
} else {
done(new Error(`Label '${projectLabelKey}' was not set correctly. Actual: ${actualValue}, Expected: ${projectLabelValue} on resource ${urn}`));
}
});
});

});

// datasource
describe("project datasource test", () => {
let infra: typeof import("./index");

// It's important to import the program _after_ the mocks are defined.
before(async function() {
infra = await import("./index");
})

it("check if projectId was correctly set", function(done) {
pulumi.all([infra.projectDatasource, infra.projectDatasource.projectId]).apply(([urn, projectId]) => {
if (projectId === projectId) {
done();
} else {
done(new Error(`Provided projectId ${projectId} was not set correctly on datasource ${urn.name}`));
}
});
});

it("check if name was correctly set", function(done) {
pulumi.all([infra.projectDatasource, infra.projectDatasource.name]).apply(([urn, name]) => {
if (name === projectName) {
done();
} else {
done(new Error(`Provided name ${name} was not set correctly on datasource ${urn.name}`));
}
});
});

it("check if the 'labels' map contains the correct key and value", function(done) {
pulumi.all([infra.projectDatasource, infra.projectDatasource.labels]).apply(([urn, labels]) => {
const actualValue = labels?.[projectLabelKey];
if (actualValue === projectLabelValue) {
done();
} else {
done(new Error(`Label '${projectLabelKey}' was not set correctly. Actual: ${actualValue}, Expected: ${projectLabelValue} on datasource ${urn.name}`));
}
});
});

});
18 changes: 18 additions & 0 deletions tests/ts/resourcemanager/project/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.ts"
]
}
Loading