Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yradsmikham committed Apr 17, 2020
1 parent 069e518 commit 16e27a7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
37 changes: 34 additions & 3 deletions src/commands/service/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,35 @@ describe("Test fetchValues function", () => {
expect(result.middlewaresArray).toEqual(["mid1", "mid2"]);
});

it("Positive test: with serviceBuildVg value", () => {
jest
.spyOn(config, "Bedrock")
.mockReturnValueOnce(bedrockYaml.DEFAULT_CONTENT());
const mocked = getMockValues();
mocked.serviceBuildVg = "foo,bar";
const result = fetchValues(mocked);
expect(result.serviceVgArray).toEqual(["foo", "bar"]);
});

it("Negative test: with serviceBuildVg value", () => {
jest
.spyOn(config, "Bedrock")
.mockReturnValueOnce(bedrockYaml.DEFAULT_CONTENT());
const mocked = getMockValues();
mocked.serviceBuildVg = "foo,,bar";
expect(() => fetchValues(mocked)).toThrow();
});

it("Positive test: with serviceBuildVariables value", () => {
jest
.spyOn(config, "Bedrock")
.mockReturnValueOnce(bedrockYaml.DEFAULT_CONTENT());
const mocked = getMockValues();
mocked.serviceBuildVariables = "foo,bar";
const result = fetchValues(mocked);
expect(result.serviceVariablesArray).toEqual(["foo", "bar"]);
});

it("Positive test: with bedrock rings", () => {
const mockedBedrockFileConfig = { ...bedrockYaml.DEFAULT_CONTENT() };
mockedBedrockFileConfig.rings = {
Expand Down Expand Up @@ -509,8 +538,8 @@ describe("Adding a service to a repo directory", () => {
values.k8sPort = 1337;
values.serviceBuildVg = "foo,bar,baz";
values.serviceBuildVariables = "FOO,BAR,BAZ";
values.serviceVgArray = [ "foo", "bar", "baz"]
values.serviceVariablesArray = [ "FOO", "BAR", "BAZ"]
values.serviceVgArray = ["foo", "bar", "baz"];
values.serviceVariablesArray = ["FOO", "BAR", "BAZ"];

logger.info(
`creating randomTmpDir ${randomTmpDir} and service ${serviceName}`
Expand All @@ -527,7 +556,9 @@ describe("Adding a service to a repo directory", () => {
expect(service.serviceBuildVg).toBeDefined();
expect(service.serviceBuildVariables).toBeDefined();
expect(service.serviceBuildVg).toStrictEqual(values.serviceVgArray);
expect(service.serviceBuildVariables).toStrictEqual(values.serviceVariablesArray);
expect(service.serviceBuildVariables).toStrictEqual(
values.serviceVariablesArray
);
}
}
});
Expand Down
7 changes: 7 additions & 0 deletions src/commands/service/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ export const fetchValues = (opts: CommandOptions): CommandValues => {
}
});

if (serviceVariablesArray.includes("") || serviceVgArray.includes("")) {
throw buildError(
errorStatusCode.VALIDATION_ERR,
"service-create-cmd-invalid-service-variable-group-err"
);
}

const values: CommandValues = {
gitPush: opts.gitPush,
helmChartChart: opts.helmChartChart,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fileutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export const serviceBuildAndUpdatePipeline = (
`ACR_BUILD_COMMAND="az acr build -r $(ACR_NAME) --image $IMAGE_NAME ."`,
``,
`echo "Exporting build variables from variable groups, if available: "`,
`echo "Build Variables: ${serviceBuildVariables}"`,
`echo "Build Variables: \${serviceBuildVariables}"`,
...(serviceBuildVariables ?? []).map(
(variable) =>
`ACR_BUILD_COMMAND+=" --build-arg ${variable}='$(${variable})'"`
Expand Down
1 change: 1 addition & 0 deletions src/lib/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"service-get-display-name-cmd-service-name-not-found-err": "Could not find a service for path {0}. Make sure that the specified path is valid.",

"service-create-cmd-invalid-helm-url-err": "The helm git URL was invalid. Provided helm git URL is an invalid git+ssh or http/https URL: {0}",
"service-create-cmd-invalid-service-variable-group-err": "The value for --service-build-vg or --service-build-variable was not valid.",
"service-create-cmd-service-name-missing-err": "Service name was missing. Provide it.",
"service-create-cmd-service-path-missing-err": "Service path was missing. Provide it.",
"service-create-cmd-service-name-dns-invalid-err": "Service name or DNS value was invalid. See error message for more details.",
Expand Down

0 comments on commit 16e27a7

Please sign in to comment.