Skip to content

Commit 465f63c

Browse files
authored
fix(tests): improve test compatibility for macOS and podman (#2080)
#### What type of PR is this? <!-- Add one of the following kinds: /kind bug /kind documentation /kind feature --> /kind cleanup #### What this PR does / why we need it: - Remove deprecated 'version' attribute that we no longer use across all fixture files (confirmed they still convert 1-1) - Added macOS compatibility, using grealpath instead since it's a bit different on macOS vs Linux - Container connection on build for machines without podman or docker - Fixed typos - Fixes tests usually having warnings that no longer do - Fix bug with state validation TLDR; CI is finally passing again after some clean up #### Which issue(s) this PR fixes: <!-- *Automatically closes linked issue when PR is merged. Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> N/A, spring clean up fixing up Kompose testing again for any newcomers #### Special notes for your reviewer: Signed-off-by: Charlie Drage <[email protected]>
1 parent a1a8374 commit 465f63c

File tree

110 files changed

+59
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+59
-148
lines changed

script/test/cmd/tests.sh

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ else
2121
KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..)
2222
fi
2323

24+
# for mac (GNU realpath)
25+
realpath_cmd="realpath"
26+
if type "grealpath" > /dev/null 2>&1; then
27+
realpath_cmd="grealpath"
28+
fi
29+
30+
# Check for container runtime (docker or podman)
31+
# These are needed for --build local tests
32+
CONTAINER_RUNTIME=""
33+
BUILD_CMD_FLAGS=""
34+
if docker info > /dev/null 2>&1; then
35+
CONTAINER_RUNTIME="docker"
36+
elif podman info > /dev/null 2>&1; then
37+
CONTAINER_RUNTIME="podman"
38+
BUILD_CMD_FLAGS="--build-command 'podman build' --push-command 'podman push'"
39+
fi
40+
2441
source $KOMPOSE_ROOT/script/test/cmd/lib.sh
2542

2643
# Get current branch and remote url of git repository
@@ -48,8 +65,8 @@ os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/$DIR/
4865
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/$DIR/output-k8s.yaml"
4966
os_output="$KOMPOSE_ROOT/script/test/fixtures/$DIR/output-os.yaml"
5067

51-
convert::expect_success "$k8s_cmd" "$k8s_output"
52-
convert::expect_success "$os_cmd" "$os_output"
68+
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output"
69+
convert::expect_success_and_warning "$os_cmd" "$os_output"
5370

5471

5572

@@ -88,24 +105,29 @@ convert::check_artifacts_generated "kompose --provider=openshift -f $KOMPOSE_ROO
88105

89106

90107
######
91-
# Test the path of build image
92-
# Test build v2 absolute compose file
93-
convert::check_artifacts_generated "kompose --build local -f $KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose.yaml convert -o $TEMP_DIR/output_file" "$TEMP_DIR/output_file"
94-
# Test build v2 relative compose file
95-
relative_path=$(realpath --relative-to="$PWD" "$KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose.yaml")
96-
convert::check_artifacts_generated "kompose --build local -f $relative_path convert -o $TEMP_DIR/output_file" "$TEMP_DIR/output_file"
97-
# Test build v3 absolute compose file with context
98-
convert::check_artifacts_generated "kompose --build local -f $KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose-v3.yaml convert -o $TEMP_DIR/output_file" "$TEMP_DIR/output_file"
99-
# Test build v3 relative compose file with context
100-
relative_path=$(realpath --relative-to="$PWD" "$KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose-v3.yaml")
101-
convert::check_artifacts_generated "kompose --build local -f $relative_path convert -o $TEMP_DIR/output_file" "$TEMP_DIR/output_file"
102-
103-
# #####
104-
# Test the build config with push image
105-
# see tests_push_image.sh for local push test
106-
# Should warn when push image disabled
107-
cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose-build-no-image.yaml -o $TEMP_DIR/output_file convert --build=local --push-image-registry=whatever"
108-
convert::expect_warning "$cmd" "Push image registry 'whatever' is specified but push image is disabled, skipping pushing to repository"
108+
# Test the path of build image (requires docker or podman)
109+
if [ -n "$CONTAINER_RUNTIME" ]; then
110+
echo "Container runtime detected: $CONTAINER_RUNTIME - running build tests"
111+
# Test build v2 absolute compose file
112+
convert::check_artifacts_generated "kompose --build local $BUILD_CMD_FLAGS -f $KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose.yaml convert -o $TEMP_DIR/output_file" "$TEMP_DIR/output_file"
113+
# Test build v2 relative compose file
114+
relative_path=$($realpath_cmd --relative-to="$PWD" "$KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose.yaml")
115+
convert::check_artifacts_generated "kompose --build local $BUILD_CMD_FLAGS -f $relative_path convert -o $TEMP_DIR/output_file" "$TEMP_DIR/output_file"
116+
# Test build v3 absolute compose file with context
117+
convert::check_artifacts_generated "kompose --build local $BUILD_CMD_FLAGS -f $KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose-v3.yaml convert -o $TEMP_DIR/output_file" "$TEMP_DIR/output_file"
118+
# Test build v3 relative compose file with context
119+
relative_path=$($realpath_cmd --relative-to="$PWD" "$KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose-v3.yaml")
120+
convert::check_artifacts_generated "kompose --build local $BUILD_CMD_FLAGS -f $relative_path convert -o $TEMP_DIR/output_file" "$TEMP_DIR/output_file"
121+
122+
# #####
123+
# Test the build config with push image
124+
# see tests_push_image.sh for local push test
125+
# Should warn when push image disabled
126+
cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/buildconfig/compose-build-no-image.yaml -o $TEMP_DIR/output_file convert --build=local $BUILD_CMD_FLAGS --push-image-registry=whatever"
127+
convert::expect_warning "$cmd" "Push image registry 'whatever' is specified but push image is disabled, skipping pushing to repository"
128+
else
129+
echo "SKIP: Build tests require docker or podman (neither is running)"
130+
fi
109131

