Skip to content

Commit 217b0dc

Browse files
tests: fix and add more tests
1 parent e05df88 commit 217b0dc

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

tests/unit/general/scripts-sbom.bats

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
# bats file_tags=scripts-sbom
44

5-
sbom_backup=$(mktemp --suffix=-sbom.json)
6-
velero_chart_backup=$(mktemp --suffix=-velero-chart.json)
7-
85
setup() {
96
load "../../bats.lib.bash"
107
load_assert
@@ -14,16 +11,7 @@ setup() {
1411

1512
export CK8S_AUTO_APPROVE=false
1613
export CK8S_SKIP_VALIDATION=false
17-
VELERO_CHART_RELATIVE_FOLDER=helmfile.d/upstream/vmware-tanzu/velero
18-
VELERO_CHART="${ROOT}/${VELERO_CHART_RELATIVE_FOLDER}/Chart.yaml"
19-
20-
cp "${ROOT}/docs/sbom.json" "${sbom_backup}"
21-
cp "${VELERO_CHART}" "${velero_chart_backup}"
22-
}
23-
24-
teardown() {
25-
mv --force "${sbom_backup}" "${ROOT}/docs/sbom.json"
26-
mv --force "${velero_chart_backup}" "${VELERO_CHART}"
14+
VELERO_CHART_LOCATION=helmfile.d/upstream/vmware-tanzu/velero
2715
}
2816

2917
@test "sbom script should show usage if no command is given" {
@@ -32,34 +20,45 @@ teardown() {
3220
assert_output --partial "COMMANDS:"
3321
}
3422

35-
@test "sbom script get existing component" {
36-
run sbom.bash get "${VELERO_CHART_RELATIVE_FOLDER}"
23+
@test "sbom script get existing component be successful" {
24+
run sbom.bash get "${VELERO_CHART_LOCATION}"
3725
assert_success
3826
assert_output --partial '"name": "velero"'
3927
}
4028

41-
@test "sbom script get non-existing component" {
29+
@test "sbom script get non-existing component should fail" {
4230
run sbom.bash get non-existing
4331
assert_failure
4432
}
4533

34+
@test "sbom script get-charts should be successful" {
35+
run sbom.bash get-charts
36+
assert_success
37+
assert_output --partial "${VELERO_CHART_LOCATION}"
38+
}
39+
40+
@test "sbom script get-containers should be successful" {
41+
run sbom.bash get-containers
42+
assert_success
43+
}
44+
4645
@test "sbom script validate should be successful" {
4746
run sbom.bash validate
4847
assert_success
4948
assert_output --partial 'BOM validated successfully.'
5049
}
5150

52-
@test "sbom script add component with unsupported key" {
53-
run sbom.bash add "${VELERO_CHART_RELATIVE_FOLDER}" unsupported-key "foo"
51+
@test "sbom script add component with unsupported key should fail" {
52+
run sbom.bash add "${VELERO_CHART_LOCATION}" unsupported-key "foo"
5453
assert_failure
5554
assert_output --partial 'unsupported key'
5655
}
5756

58-
@test "sbom script add component with supported key properties" {
59-
export CK8S_AUTO_APPROVE=true
60-
run sbom.bash add "${VELERO_CHART_RELATIVE_FOLDER}" properties "foo" "bar"
57+
@test "sbom script add component with supported key properties should prompt" {
58+
run sbom.bash add "${VELERO_CHART_LOCATION}" properties "foo" "bar" <<<n
6159
assert_success
62-
assert_output --partial 'Updated properties'
60+
assert_output --partial 'BOM validated successfully.'
61+
assert_output --partial 'Do you want to continue?'
6362
}
6463

6564
@test "sbom script generate requires GITHUB_TOKEN" {
@@ -69,14 +68,19 @@ teardown() {
6968
}
7069

7170
@test "sbom script update requires GITHUB_TOKEN" {
72-
GITHUB_TOKEN="" run sbom.bash update "${VELERO_CHART_RELATIVE_FOLDER}"
71+
GITHUB_TOKEN="" run sbom.bash update "${VELERO_CHART_LOCATION}"
7372
assert_failure
7473
assert_output --partial "Missing GITHUB_TOKEN"
7574
}
7675

77-
@test "sbom script update with no change should work" {
78-
export CK8S_SKIP_VALIDATION=true
79-
GITHUB_TOKEN="test" run sbom.bash update "${VELERO_CHART_RELATIVE_FOLDER}"
76+
@test "sbom script update with no change should be successful" {
77+
CK8S_SKIP_VALIDATION=true GITHUB_TOKEN="test" run sbom.bash update "${VELERO_CHART_LOCATION}"
8078
assert_success
8179
assert_output --partial "No change"
8280
}
81+
82+
@test "sbom script diff with no change should be successful" {
83+
CK8S_SKIP_VALIDATION=true GITHUB_TOKEN="test" run sbom.bash diff
84+
assert_success
85+
assert_output --partial "No chart changes found"
86+
}

0 commit comments

Comments
 (0)