Skip to content

Commit

Permalink
resolved unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
yradsmikham committed Apr 14, 2020
1 parent 1147142 commit 42394ef
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/lib/bedrockYaml/bedrockYaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ describe("Adding a new service to a Bedrock file", () => {
const k8sBackend = "mybackendservice";
const pathPrefix = "ingressprefix";
const pathPrefixMajorVersion = "v2";
const BuildVariables = ["version"];
const BuildVg = ["test-vg"];

const defaultBedrockFileObject = createTestBedrockYaml(
false
Expand All @@ -77,8 +79,8 @@ describe("Adding a new service to a Bedrock file", () => {
k8sBackend,
pathPrefix,
pathPrefixMajorVersion,
[],
[]
BuildVg,
BuildVariables
);

const expected: BedrockFile = {
Expand All @@ -94,6 +96,8 @@ describe("Adding a new service to a Bedrock file", () => {
middlewares: traefikMiddlewares,
pathPrefix,
pathPrefixMajorVersion,
serviceBuildVg: BuildVg,
serviceBuildVariables: BuildVariables,
},
],
variableGroups: [],
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fileutils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe("generateServiceBuildAndUpdatePipelineYaml", () => {
path.join(targetDirectory, serviceDirectory),
[],
[],
[]
["${serviceBuildVariables}"]
);

expect(writeSpy).toBeCalledWith(
Expand Down
13 changes: 6 additions & 7 deletions src/lib/fileutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,16 @@ export const serviceBuildAndUpdatePipeline = (
},
{
script: generateYamlScript([
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
`export BUILD_REPO_NAME=${BUILD_REPO_NAME(serviceName)}`,
`tag_name="$BUILD_REPO_NAME:${IMAGE_TAG}"`,
`commitId=$(Build.SourceVersion)`,
`commitId=$(echo "\${commitId:0:7}")`,
`service=$(Build.Repository.Name)`,
`service=\${service##*/}`,
`service=$(./spk/spk service get-display-name -p ${relativeServiceForDockerfile})`,
`url=$(git remote --verbose | grep origin | grep fetch | cut -f2 | cut -d' ' -f1)`,
`repourl=\${url##*@}`,
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p1 $(Build.BuildId) --image-tag $tag_name --commit-id $commitId --service $service --repository $repourl`,
]),
displayName:
Expand Down Expand Up @@ -595,7 +594,7 @@ const manifestGenerationPipelineYaml = (): string => {
displayName:
"If configured, update manifest pipeline details in Spektate db before manifest generation",
condition:
"and(ne(variables['INTROSPECTION_ACCOUNT_NAME'], ''), ne(variables['INTROSPECTION_ACCOUNT_KEY'], ''),ne(variables['INTROSPECTION_TABLE_NAME'], ''),ne(variables['INTROSPECTION_PARTITION_KEY'], ''))",
"and(ne(variables['INTROSPECTION_ACCOUNT_NAME'], ''), ne(variables['INTROSPECTION_ACCOUNT_KEY'], ''),ne(variables['INTROSPECTION_TABLE_NAME'], ''),ne(variables['INTROSPECTION_PARTITION_KEY'], ''), ne(variables['Build.Reason'], 'PullRequest'))",
},
{
task: "ShellScript@2",
Expand Down Expand Up @@ -637,7 +636,7 @@ const manifestGenerationPipelineYaml = (): string => {
displayName:
"If configured, update manifest pipeline details in Spektate db after manifest generation",
condition:
"and(ne(variables['INTROSPECTION_ACCOUNT_NAME'], ''), ne(variables['INTROSPECTION_ACCOUNT_KEY'], ''),ne(variables['INTROSPECTION_TABLE_NAME'], ''),ne(variables['INTROSPECTION_PARTITION_KEY'], ''))",
"and(ne(variables['INTROSPECTION_ACCOUNT_NAME'], ''), ne(variables['INTROSPECTION_ACCOUNT_KEY'], ''),ne(variables['INTROSPECTION_TABLE_NAME'], ''),ne(variables['INTROSPECTION_PARTITION_KEY'], ''), ne(variables['Build.Reason'], 'PullRequest'))",
},
],
};
Expand Down
8 changes: 7 additions & 1 deletion src/test/mockFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ export const createTestServiceBuildAndUpdatePipelineYaml = (
},
{
script: generateYamlScript([
`export BUILD_REPO_NAME=$(echo $(Build.Repository.Name)-${serviceName} | tr '[:upper:]' '[:lower:]')`,
// Iterate through serviceBuildVariables, export each variable, then append as build argument
`ACR_BUILD_BASE_COMMAND='az acr build -r $(ACR_NAME) --image $IMAGE_NAME .'`,
`SERVICE_BUILD_VARIABLES=$(echo \${serviceBuildVariables} | tr "," " " )`,
`echo "Service Variables: $SERVICE_BUILD_VARIABLES`,
`VARIABLES_ARRAY=(echo $SERVICE_BUILD_VARIABLES)`,
`for i in \${VARIABLES_ARRAY[@]}; do export $i=\${i} ; ACR_BUILD_BASE_COMMAND+=" --build-arg $i=\${i}" ; done`,
`export BUILD_REPO_NAME=${BUILD_REPO_NAME(serviceName)}`,
`export IMAGE_TAG=${IMAGE_TAG}`,
`export IMAGE_NAME=$BUILD_REPO_NAME:$IMAGE_TAG`,
`echo "Image Name: $IMAGE_NAME"`,
Expand Down

0 comments on commit 42394ef

Please sign in to comment.