Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
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
12 changes: 8 additions & 4 deletions docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@
{
"arg": "-U, --hld-repo-url <hld-repo-url>",
"description": "The high level definition (HLD) git repo url; falls back to azure_devops.org in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.hld_repository"
},
{
"arg": "-u, --service-principal-id <service-principal-id>",
Expand All @@ -420,17 +421,20 @@
{
"arg": "-o, --org-name <organization-name>",
"description": "Azure DevOps organization name; falls back to azure_devops.org in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.org"
},
{
"arg": "-d, --devops-project <project>",
"description": "Azure DevOps project name; falls back to azure_devops.project in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.project"
},
{
"arg": "-a, --personal-access-token <personal-access-token>",
"description": "Azure DevOps Personal access token; falls back to azure_devops.access_token in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.access_token"
}
],
"markdown": "## Description\n\nCreate new variable group in Azure DevOps project\n\n## Command Prerequisites\n\nIn addition to an existing\n[Azure DevOps project](https://azure.microsoft.com/en-us/services/devops/), to\nlink secrets from an Azure key vault as variables in Variable Group, you will\nneed an existing key vault containing your secrets and the Service Principal for\nauthorization with Azure Key Vault.\n\n1. Use existng or\n [create a service principal either in Azure Portal](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal)\n or\n [with Azure CLI](https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli?view=azure-cli-latest).\n2. Use existing or\n [create a Azure Container Registry in Azure Portal](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal)\n or\n [with Azure CLI](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-azure-cli).\n"
Expand Down
12 changes: 8 additions & 4 deletions src/commands/project/create-variable-group.decorator.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
{
"arg": "-U, --hld-repo-url <hld-repo-url>",
"description": "The high level definition (HLD) git repo url; falls back to azure_devops.org in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.hld_repository"
},
{
"arg": "-u, --service-principal-id <service-principal-id>",
Expand All @@ -31,17 +32,20 @@
{
"arg": "-o, --org-name <organization-name>",
"description": "Azure DevOps organization name; falls back to azure_devops.org in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.org"
},
{
"arg": "-d, --devops-project <project>",
"description": "Azure DevOps project name; falls back to azure_devops.project in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.project"
},
{
"arg": "-a, --personal-access-token <personal-access-token>",
"description": "Azure DevOps Personal access token; falls back to azure_devops.access_token in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.access_token"
}
]
}
59 changes: 26 additions & 33 deletions src/commands/project/create-variable-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
PROJECT_PIPELINE_FILENAME,
VERSION_MESSAGE,
} from "../../lib/constants";
import { AzureDevOpsOpts } from "../../lib/git";
import { createTempDir } from "../../lib/ioUtil";
import * as pipelineVariableGroup from "../../lib/pipelines/variableGroup";
import {
Expand All @@ -25,6 +24,7 @@ import {
} from "../../test/mockFactory";
import { AzurePipelinesYaml, BedrockFile } from "../../types";
import {
CommandOptions,
create,
execute,
setVariableGroupInBedrockFile,
Expand All @@ -33,7 +33,7 @@ import {
} from "./create-variable-group";
import * as createVariableGrp from "./create-variable-group";
import * as fileutils from "../../lib/fileutils";
import { getErrorMessage } from "../../lib/errorBuilder";
import { deepClone } from "../../lib/util";

beforeAll(() => {
enableVerboseLogging();
Expand Down Expand Up @@ -137,24 +137,6 @@ describe("test execute function", () => {
});

describe("create", () => {
it("Should fail with empty variable group arguments", async () => {
const accessOpts: AzureDevOpsOpts = {
orgName,
personalAccessToken,
project: devopsProject,
};

// for some reasons, cannot get the await expect(...).rejects.toThrow() to work
try {
await create("", "", "", "", "", "", accessOpts);
expect(true).toBeFalsy();
} catch (e) {
expect(e.message).toBe(
getErrorMessage("project-create-variable-group-cmd-err-values-missing")
);
}
});

test("Should pass with variable group arguments", async () => {
// mock the function that calls the Azdo project's Task API
// because unit test is unable to reach this API.
Expand All @@ -168,23 +150,18 @@ describe("create", () => {
return Promise.resolve({});
});

const accessOpts: AzureDevOpsOpts = {
orgName,
personalAccessToken,
project: devopsProject,
};

try {
logger.info("calling create");
await create(
variableGroupName,
await create(variableGroupName, {
registryName,
hldRepoUrl,
servicePrincipalId,
servicePrincipalPassword,
tenant,
accessOpts
);
orgName,
devopsProject,
personalAccessToken,
});
} catch (err) {
// should not reach here
expect(true).toBe(false);
Expand Down Expand Up @@ -396,18 +373,34 @@ describe("updateLifeCyclePipeline", () => {
});
});

const mockConfigValues: CommandOptions = {
hldRepoUrl,
orgName,
personalAccessToken,
devopsProject,
registryName,
servicePrincipalId,
servicePrincipalPassword,
tenant,
};

describe("test validateValues function", () => {
it("valid org and project name", () => {
validateValues(devopsProject, orgName);
const data = deepClone(mockConfigValues);
validateValues(data);
});
it("invalid project name", () => {
const data = deepClone(mockConfigValues);
data.devopsProject = "project\\abc";
expect(() => {
validateValues("project\\abc", orgName);
validateValues(data);
}).toThrow();
});
it("invalid org name", () => {
const data = deepClone(mockConfigValues);
data.orgName = "org name";
expect(() => {
validateValues(devopsProject, "org name");
validateValues(data);
}).toThrow();
});
});
Loading