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

Commit

Permalink
Add test for updating services pipeline yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Edaena Salinas authored and Edaena Salinas committed Apr 23, 2020
1 parent 5b093ca commit d6321e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,13 @@
"arg": "-a, --personal-access-token <personal-access-token>",
"description": "Personal Access Token",
"required": true,
"inherit": "azureDevops.access_token"
"inherit": "azure_devops.access_token"
},
{
"arg": "-o, --org-name <organization-name>",
"description": "Organization Name for Azure DevOps",
"required": true,
"inherit": "azureDevops.org"
"inherit": "azure_devops.org"
},
{
"arg": "-u, --repo-url <repo-url>",
Expand All @@ -510,7 +510,7 @@
"arg": "-d, --devops-project <devops-project>",
"description": "Azure DevOps Project name",
"required": true,
"inherit": "azureDevops.project"
"inherit": "azure_devops.project"
},
{
"arg": "-b, --build-script-url <build-script-url>",
Expand Down
6 changes: 6 additions & 0 deletions src/commands/project/append-variable-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ describe("Test execute function", () => {
.spyOn(appendVariableGrp, "validateValues")
.mockReturnValueOnce(mockValues as ConfigValues);
jest.spyOn(bedrockYaml, "addVariableGroup").mockReturnValue();
jest
.spyOn(fileutils, "appendVariableGroupToPipelineYaml")
.mockReturnValue();

expect(bedrockFile.variableGroups?.length).toBe(0);
await execute("my-path", "my-vg", mockValues, exitFn);
expect(exitFn).toBeCalledTimes(1);
expect(exitFn.mock.calls).toEqual([[0]]);
expect(fileutils.appendVariableGroupToPipelineYaml).toHaveBeenCalledTimes(
3
);
});
});
23 changes: 22 additions & 1 deletion src/commands/project/append-variable-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import { logger } from "../../logger";
import { build as buildError, log as logError } from "../../lib/errorBuilder";
import { errorStatusCode } from "../../lib/errorStatusCode";
import decorator from "./append-variable-group.decorator.json";
import { BedrockFileInfo } from "../../types";
import { BedrockFileInfo, BedrockFile } from "../../types";
import * as bedrockYaml from "../../lib/bedrockYaml";
import { hasVariableGroup } from "../../lib/pipelines/variableGroup";
import { AzureDevOpsOpts } from "../../lib/git";
import { appendVariableGroupToPipelineYaml } from "../../lib/fileutils";
import { SERVICE_PIPELINE_FILENAME } from "../../lib/constants";

// Values that need to be pulled out from the command operator
export interface CommandOptions {
Expand Down Expand Up @@ -87,6 +89,24 @@ export const variableGroupExists = async (
return await hasVariableGroup(accessOpts, variableGroupName);
};

/**
* Update the variable groups for the project services
* @param bedrockFile The bedrock.yaml file
*/
export const updateServicesVariableGroups = (
bedrockFile: BedrockFile,
variableGroupName: string
): void => {
bedrockFile.services.forEach((service) => {
const path = service.path;
appendVariableGroupToPipelineYaml(
path,
SERVICE_PIPELINE_FILENAME,
variableGroupName
);
});
};

/**
* Executes the command.
*
Expand Down Expand Up @@ -118,6 +138,7 @@ export const execute = async (

const bedrockFile = Bedrock(projectPath);
bedrockYaml.addVariableGroup(bedrockFile, projectPath, variableGroupName);
updateServicesVariableGroups(bedrockFile, variableGroupName);
await exitFn(0);
} catch (err) {
logError(
Expand Down

0 comments on commit d6321e4

Please sign in to comment.