forked from LaconicNetwork/kompose
Fixing functional tests for checking generated artifacts
Earlier any test written after check_file_exist would fail, so fixed it with new function.
This commit is contained in:
parent
6e260bab0b
commit
26e348e731
@ -167,28 +167,36 @@ function convert::expect_failure() {
|
|||||||
}
|
}
|
||||||
readonly -f convert::expect_failure
|
readonly -f convert::expect_failure
|
||||||
|
|
||||||
function convert::files_exist() {
|
# see if the given files exists
|
||||||
local cmd=$1
|
function utils::file_exists() {
|
||||||
local dir=$2
|
for file in "$@"
|
||||||
|
|
||||||
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 "$@"
|
|
||||||
do
|
do
|
||||||
if [ ! -f $var ]
|
exit_status=$([ -f $file ]; echo $?)
|
||||||
then
|
if [ $exit_status -ne 0 ]; then convert::print_fail "$file does not exist\n"; EXIT_STATUS=1;
|
||||||
convert::print_fail "file $var does not exist\n"
|
else convert::print_pass "$file exists\n"; fi
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
convert::print_pass "file $var exists\n"
|
|
||||||
done
|
done
|
||||||
convert::teardown
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
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 $exit_status
|
||||||
|
}
|
||||||
|
readonly -f convert::check_artifacts_generated
|
||||||
@ -165,14 +165,12 @@ convert::expect_success "kompose --provider openshift -f $KOMPOSE_ROOT/script/te
|
|||||||
######
|
######
|
||||||
# Test the output file behavior of kompose convert
|
# Test the output file behavior of kompose convert
|
||||||
# Default behavior without -o
|
# 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 <filename>
|
# Behavior with -o <filename>
|
||||||
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 <dirname>
|
# Behavior with -o <dirname>
|
||||||
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 <dirname>/<filename>
|
# Behavior with -o <dirname>/<filename>
|
||||||
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"
|
convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/examples/docker-compose.yml convert -o $TEMP_DIR/output_file -j" "$TEMP_DIR/output_file"
|
||||||
# Behavior with -o <dirname>/<dirname>/<filename>
|
|
||||||
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"
|
|
||||||
|
|
||||||
exit $EXIT_STATUS
|
exit $EXIT_STATUS
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user