Skip to content

Commit e4f6d63

Browse files
committed
Add test for override parameters
1 parent 0751526 commit e4f6d63

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

test/code-build-test.js

+58
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,64 @@ describe("inputs2Parameters", () => {
205205
expect(shaEnv).to.haveOwnProperty("type").and.to.equal("PLAINTEXT");
206206
});
207207

208+
it("build override parameters for codeBuild.startBuild", () => {
209+
// This is how GITHUB injects its input values.
210+
// It would be nice if there was an easy way to test this...
211+
process.env[`INPUT_PROJECT-NAME`] = projectName;
212+
process.env[`GITHUB_REPOSITORY`] = repoInfo;
213+
process.env[`GITHUB_SHA`] = sha;
214+
const test = inputs2Parameters({
215+
projectName,
216+
sourceVersion: sha,
217+
owner: "owner",
218+
repo: "repo",
219+
computeTypeOverride: "BUILD_GENERAL1_LARGE",
220+
environmentTypeOverride: "LINUX_CONTAINER",
221+
imageOverride: "111122223333.dkr.ecr.us-west-2.amazonaws.com/codebuild-docker-repo"
222+
});
223+
expect(test).to.haveOwnProperty("projectName").and.to.equal(projectName);
224+
expect(test).to.haveOwnProperty("sourceVersion").and.to.equal(sha);
225+
expect(test)
226+
.to.haveOwnProperty("sourceTypeOverride")
227+
.and.to.equal("GITHUB");
228+
expect(test)
229+
.to.haveOwnProperty("sourceLocationOverride")
230+
.and.to.equal(`https://github.com/owner/repo.git`);
231+
expect(test)
232+
.to.haveOwnProperty("buildspecOverride")
233+
.and.to.equal(undefined);
234+
expect(test)
235+
.to.haveOwnProperty("computeTypeOverride")
236+
.and.to.equal(`BUILD_GENERAL1_LARGE`);
237+
expect(test)
238+
.to.haveOwnProperty("environmentTypeOverride")
239+
.and.to.equal(`LINUX_CONTAINER`);
240+
expect(test)
241+
.to.haveOwnProperty("imageOverride")
242+
.and.to.equal(`111122223333.dkr.ecr.us-west-2.amazonaws.com/codebuild-docker-repo`);
243+
244+
// I send everything that starts 'GITHUB_'
245+
expect(test)
246+
.to.haveOwnProperty("environmentVariablesOverride")
247+
.and.to.have.lengthOf.greaterThan(1);
248+
249+
const [repoEnv] = test.environmentVariablesOverride.filter(
250+
({ name }) => name === "GITHUB_REPOSITORY"
251+
);
252+
expect(repoEnv)
253+
.to.haveOwnProperty("name")
254+
.and.to.equal("GITHUB_REPOSITORY");
255+
expect(repoEnv).to.haveOwnProperty("value").and.to.equal(repoInfo);
256+
expect(repoEnv).to.haveOwnProperty("type").and.to.equal("PLAINTEXT");
257+
258+
const [shaEnv] = test.environmentVariablesOverride.filter(
259+
({ name }) => name === "GITHUB_SHA"
260+
);
261+
expect(shaEnv).to.haveOwnProperty("name").and.to.equal("GITHUB_SHA");
262+
expect(shaEnv).to.haveOwnProperty("value").and.to.equal(sha);
263+
expect(shaEnv).to.haveOwnProperty("type").and.to.equal("PLAINTEXT");
264+
});
265+
208266
it("can process env-vars-for-codebuild", () => {
209267
// This is how GITHUB injects its input values.
210268
// It would be nice if there was an easy way to test this...

0 commit comments

Comments
 (0)