2
2
3
3
# bats file_tags=scripts-sbom
4
4
5
- sbom_backup=$( mktemp --suffix=-sbom.json)
6
- velero_chart_backup=$( mktemp --suffix=-velero-chart.json)
7
-
8
5
setup () {
9
6
load " ../../bats.lib.bash"
10
7
load_assert
@@ -14,16 +11,7 @@ setup() {
14
11
15
12
export CK8S_AUTO_APPROVE=false
16
13
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
27
15
}
28
16
29
17
@test " sbom script should show usage if no command is given" {
@@ -32,34 +20,45 @@ teardown() {
32
20
assert_output --partial " COMMANDS:"
33
21
}
34
22
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 } "
37
25
assert_success
38
26
assert_output --partial ' "name": "velero"'
39
27
}
40
28
41
- @test " sbom script get non-existing component" {
29
+ @test " sbom script get non-existing component should fail " {
42
30
run sbom.bash get non-existing
43
31
assert_failure
44
32
}
45
33
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
+
46
45
@test " sbom script validate should be successful" {
47
46
run sbom.bash validate
48
47
assert_success
49
48
assert_output --partial ' BOM validated successfully.'
50
49
}
51
50
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"
54
53
assert_failure
55
54
assert_output --partial ' unsupported key'
56
55
}
57
56
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
61
59
assert_success
62
- assert_output --partial ' Updated properties'
60
+ assert_output --partial ' BOM validated successfully.'
61
+ assert_output --partial ' Do you want to continue?'
63
62
}
64
63
65
64
@test " sbom script generate requires GITHUB_TOKEN" {
@@ -69,14 +68,19 @@ teardown() {
69
68
}
70
69
71
70
@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 } "
73
72
assert_failure
74
73
assert_output --partial " Missing GITHUB_TOKEN"
75
74
}
76
75
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} "
80
78
assert_success
81
79
assert_output --partial " No change"
82
80
}
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