110132
#TEST the kompose.volume.storage-class-name label
111133
convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/script/test/fixtures/storage-class-name/compose.yaml convert -o $TEMP_DIR/output-k8s.yaml" "$TEMP_DIR/output-k8s.yaml"
@@ -159,8 +181,8 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/compose.
159181
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-k8s-empty-vols-template.yaml"
160182
os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/compose.yaml convert --with-kompose-annotation=false --stdout --volumes emptyDir"
161183
os_output="$KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-os-empty-vols-template.yaml"
162-
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
163-
convert::expect_success "$os_cmd" "$os_output" || exit 1
184+
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
185+
convert::expect_success_and_warning "$os_cmd" "$os_output" || exit 1
164186

165187
# Test that emptyvols works
166188
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/compose.yaml convert --with-kompose-annotation=false --stdout --emptyvols"
@@ -205,8 +227,8 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/statefulset/compose.yaml
205227
ocp_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/statefulset/compose.yaml convert --stdout --with-kompose-annotation=false --controller statefulset"
206228
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/statefulset/output-k8s.yaml"
207229
ocp_output="$KOMPOSE_ROOT/script/test/fixtures/statefulset/output-os.yaml"
208-
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
209-
convert::expect_success "$ocp_cmd" "$ocp_output" || exit 1
230+
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
231+
convert::expect_success_and_warning "$ocp_cmd" "$ocp_output" || exit 1
210232

211233
# test cronjob
212234
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/cronjob/compose.yaml convert --stdout --with-kompose-annotation=false"
@@ -222,7 +244,7 @@ os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/mul
222244
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/multiple-type-volumes/output-k8s.yaml"
223245
os_output="$KOMPOSE_ROOT/script/test/fixtures/multiple-type-volumes/output-os.yaml"
224246
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
225-
convert::expect_success "$os_cmd" "$os_output" || exit 1
247+
convert::expect_success_and_warning "$os_cmd" "$os_output" || exit 1
226248

227249
# Test environment variables interpolation
228250
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/envvars-interpolation/compose.yaml convert --stdout --with-kompose-annotation=false"
@@ -237,8 +259,8 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/env-dotenv/compose.yaml c
237259
os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/env-dotenv/compose.yaml convert --stdout --with-kompose-annotation=false"
238260
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/env-dotenv/output-k8s.yaml"
239261
os_output="$KOMPOSE_ROOT/script/test/fixtures/env-dotenv/output-os.yaml"
240-
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
241-
convert::expect_success_and_warning "$os_cmd" "$os_output" || exit 1
262+
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
263+
convert::expect_success "$os_cmd" "$os_output" || exit 1
242264

243265
# Test single file output feature
244266
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/single-file-output/compose.yaml convert --stdout --with-kompose-annotation=false"
@@ -275,7 +297,7 @@ k8s_output="$KOMPOSE_ROOT/script/test/fixtures/fsgroup/output-k8s.yaml"
275297
os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/fsgroup/compose.yaml convert --stdout --with-kompose-annotation=false"
276298
os_output="$KOMPOSE_ROOT/script/test/fixtures/fsgroup/output-os.yaml"
277299
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
278-
convert::expect_success "$os_cmd" "$os_output" || exit 1
300+
convert::expect_success_and_warning "$os_cmd" "$os_output" || exit 1
279301

