Skip to content

Commit 7a0d890

Browse files
committed
add test cases for validation process
1 parent bc0367b commit 7a0d890

9 files changed

+98
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "status": "OK", "version": "v2.999.0", "sha": "1234567890ABCDEF" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "status": "OK", "version": "undefined", "sha": "undefined"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Invalid Response Format"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "status": "OK", "version": "v2.999.0", "sha": "BAD_SHA" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "status": "BAD_STATUS", "version": "v2.999.0", "sha": "1234567890ABCDEF" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "status": "OK", "version": "v1.0.0-BAD", "sha": "1234567890ABCDEF" }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bats
2+
3+
load 'test_helpers'
4+
5+
@test "Test bogus URL" {
6+
run ./scripts/app-workflows/fetch-deploy-info.sh "http://localhost/bogus-url"
7+
test_value 1 "$status"
8+
test_value "Failed to fetch the verification URL: http://localhost/bogus-url" "${lines[0]}"
9+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bats
2+
3+
load 'test_helpers'
4+
5+
@test "Test bad status" {
6+
fixture=$(load_json_fixture "validate-status-error.json")
7+
run ./scripts/app-workflows/validate-deploy.sh $fixture "v2.999.0" "1234567890ABCDEF"
8+
test_value 1 "$status"
9+
test_value "Validation failed: status is not OK" "${lines[0]}"
10+
test_value "Expected: OK, Actual: BAD_STATUS" "${lines[1]}"
11+
}
12+
13+
@test "Test incorrect version" {
14+
fixture=$(load_json_fixture "validate-version-error.json")
15+
run ./scripts/app-workflows/validate-deploy.sh $fixture "v2.999.0" "1234567890ABCDEF"
16+
test_value 1 "$status"
17+
test_value "Validation failed: version mismatch" "${lines[0]}"
18+
test_value "Expected: v2.999.0, Actual: v1.0.0-BAD" "${lines[1]}"
19+
}
20+
21+
@test "Test incorrect sha" {
22+
fixture=$(load_json_fixture "validate-sha-error.json")
23+
run ./scripts/app-workflows/validate-deploy.sh $fixture "v2.999.0" "1234567890ABCDEF"
24+
test_value 1 "$status"
25+
test_value "Validation failed: sha mismatch" "${lines[0]}"
26+
test_value "Expected: 1234567890ABCDEF, Actual: BAD_SHA" "${lines[1]}"
27+
}
28+
29+
@test "Test valid response" {
30+
fixture=$(load_json_fixture "validate-good-response.json")
31+
run ./scripts/app-workflows/validate-deploy.sh $fixture "v2.999.0" "1234567890ABCDEF"
32+
test_value 0 "$status"
33+
}
34+
35+
@test "Test non-JSON response" {
36+
fixture=$(load_json_fixture "validate-non-json-response.json")
37+
run ./scripts/app-workflows/validate-deploy.sh '$fixture' "v2.999.0" "1234567890ABCDEF"
38+
test_value 1 "$status"
39+
test_value "Error: Invalid JSON string" "${lines[0]}"
40+
}
41+
42+
@test "Test invalid JSON response" {
43+
fixture=$(load_json_fixture "validate-invalid-json-response.json")
44+
run ./scripts/app-workflows/validate-deploy.sh '$fixture' "v2.999.0" "1234567890ABCDEF"
45+
test_value 1 "$status"
46+
test_value "Error: Invalid JSON string" "${lines[0]}"
47+
}
48+
49+
@test "Test empty response" {
50+
run ./scripts/app-workflows/validate-deploy.sh "" "v2.999.0" "1234567890ABCDEF"
51+
test_value 1 "$status"
52+
test_value "Error: Invalid JSON string" "${lines[0]}"
53+
}

tests/scripts/app-workflows/test_helpers.bash

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,34 @@
33
test_value() {
44
local expected="$1"
55
local actual="$2"
6-
diff <(echo "$actual") <(echo "$expected") || { echo -e "expected: $expected\nactual: '$actual'"; return 1; }
6+
diff <(echo "$actual") <(echo "$expected") || { echo -e "expected: '$expected'\nactual: '$actual'"; return 1; }
7+
}
8+
9+
load_json_fixture() {
10+
local fixture_filename="$1"
11+
fixtures_dir="./tests/scripts/app-workflows/fixtures"
12+
fixture_fullpath="$fixtures_dir/$fixture_filename"
13+
14+
run cat "$fixture_fullpath"
15+
fixture=$output
16+
17+
# Validate and reformat the fixture as a JSON string
18+
if echo "$fixture" | jq empty > /dev/null 2>&1; then
19+
# If valid, reformat the JSON string
20+
fixture_json=$(echo "$fixture" | jq -c .)
21+
else
22+
# Let bad data through for testing
23+
fixture_json=$fixture
24+
# exit 1
25+
fi
26+
27+
echo "$fixture_json"
28+
}
29+
30+
script_fullpath() {
31+
local script_filename="$1"
32+
scripts_dir="./scripts/app-workflows"
33+
fullpath="$scripts_dir/$script_filename"
34+
35+
echo "$fullpath"
736
}

0 commit comments

Comments
 (0)