282 lines
8.6 KiB
Diff
282 lines
8.6 KiB
Diff
|
|
From 87c8603713cdcbd0f2abad29c73d3909b3f4c417 Mon Sep 17 00:00:00 2001
|
||
|
|
From: xingweizheng <xingweizheng@huawei.com>
|
||
|
|
Date: Tue, 24 Aug 2021 17:14:47 +0800
|
||
|
|
Subject: [PATCH 4/4] add integration test for saving one image with multiple
|
||
|
|
tags
|
||
|
|
|
||
|
|
---
|
||
|
|
Makefile | 1 +
|
||
|
|
tests/lib/common.sh | 8 +++
|
||
|
|
...gration_test_save_single_image_multiple_tags.sh | 58 ++++++++++++++++++++
|
||
|
|
tests/src/integration_test_set_new_root.sh | 62 ++++++++++++++++++++++
|
||
|
|
tests/src/test_integration_set_new_root.sh | 60 ---------------------
|
||
|
|
tests/test.sh | 9 ++--
|
||
|
|
6 files changed, 134 insertions(+), 64 deletions(-)
|
||
|
|
create mode 100644 tests/src/integration_test_save_single_image_multiple_tags.sh
|
||
|
|
create mode 100644 tests/src/integration_test_set_new_root.sh
|
||
|
|
delete mode 100644 tests/src/test_integration_set_new_root.sh
|
||
|
|
|
||
|
|
diff --git a/Makefile b/Makefile
|
||
|
|
index a9d4c93..1d87625 100644
|
||
|
|
--- a/Makefile
|
||
|
|
+++ b/Makefile
|
||
|
|
@@ -91,6 +91,7 @@ test-unit:
|
||
|
|
.PHONY: test-integration
|
||
|
|
test-integration:
|
||
|
|
@echo "Integration test starting..."
|
||
|
|
+ @./tests/test.sh base
|
||
|
|
@./tests/test.sh integration
|
||
|
|
@echo "Integration test done!"
|
||
|
|
|
||
|
|
diff --git a/tests/lib/common.sh b/tests/lib/common.sh
|
||
|
|
index f393ee1..5e4c208 100755
|
||
|
|
--- a/tests/lib/common.sh
|
||
|
|
+++ b/tests/lib/common.sh
|
||
|
|
@@ -219,3 +219,11 @@ function show_and_run_command() {
|
||
|
|
fi
|
||
|
|
echo "PASS"
|
||
|
|
}
|
||
|
|
+
|
||
|
|
+function run_with_debug() {
|
||
|
|
+ if [ "${DEBUG:-0}" -eq 1 ]; then
|
||
|
|
+ $1
|
||
|
|
+ else
|
||
|
|
+ $1 > /dev/null 2>&1
|
||
|
|
+ fi
|
||
|
|
+}
|
||
|
|
\ No newline at end of file
|
||
|
|
diff --git a/tests/src/integration_test_save_single_image_multiple_tags.sh b/tests/src/integration_test_save_single_image_multiple_tags.sh
|
||
|
|
new file mode 100644
|
||
|
|
index 0000000..a25786a
|
||
|
|
--- /dev/null
|
||
|
|
+++ b/tests/src/integration_test_save_single_image_multiple_tags.sh
|
||
|
|
@@ -0,0 +1,58 @@
|
||
|
|
+#!/bin/bash
|
||
|
|
+
|
||
|
|
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||
|
|
+# isula-build licensed under the Mulan PSL v2.
|
||
|
|
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||
|
|
+# You may obtain a copy of Mulan PSL v2 at:
|
||
|
|
+# http://license.coscl.org.cn/MulanPSL2
|
||
|
|
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||
|
|
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||
|
|
+# PURPOSE.
|
||
|
|
+# See the Mulan PSL v2 for more details.
|
||
|
|
+# Author: Weizheng Xing
|
||
|
|
+# Create: 2021-08-24
|
||
|
|
+# Description: check if saving single image with multiple tags has been corrected
|
||
|
|
+
|
||
|
|
+top_dir=$(git rev-parse --show-toplevel)
|
||
|
|
+# shellcheck disable=SC1091
|
||
|
|
+source "$top_dir"/tests/lib/common.sh
|
||
|
|
+
|
||
|
|
+image_name=add-chown-basic
|
||
|
|
+context_dir="$top_dir"/tests/data/add-chown-basic
|
||
|
|
+
|
||
|
|
+function clean()
|
||
|
|
+{
|
||
|
|
+ systemctl stop isula-build
|
||
|
|
+ rm -rf "$temp_tar"
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+function pre_test()
|
||
|
|
+{
|
||
|
|
+ temp_tar=$(mktemp -u --suffix=.tar)
|
||
|
|
+ systemctl restart isula-build
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+function do_test()
|
||
|
|
+{
|
||
|
|
+ if ! run_with_debug "isula-build ctr-img build -t $image_name:latest $context_dir"; then
|
||
|
|
+ echo "FAIL"
|
||
|
|
+ fi
|
||
|
|
+
|
||
|
|
+ if ! run_with_debug "isula-build ctr-img tag $image_name:latest $image_name:latest-child"; then
|
||
|
|
+ echo "FAIL"
|
||
|
|
+ fi
|
||
|
|
+
|
||
|
|
+ if ! run_with_debug "isula-build ctr-img save -f docker $image_name:latest $image_name:latest-child -o $temp_tar"; then
|
||
|
|
+ echo "FAIL"
|
||
|
|
+ fi
|
||
|
|
+
|
||
|
|
+ if ! run_with_debug "isula-build ctr-img rm $image_name:latest $image_name:latest-child"; then
|
||
|
|
+ echo "FAIL"
|
||
|
|
+ fi
|
||
|
|
+
|
||
|
|
+ echo "PASS"
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+pre_test
|
||
|
|
+do_test
|
||
|
|
+clean
|
||
|
|
diff --git a/tests/src/integration_test_set_new_root.sh b/tests/src/integration_test_set_new_root.sh
|
||
|
|
new file mode 100644
|
||
|
|
index 0000000..7238240
|
||
|
|
--- /dev/null
|
||
|
|
+++ b/tests/src/integration_test_set_new_root.sh
|
||
|
|
@@ -0,0 +1,62 @@
|
||
|
|
+#!/bin/bash
|
||
|
|
+
|
||
|
|
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||
|
|
+# isula-build licensed under the Mulan PSL v2.
|
||
|
|
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||
|
|
+# You may obtain a copy of Mulan PSL v2 at:
|
||
|
|
+# http://license.coscl.org.cn/MulanPSL2
|
||
|
|
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||
|
|
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||
|
|
+# PURPOSE.
|
||
|
|
+# See the Mulan PSL v2 for more details.
|
||
|
|
+# Author: Weizheng Xing
|
||
|
|
+# Create: 2021-05-29
|
||
|
|
+# Description: test set new run and data root in configuration.toml
|
||
|
|
+
|
||
|
|
+top_dir=$(git rev-parse --show-toplevel)
|
||
|
|
+# shellcheck disable=SC1091
|
||
|
|
+source "$top_dir"/tests/lib/common.sh
|
||
|
|
+
|
||
|
|
+run_root="/var/run/new-isula-build"
|
||
|
|
+data_root="/var/lib/new-isula-build"
|
||
|
|
+config_file="/etc/isula-build/configuration.toml"
|
||
|
|
+base_image="hub.oepkgs.net/openeuler/openeuler:21.03"
|
||
|
|
+
|
||
|
|
+function clean()
|
||
|
|
+{
|
||
|
|
+ rm -f $config_file
|
||
|
|
+ mv "$config_file".bak $config_file
|
||
|
|
+ systemctl stop isula-build
|
||
|
|
+ rm -rf $run_root $data_root
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+# change to new data and run root
|
||
|
|
+function pre_test()
|
||
|
|
+{
|
||
|
|
+ cp $config_file "$config_file".bak
|
||
|
|
+ sed -i "/run_root/d;/data_root/d" $config_file
|
||
|
|
+ echo "run_root = \"${run_root}\"" >> $config_file
|
||
|
|
+ echo "data_root = \"${data_root}\"" >> $config_file
|
||
|
|
+
|
||
|
|
+ systemctl restart isula-build
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+# check if new resources are downloaded in new root
|
||
|
|
+function do_test()
|
||
|
|
+{
|
||
|
|
+ tree_node_befor=$(tree -L 3 $data_root | wc -l)
|
||
|
|
+ run_with_debug "isula-build ctr-img pull $base_image"
|
||
|
|
+ tree_node_after=$(tree -L 3 $data_root | wc -l)
|
||
|
|
+
|
||
|
|
+ if [ $((tree_node_after - tree_node_befor)) -eq 8 ] && run_with_debug "isula-build ctr-img rm $base_image"; then
|
||
|
|
+ echo "PASS"
|
||
|
|
+ else
|
||
|
|
+ echo "Sets of run and data root are not effective"
|
||
|
|
+ clean
|
||
|
|
+ exit 1
|
||
|
|
+ fi
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+pre_test
|
||
|
|
+do_test
|
||
|
|
+clean
|
||
|
|
diff --git a/tests/src/test_integration_set_new_root.sh b/tests/src/test_integration_set_new_root.sh
|
||
|
|
deleted file mode 100644
|
||
|
|
index 85b724a..0000000
|
||
|
|
--- a/tests/src/test_integration_set_new_root.sh
|
||
|
|
+++ /dev/null
|
||
|
|
@@ -1,60 +0,0 @@
|
||
|
|
-#!/bin/bash
|
||
|
|
-
|
||
|
|
-# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||
|
|
-# isula-build licensed under the Mulan PSL v2.
|
||
|
|
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||
|
|
-# You may obtain a copy of Mulan PSL v2 at:
|
||
|
|
-# http://license.coscl.org.cn/MulanPSL2
|
||
|
|
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||
|
|
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||
|
|
-# PURPOSE.
|
||
|
|
-# See the Mulan PSL v2 for more details.
|
||
|
|
-# Author: Weizheng Xing
|
||
|
|
-# Create: 2021-05-29
|
||
|
|
-# Description: test set new run and data root in configuration.toml
|
||
|
|
-
|
||
|
|
-run_root="/var/run/new-isula-build"
|
||
|
|
-data_root="/var/lib/new-isula-build"
|
||
|
|
-config_file="/etc/isula-build/configuration.toml"
|
||
|
|
-base_image="hub.oepkgs.net/openeuler/openeuler:21.03"
|
||
|
|
-
|
||
|
|
-function clean()
|
||
|
|
-{
|
||
|
|
- isula-build ctr-img rm $base_image >/dev/null 2>&1
|
||
|
|
- rm -f $config_file
|
||
|
|
- mv "$config_file".bak $config_file
|
||
|
|
- systemctl stop isula-build
|
||
|
|
- rm -rf $run_root $data_root
|
||
|
|
-}
|
||
|
|
-
|
||
|
|
-# change to new data and run root
|
||
|
|
-function pre_test()
|
||
|
|
-{
|
||
|
|
- cp $config_file "$config_file".bak
|
||
|
|
- sed -i "/run_root/d;/data_root/d" $config_file
|
||
|
|
- echo "run_root = \"${run_root}\"" >> $config_file
|
||
|
|
- echo "data_root = \"${data_root}\"" >> $config_file
|
||
|
|
-
|
||
|
|
- systemctl restart isula-build
|
||
|
|
-}
|
||
|
|
-
|
||
|
|
-# check if new resources are downloaded in new root
|
||
|
|
-function do_test()
|
||
|
|
-{
|
||
|
|
- tree_node_befor=$(tree -L 3 $data_root | wc -l)
|
||
|
|
- isula-build ctr-img pull $base_image >/dev/null 2>&1
|
||
|
|
- tree_node_after=$(tree -L 3 $data_root | wc -l)
|
||
|
|
-
|
||
|
|
- if [ $(($tree_node_after - $tree_node_befor)) -eq 8 ]; then
|
||
|
|
- echo "PASS"
|
||
|
|
- else
|
||
|
|
- echo "Sets of run and data root are not effective"
|
||
|
|
- clean
|
||
|
|
- exit 1
|
||
|
|
- fi
|
||
|
|
-}
|
||
|
|
-
|
||
|
|
-# clean
|
||
|
|
-pre_test
|
||
|
|
-do_test
|
||
|
|
-clean
|
||
|
|
diff --git a/tests/test.sh b/tests/test.sh
|
||
|
|
index e04cc96..01f0f31 100755
|
||
|
|
--- a/tests/test.sh
|
||
|
|
+++ b/tests/test.sh
|
||
|
|
@@ -33,18 +33,17 @@ function fuzz() {
|
||
|
|
exit $failed
|
||
|
|
}
|
||
|
|
|
||
|
|
-# base test
|
||
|
|
+# integration test
|
||
|
|
function integration() {
|
||
|
|
source "$top_dir"/tests/lib/common.sh
|
||
|
|
- pre_check
|
||
|
|
systemctl restart isula-build
|
||
|
|
|
||
|
|
while IFS= read -r testfile; do
|
||
|
|
- printf "%-45s" "test $(basename "$testfile"): "
|
||
|
|
+ printf "%-65s" "test $(basename "$testfile"): "
|
||
|
|
if ! bash "$testfile"; then
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
- done < <(find "$top_dir"/tests/src -maxdepth 1 -name "test_integration*" -type f -print)
|
||
|
|
+ done < <(find "$top_dir"/tests/src -maxdepth 1 -name "integration_test*" -type f -print)
|
||
|
|
}
|
||
|
|
|
||
|
|
# main function to chose which kind of test
|
||
|
|
@@ -67,4 +66,6 @@ function main() {
|
||
|
|
}
|
||
|
|
|
||
|
|
export "ISULABUILD_CLI_EXPERIMENTAL"="enabled"
|
||
|
|
+export DEBUG=0
|
||
|
|
+
|
||
|
|
main "$@"
|
||
|
|
--
|
||
|
|
1.8.3.1
|
||
|
|
|