diff --git a/script/test/cmd/lib.sh b/script/test/cmd/lib.sh index 1fbd8d5a..dcfe52ad 100644 --- a/script/test/cmd/lib.sh +++ b/script/test/cmd/lib.sh @@ -167,28 +167,36 @@ function convert::expect_failure() { } readonly -f convert::expect_failure -function convert::files_exist() { - local cmd=$1 - local dir=$2 - - convert::start_test "convert::files_exist: Running: '${cmd}'" - mkdir -p $dir 2> /dev/null - - cd $TEMP_DIR && convert::run_cmd $cmd - exit_status=$? - - shift - shift - - for var in "$@" +# see if the given files exists +function utils::file_exists() { + for file in "$@" do - if [ ! -f $var ] - then - convert::print_fail "file $var does not exist\n" - return 1 - fi - convert::print_pass "file $var exists\n" + exit_status=$([ -f $file ]; echo $?) + if [ $exit_status -ne 0 ]; then convert::print_fail "$file does not exist\n"; EXIT_STATUS=1; + else convert::print_pass "$file exists\n"; fi done +} +readonly -f utils::file_exists + +# delete given files one by one +function utils::remove_files() { + for file in "$@" + do + rm $file + done +} +readonly -f utils::remove_files + +function convert::check_artifacts_generated() { + local cmd=$1 + + convert::start_test "convert::check_artifacts_generated: Running: '${cmd}'" + convert::run_cmd $cmd + # passing all args except the first one + utils::file_exists "${@:2}" + utils::remove_files "${@:2}" + convert::teardown - return 0 -} \ No newline at end of file + return $exit_status +} +readonly -f convert::check_artifacts_generated \ No newline at end of file diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index 1d61bf55..a5664142 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -165,14 +165,12 @@ convert::expect_success "kompose --provider openshift -f $KOMPOSE_ROOT/script/te ###### # Test the output file behavior of kompose convert # Default behavior without -o -convert::files_exist "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -j" "" "$TEMP_DIR/redis-deployment.json -j" "$TEMP_DIR/redis-service.json" "$TEMP_DIR/web-deployment.json" "$TEMP_DIR/web-service.json" +convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -j" "redis-deployment.json" "redis-service.json" "web-deployment.json" "web-service.json" # Behavior with -o -convert::files_exist "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -o output_file -j" "" "$TEMP_DIR/output_file" +convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -o output_file -j" "output_file" # Behavior with -o -convert::files_exist "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -o output_dir -j" "$TEMP_DIR/output_dir/" "$TEMP_DIR/output_dir/redis-deployment.json" "$TEMP_DIR/output_dir/redis-service.json" "$TEMP_DIR/output_dir/web-deployment.json" "$TEMP_DIR/output_dir/web-service.json" +convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -o $TEMP_DIR -j" "$TEMP_DIR/redis-deployment.json" "$TEMP_DIR/redis-service.json" "$TEMP_DIR/web-deployment.json" "$TEMP_DIR/web-service.json" # Behavior with -o / -convert::files_exist "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -o output_dir/output_file -j" "$TEMP_DIR/output_dir/" "$TEMP_DIR/output_dir/output_file" -# Behavior with -o // -convert::files_exist "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -o output_dir/output_dir_nested/output_file -j" "$TEMP_DIR/output_dir/output_dir_nested" "$TEMP_DIR/output_dir/output_dir_nested/output_file" +convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -o $TEMP_DIR/output_file -j" "$TEMP_DIR/output_file" exit $EXIT_STATUS