280302
# Test support for compose.yaml file
281303
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/compose-file-support/compose.yaml convert --stdout --with-kompose-annotation=false"
@@ -286,29 +308,27 @@ convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
286308
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/compose-env-interpolation/compose.yaml convert --stdout --with-kompose-annotation=false"
287309
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/compose-env-interpolation/output-k8s.yaml"
288310
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
289-
convert::expect_success "$os_cmd" "$os_output" || exit 1
290311

291312
# Test support for compose env without interpolation
292313
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/compose-env-no-interpolation/compose.yaml convert --stdout --no-interpolate --with-kompose-annotation=false"
293314
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/compose-env-no-interpolation/output-k8s.yaml"
294315
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
295-
convert::expect_success "$os_cmd" "$os_output" || exit 1
296316

297-
# Test configmap generated by env_file with variable interpolation
317+
# Test configmap generated by env_file with variable interpolation
298318
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/envfile-interpolation/compose.yaml convert --stdout --with-kompose-annotation=false"
299319
os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/envfile-interpolation/compose.yaml convert --stdout --with-kompose-annotation=false"
300320
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/envfile-interpolation/output-k8s.yaml"
301321
os_output="$KOMPOSE_ROOT/script/test/fixtures/envfile-interpolation/output-os.yaml"
302-
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
303-
convert::expect_success_and_warning "$os_cmd" "$os_output" || exit 1
322+
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
323+
convert::expect_success "$os_cmd" "$os_output" || exit 1
304324

305325
# Test support for subpath volume
306326
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/vols-subpath/compose.yaml convert --stdout --with-kompose-annotation=false"
307327
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/vols-subpath/output-k8s.yaml"
308328
os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/vols-subpath/compose.yaml convert --stdout --with-kompose-annotation=false"
309329
os_output="$KOMPOSE_ROOT/script/test/fixtures/vols-subpath/output-os.yaml"
310330
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
311-
convert::expect_success "$os_cmd" "$os_output" || exit 1
331+
convert::expect_success_and_warning "$os_cmd" "$os_output" || exit 1
312332

313333
# Test support for network policies generation
314334
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/network-policies/compose.yaml convert --generate-network-policies --stdout --with-kompose-annotation=false"
@@ -371,10 +391,10 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/initcontainer/compose.yam
371391
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/initcontainer/output-k8s.yaml"
372392
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
373393

374-
# Test HPA
394+
# Test HPA
375395
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/hpa/compose.yaml convert --stdout --with-kompose-annotation=false"
376396
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/hpa/output-k8s.yaml"
377-
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
397+
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
378398

379399
#Test auto configmaps from files/dir
380400
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/configmap-file-configs/compose-1.yaml convert --stdout --with-kompose-annotation=false"
@@ -397,13 +417,13 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/configmap-file-configs/co
397417
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-file-configs/output-k8s-3.yaml"
398418
os_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/configmap-file-configs/compose-3.yaml convert --provider openshift --stdout --with-kompose-annotation=false"
399419
os_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-file-configs/output-os-3.yaml"
400-
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
401-
convert::expect_success "$os_cmd" "$os_output" || exit 1
420+
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
421+
convert::expect_success_and_warning "$os_cmd" "$os_output" || exit 1
402422

403423
# Test network_mode: service:
404424
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/network-mode-service/compose.yaml convert --stdout --with-kompose-annotation=false"
405425
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/network-mode-service/output-k8s.yaml"
406-
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
426+
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
407427

408428
# Test env var with status
409429
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/envvars-with-status/compose.yaml convert --stdout --with-kompose-annotation=false"

script/test/fixtures/buildargs/compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "2"
21

32
services:
43
foo:

script/test/fixtures/buildconfig/compose-build-no-image.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "2"
21

32
services:
43
foo:

script/test/fixtures/buildconfig/compose-dockerfile.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "2"
21

32
services:
43
foo:

script/test/fixtures/buildconfig/compose-v3.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3"
21

32
services:
43
foo:

script/test/fixtures/buildconfig/compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "2"
21

32
services:
43
foo:

script/test/fixtures/change-in-volume/compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '2'
21
services:
32
web:
43
image: flask_web

script/test/fixtures/compose-env-interpolation/compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21

32
services:
43
foo:

script/test/fixtures/compose-env-no-interpolation/compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21

32
services:
43
foo:

script/test/fixtures/compose-file-env-variable/alternative-compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3"
21
services:
32
alpine:
43
image: alpine

0 commit comments

Comments
 (0)