Skip to content

Commit 9d6f7c5

Browse files
test(sbom): update test to include a range of scenarios
1 parent 666bc89 commit 9d6f7c5

File tree

6 files changed

+146
-2
lines changed

6 files changed

+146
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# Scenario: install_sbom_custom_alias
4+
# Verifies that sbom-tool installs with a custom alias ("msft-sbom")
5+
6+
set -e
7+
8+
source dev-container-features-test-lib
9+
10+
# Verify the custom alias is available on the PATH
11+
check "msft-sbom is installed" bash -c "which msft-sbom"
12+
13+
# Verify the custom alias can report its version
14+
check "msft-sbom version runs" bash -c "msft-sbom version"
15+
16+
# Verify the binary is in the expected location under the custom alias
17+
check "msft-sbom in /usr/local/bin" bash -c "ls /usr/local/bin/msft-sbom"
18+
19+
# Verify the default alias is NOT present (only the custom alias should exist)
20+
check "default sbom-tool alias not present" bash -c "! which sbom-tool"
21+
22+
reportResults

test/sbom/install_sbom_latest.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# Scenario: install_sbom_latest
4+
# Verifies that sbom-tool installs successfully when version is set to "latest"
5+
6+
set -e
7+
8+
source dev-container-features-test-lib
9+
10+
# Verify sbom-tool is installed
11+
check "sbom-tool is installed" bash -c "which sbom-tool"
12+
13+
# Verify sbom-tool version output is not empty
14+
check "sbom-tool version reports output" bash -c "sbom-tool version"
15+
16+
# Verify sbom-tool binary is in the expected location
17+
check "sbom-tool in /usr/local/bin" bash -c "ls /usr/local/bin/sbom-tool"
18+
19+
reportResults
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# Scenario: install_sbom_specific_version
4+
# Verifies that a specific version of sbom-tool (0.3.3) installs correctly
5+
6+
set -e
7+
8+
source dev-container-features-test-lib
9+
10+
# Verify sbom-tool is installed
11+
check "sbom-tool is installed" bash -c "which sbom-tool"
12+
13+
# Verify sbom-tool can run
14+
check "sbom-tool version runs" bash -c "sbom-tool version"
15+
16+
# Verify sbom-tool binary is in the expected location
17+
check "sbom-tool in /usr/local/bin" bash -c "ls /usr/local/bin/sbom-tool"
18+
19+
reportResults

test/sbom/invalid_version.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
# Scenario: invalid_version
4+
# Verifies that the install script's version validation correctly rejects
5+
# a non-existent version. Since the container must build successfully to
6+
# run tests, sbom-tool is installed with "latest" and we then exercise the
7+
# validation logic manually.
8+
9+
set -e
10+
11+
source dev-container-features-test-lib
12+
13+
# sbom-tool should be installed (the scenario uses "latest")
14+
check "sbom-tool is installed" bash -c "which sbom-tool"
15+
16+
# Verify that a completely fake version does NOT appear in the releases list
17+
check "fake version not in releases" bash -c \
18+
"! curl -sL https://api.github.com/repos/microsoft/sbom-tool/releases | jq -r '.[].tag_name' | grep -qx 'v99.99.99'"
19+
20+
# Simulate the install script's validation: attempt to match a non-existent
21+
# version against the release list and confirm it fails
22+
check "validation rejects non-existent version" bash -c '
23+
version_list=$(curl -sL https://api.github.com/repos/microsoft/sbom-tool/releases | jq -r ".[].tag_name")
24+
if echo "${version_list}" | grep -qx "v99.99.99"; then
25+
echo "ERROR: fake version was found in release list"
26+
exit 1
27+
fi
28+
echo "Correctly rejected non-existent version v99.99.99"
29+
'
30+
31+
# Also verify that a valid version IS accepted by the same logic
32+
check "validation accepts a real version" bash -c '
33+
version_list=$(curl -sL https://api.github.com/repos/microsoft/sbom-tool/releases | jq -r ".[].tag_name")
34+
if ! echo "${version_list}" | grep -q "0.3.3"; then
35+
echo "ERROR: valid version 0.3.3 was not found in release list"
36+
exit 1
37+
fi
38+
echo "Correctly accepted valid version 0.3.3"
39+
'
40+
41+
reportResults

test/sbom/scenarios.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"install_sbom_latest": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
4+
"features": {
5+
"sbom": {
6+
"version": "latest"
7+
}
8+
}
9+
},
10+
"install_sbom_specific_version": {
11+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
12+
"features": {
13+
"sbom": {
14+
"version": "0.3.3"
15+
}
16+
}
17+
},
18+
"install_sbom_custom_alias": {
19+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
20+
"features": {
21+
"sbom": {
22+
"version": "latest",
23+
"alias": "msft-sbom"
24+
}
25+
}
26+
},
27+
"invalid_version": {
28+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
29+
"features": {
30+
"sbom": {
31+
"version": "latest"
32+
}
33+
}
34+
}
35+
}

test/sbom/test.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# This test can be run with the following command (from the root of this repo)
44
# devcontainer features test \
5-
# --features sbom-tool \
5+
# --features sbom \
66
# --base-image mcr.microsoft.com/devcontainers/base:ubuntu .
77

88
set -e
@@ -12,7 +12,15 @@ source dev-container-features-test-lib
1212

1313
# Feature-specific tests
1414
# The 'check' command comes from the dev-container-features-test-lib.
15-
check "sbom-tool version" sbom-tool version
15+
16+
# Verify sbom-tool is installed and on the PATH
17+
check "sbom-tool is installed" bash -c "which sbom-tool"
18+
19+
# Verify sbom-tool can report its version
20+
check "sbom-tool version runs" bash -c "sbom-tool version"
21+
22+
# Verify sbom-tool is installed to the expected location
23+
check "sbom-tool in /usr/local/bin" bash -c "ls /usr/local/bin/sbom-tool"
1624

1725
# Report result
1826
# If any of the checks above exited with a non-zero exit code, the test will fail.

0 commit comments

Comments
 (0)