Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit e96489a

Browse files
authored
Improve introspection integration test (#429)
* Improving introspection integration test * Add camelcase ignore * Adding echo -e
1 parent fa9eaf8 commit e96489a

File tree

7 files changed

+39
-17
lines changed

7 files changed

+39
-17
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"open": "^6.4.0",
9696
"shelljs": "^0.8.3",
9797
"simple-git": "^1.126.0",
98-
"spektate": "^1.0.2",
98+
"spektate": "^1.0.4",
9999
"ssh-url": "^0.1.5",
100100
"uuid": "^3.3.3",
101101
"winston": "^3.2.1"

src/commands/deployment/dashboard.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable @typescript-eslint/camelcase */
2-
32
jest.mock("open");
43
import open from "open";
54
jest.mock("../../config");

src/lib/fileutils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ const manifestGenerationPipelineYaml = (): string => {
515515
`get_spk_version`,
516516
`download_spk`,
517517
`message="$(Build.SourceVersionMessage)"`,
518-
`if [[ $message == *"Merged PR"* ]]; then`,
518+
`if [[ $message == *"Merge"* ]]; then`,
519519
`pr_id=$(echo $message | grep -oE '[0-9]+' | head -1 | sed -e 's/^0\\+//')`,
520520
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId --pr $pr_id`,
521521
`else`,

src/test/mockFactory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ export const createTestHldAzurePipelinesYaml = (
447447
`get_spk_version`,
448448
`download_spk`,
449449
`message="$(Build.SourceVersionMessage)"`,
450-
`if [[ $message == *"Merged PR"* ]]; then`,
450+
`if [[ $message == *"Merge"* ]]; then`,
451451
`pr_id=$(echo $message | grep -oE '[0-9]+' | head -1 | sed -e 's/^0\\+//')`,
452452
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId --pr $pr_id`,
453453
`else`,

tests/functions.sh

+3
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ function verify_pipeline_with_poll () {
305305

306306
# We expect only 1 build right now
307307
build_count=$(tr '"\""' '"\\"' <<< "$pipeline_builds" | jq '. | length')
308+
if [[ -z "$expected_build_count" ]]; then
309+
expected_build_count=1
310+
fi
308311
if [ "$build_count" != "$expected_build_count" ]; then
309312
echo "Expected $expected_build_count build for pipeline: $pipeline_name-$pipeline_id but found $build_count"
310313
exit 1

tests/validations.sh

+29-9
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ echo "hld_repo_url $hld_repo_url"
148148
echo "manifest_repo_url $manifest_repo_url"
149149
spk hld install-manifest-pipeline --org-name $AZDO_ORG -d $AZDO_PROJECT --personal-access-token $ACCESS_TOKEN_SECRET -u https://$hld_repo_url -m https://$manifest_repo_url >> $TEST_WORKSPACE/log.txt
150150

151+
##################################
152+
# Temporary: Add a variable group to hld to manifest pipeline manually for testing introspection
153+
# Will no longer be needed once install-manifest-pipeline supports adding a VG
154+
##################################
155+
cd $hld_dir
156+
echo -e "variables:\n - group: $vg_name" | cat - manifest-generation.yaml > temp && mv temp manifest-generation.yaml
157+
git add .
158+
git commit -m "Adding variable group $vg_name to pipeline"
159+
git push origin master
160+
echo "Successfully added variable group $vg_name to hld pipeline"
161+
151162
# Verify hld to manifest pipeline was created
152163
pipeline_created=$(az pipelines show --name $hld_to_manifest_pipeline_name --org $AZDO_ORG_URL --p $AZDO_PROJECT)
153164

@@ -409,32 +420,41 @@ echo "Successfully reached the end of the service validations scripts."
409420
# # SPK Introspection Validation START
410421
# ##################################
411422

423+
pipeline1id=$(az pipelines build list --definition-ids $pipeline_id --organization $AZDO_ORG_URL --project $AZDO_PROJECT | jq '.[0].id')
424+
425+
# Verify hld to manifest pipeline run was successful, to verify the full end-end capture of
426+
# introspection data
427+
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 3
428+
412429
cd $TEST_WORKSPACE
413430
cd ..
414431
if [ -d "tests" ]; then
415432
cd tests
416433
fi
417434
export sa_access_key=$(echo "$sa_access_key" | tr -d '"')
418435
spk init -f ./spk-config-test.yaml
419-
export output=$(spk deployment get -O json > file.json )
436+
spk deployment get --build-id $pipeline1id
437+
export output=$(spk deployment get --build-id $pipeline1id -O json > file.json )
420438
length=$(cat file.json | jq 'length')
421439
if (( length > 0 )); then
422-
echo "$length deployments were returned by spk deployment get"
440+
echo "$length deployment(s) were returned by spk deployment get"
423441
else
424442
echo "Error: Empty JSON was returned from spk deployment get"
425443
exit 1
426444
fi
427445

428-
# Compare $pipeline_id with the data returned by get.
446+
# Parse the response to verify data from get command
447+
srcPipelineId=$(cat file.json | jq '.[].srcToDockerBuild.id')
448+
acrPipelineId=$(cat file.json | jq '.[].dockerToHldReleaseStage.id')
449+
hldPipelineId=$(cat file.json | jq '.[].hldToManifestBuild.id')
450+
prId=$(cat file.json | jq '.[].pr')
429451

430-
listofIds=$(cat file.json | jq '.[].srcToDockerBuild.id')
431-
432-
if [[ $listofIds == *"$pipeline1id"* ]]; then
433-
echo "Pipeline Id $pipeline1id exists. Verified that data exists in storage and could be retrieved."
452+
if [[ "$srcPipelineId" == "$pipeline1id" && "$acrPipelineId" == "$srcPipelineId" && "$hldPipelineId" != "" && "$prId" != "" && "$prId" != "null" ]]; then
453+
echo "Verified that srcPipeline:$srcPipelineId acrPipelineId:$acrPipelineId hldPipelineId:$hldPipelineId pullrequest:$prId are all linked together correctly."
434454
else
435-
echo "Error: Pipeline Id $pipeline1id is not found in data returned from get. "
455+
echo "Error: Data returned from get command does not match expected output:"
456+
cat file.json
436457
exit 1
437458
fi
438-
# --------------------------------
439459

440460
echo "Successfully reached the end of spk deployment get tests."

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -6674,10 +6674,10 @@ spdx-license-ids@^3.0.0:
66746674
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.5.tgz#3694b5804567a458d3c8045842a6358632f62654"
66756675
integrity sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q==
66766676

6677-
spektate@^1.0.2:
6678-
version "1.0.3"
6679-
resolved "https://registry.yarnpkg.com/spektate/-/spektate-1.0.3.tgz#83be22d3b27b780082b37dee19024d6fba14b296"
6680-
integrity sha512-bv8ZJhtcOZrUQaqXOkpxi72ZefKc7xm6sR+CMchBOUhpx4VmROMHB81VvepYP4TOyPzL1r2WqNKm9oaYn1m78g==
6677+
spektate@^1.0.4:
6678+
version "1.0.4"
6679+
resolved "https://registry.yarnpkg.com/spektate/-/spektate-1.0.4.tgz#672e6d7cdf282adadddaf455d1ae41513d522637"
6680+
integrity sha512-Yd31la4eMPg9lX9RztoATeu7fzONunvpPVncbO9jdhoJPkvdrT9jcctFjf1j1rb5/us8rxA0F1Ufju1u3UIv0A==
66816681
dependencies:
66826682
axios "^0.19.0"
66836683
azure-storage "^2.10.3"

0 commit comments

Comments
 (0)