@@ -31,21 +31,49 @@ test_config_dir="${test_dir}/${go_architecture}"
31
31
# If a configuration folder for the architecture doesn't exist, default to amd64
32
32
test -d ${test_config_dir} || test_config_dir=" ${test_dir} /amd64"
33
33
34
- echo " ##"
35
- echo " # Build the newest 'container structure test' binary"
36
- echo " ##"
34
+
35
+ function HEADER() {
36
+ local msg=" $1 "
37
+ echo " "
38
+ echo " ###############"
39
+ echo " # $msg "
40
+ echo " ###############"
41
+ echo " "
42
+ }
43
+
44
+ HEADER " Determine the runtime"
45
+
46
+ DOCKER=" "
47
+ if which docker > /dev/null; then
48
+ DOCKER=$( which docker)
49
+ echo " Using docker at $( which docker) "
50
+ elif which podman > /dev/null; then
51
+ DOCKER=$( which podman)
52
+ echo " Using podman at $( which podman) "
53
+ else
54
+ echo " Could not find a runtime to run tests"
55
+ exit 1
56
+ fi
57
+
58
+ docker () {
59
+ $DOCKER $@
60
+ }
61
+
62
+
63
+ HEADER " Build the newest 'container structure test' binary"
64
+
37
65
cp -f " ${test_dir} /Dockerfile" " ${test_dir} /../Dockerfile"
38
- make
39
- make cross
40
- make image
66
+ make DOCKER= $DOCKER
67
+ make DOCKER= $DOCKER cross
68
+ make DOCKER= $DOCKER image
41
69
42
70
# Run the ubuntu tests, they should always pass on 20.04
43
71
test_image=" ubuntu:20.04"
44
72
docker pull " $test_image " > /dev/null
45
73
46
- echo " ## "
47
- echo " # Positive Test Case"
48
- echo " ## "
74
+
75
+ HEADER " Positive Test Case"
76
+
49
77
res=$( ./out/container-structure-test test --image " $test_image " --config " ${test_config_dir} /ubuntu_20_04_test.yaml" )
50
78
code=$?
51
79
if ! [[ (" $res " =~ " PASS" && " $code " == " 0" ) ]];
57
85
echo " PASS: Success test case passed"
58
86
fi
59
87
60
- echo " ##"
61
- echo " # Metadata Test Case"
62
- echo " ##"
88
+
89
+ HEADER " Metadata Test Case"
63
90
# test image metadata
64
91
run_metadata_tests=true
65
92
if $run_metadata_tests ;
66
93
then
67
- test_metadata_image=debian8-with-metadata:latest
94
+ test_metadata_image=test.local/ debian8-with-metadata:latest
68
95
test_metadata_tar=debian8-with-metadata.tar
69
96
test_metadata_dir=debian8-with-metadata
70
97
docker build -q -f " $test_dir " /Dockerfile.metadata --tag " $test_metadata_image " " $test_dir " > /dev/null
93
120
fi
94
121
95
122
mkdir -p " $test_metadata_dir "
96
- tar -C " $test_metadata_dir " -xvf " $test_metadata_tar " > /dev/null
97
- test_metadata_json=$( grep ' Config":"\K[^"]+ ' -Po " $test_metadata_dir /manifest.json" )
123
+ tar -C " $test_metadata_dir " -xf " $test_metadata_tar " > /dev/null
124
+ test_metadata_json=$( jq -r ' .[0].Config ' " $test_metadata_dir /manifest.json" )
98
125
res=$( ./out/container-structure-test test --driver host --force --metadata " $test_metadata_dir /$test_metadata_json " --config " ${test_config_dir} /ubuntu_20_04_metadata_test.yaml" )
99
126
code=$?
100
127
if ! [[ (" $res " =~ " PASS" && " $code " == " 0" ) ]];
111
138
docker rmi " $test_metadata_image " > /dev/null
112
139
fi
113
140
114
- echo " ## "
115
- echo " # Failure Test Case"
116
- echo " ## "
141
+
142
+ HEADER " Failure Test Case"
143
+
117
144
# Run some bogus tests, they should fail as expected
118
145
res=$( ./out/container-structure-test test --image " $test_image " --config " ${test_config_dir} /ubuntu_20_04_failure_test.yaml" )
119
146
code=$?
@@ -127,15 +154,13 @@ else
127
154
fi
128
155
129
156
130
- echo " ###"
131
- echo " # OCI layout test case"
132
- echo " ###"
133
157
134
- go install github.com/google/go-containerregistry/cmd/crane/cmd
135
- tmp=" $( mktemp -d) "
158
+ HEADER " OCI layout test case"
136
159
160
+ go install github.com/google/go-containerregistry/cmd/crane
161
+ tmp=" $( mktemp -d) "
137
162
138
- crane pull " $test_image " --format=oci " $tmp " --platform=linux/${ go_architecture}
163
+ crane pull " $test_image " --format=oci " $tmp " --platform=" linux/$go_architecture "
139
164
140
165
141
166
res=$( ./out/container-structure-test test --image-from-oci-layout=" $tmp " --config " ${test_config_dir} /ubuntu_20_04_test.yaml" 2>&1 )
150
175
echo " PASS: oci failing test case"
151
176
fi
152
177
153
- res=$( ./out/container-structure-test test --image-from-oci-layout=" $tmp " --default-image-tag=" test.local/library/ $test_image " --config " ${test_config_dir} /ubuntu_20_04_test.yaml" 2>&1 )
178
+ res=$( ./out/container-structure-test test --image-from-oci-layout=" $tmp " --default-image-tag=" test.local/$test_image " --config " ${test_config_dir} /ubuntu_20_04_test.yaml" 2>&1 )
154
179
code=$?
155
180
if ! [[ (" $res " =~ " PASS" && " $code " == " 0" ) ]];
156
181
then
161
186
else
162
187
echo " PASS: oci success test case"
163
188
fi
189
+
190
+ if [ $failures -gt 0 ]; then
191
+ echo " Some tests did not pass. $failures "
192
+ exit 1
193
+ fi
0 commit comments