提交 c6483b24 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!66 tests: refactor test-integration

Merge pull request !66 from Vanient/master
......@@ -72,7 +72,7 @@ tests: test-integration test-unit
.PHONY: test-integration
test-integration:
@echo "Integration test starting..."
@./hack/dockerfile_tests.sh
@./tests/test.sh
@echo "Integration test done!"
.PHONY: test-unit
......
......@@ -34,7 +34,7 @@ import (
"isula.org/isula-build/pkg/logger"
"isula.org/isula-build/pkg/parser"
"isula.org/isula-build/store"
testutil "isula.org/isula-build/tests/util"
testutil "isula.org/isula-build/util"
"isula.org/isula-build/util"
)
......
......@@ -36,7 +36,7 @@ import (
"isula.org/isula-build/pkg/logger"
"isula.org/isula-build/pkg/parser"
"isula.org/isula-build/store"
testUtil "isula.org/isula-build/tests/util"
testUtil "isula.org/isula-build/util"
"isula.org/isula-build/util"
)
......
......@@ -33,7 +33,7 @@ import (
"gotest.tools/fs"
constant "isula.org/isula-build"
testutil "isula.org/isula-build/tests/util"
testutil "isula.org/isula-build/util"
)
var (
......
FROM alpine
ARG http
CMD ls
\ No newline at end of file
......@@ -11,7 +11,7 @@
# See the Mulan PSL v2 for more details.
# Author: Danni Xia
# Create: 2020-03-01
# Description: shell script for dockerfile tests
# Description: common functions for tests
# check if legacy builder exists
function pre_check() {
......@@ -43,30 +43,46 @@ function start_isula_builder() {
fi
}
function cleanup() {
isula-build ctr-img rm -p > /dev/null 2>&1
kill -9 "${pidofbuilder}" > /dev/null 2>&1
rm -f /tmp/buildlog-*
}
# test build image without output
function test_build_without_output() {
tmpiidfile=$(mktemp -t iid.XXX)
if ! isula-build ctr-img build --iidfile "$tmpiidfile" > /tmp/buildlog-client 2>&1; then
if ! isula-build ctr-img build --tag "$1":latest "$2" > /tmp/buildlog-client 2>&1; then
echo "FAIL"
echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build without output)"
kill -9 "${pidofbuilder}"
exit 1
fi
if ! isula-build ctr-img rm "$1":latest > /tmp/buildlog-client 2>&1; then
echo "FAIL"
echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build without output)"
kill -9 "${pidofbuilder}"
exit 1
fi
image_clean
}
# test build image with docker-archive output
function test_build_with_docker_archive_output() {
tmpiidfile=$(mktemp -t iid.XXX)
if ! isula-build ctr-img build --iidfile "$tmpiidfile" --output=docker-archive:/tmp/"${image_name}".tar > /tmp/buildlog-client 2>&1; then
if ! isula-build ctr-img build --output=docker-archive:/tmp/"$1".tar:"$1":latest "$2" > /tmp/buildlog-client 2>&1; then
echo "FAIL"
echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker-archive output)"
kill -9 "${pidofbuilder}"
exit 1
else
rm -f /tmp/"${image_name}".tar
rm -f /tmp/"$1".tar
fi
if ! isula-build ctr-img rm "$1":latest > /tmp/buildlog-client 2>&1; then
echo "FAIL"
echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker-archive output)"
kill -9 "${pidofbuilder}"
exit 1
fi
image_clean
}
# test build image with docker-daemon output
......@@ -76,16 +92,21 @@ function test_build_with_docker_daemon_output() {
return 0
fi
tmpiidfile=$(mktemp -t iid.XXX)
if ! isula-build ctr-img build --iidfile "$tmpiidfile" --output=docker-daemon:isula/"${image_name}":latest > /tmp/buildlog-client 2>&1; then
if ! isula-build ctr-img build --output=docker-daemon:isula/"$1":latest "$2" > /tmp/buildlog-client 2>&1; then
echo "FAIL"
echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker-daemon output)"
kill -9 "${pidofbuilder}"
exit 1
else
docker rmi isula/"${image_name}" > /dev/null 2>&1
docker rmi isula/"$1" > /dev/null 2>&1
fi
if ! isula-build ctr-img rm isula/"$1":latest > /tmp/buildlog-client 2>&1; then
echo "FAIL"
echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker-daemon output)"
kill -9 "${pidofbuilder}"
exit 1
fi
image_clean
}
# test build image with isulad output
......@@ -95,56 +116,19 @@ function test_build_with_isulad_output() {
return 0
fi
tmpiidfile=$(mktemp -t iid.XXX)
if ! isula-build ctr-img build --iidfile "$tmpiidfile" --output=isulad:isula/"${image_name}":latest > /tmp/buildlog-client 2>&1; then
if ! isula-build ctr-img build --output=isulad:isula/"$1":latest "$2" > /tmp/buildlog-client 2>&1; then
echo "FAIL"
echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with isulad output)"
kill -9 "${pidofbuilder}"
exit 1
else
isula rmi isula/"${image_name}" > /dev/null 2>&1
isula rmi isula/"$1" > /dev/null 2>&1
fi
image_clean
}
function image_clean() {
imageID=$(cat "$tmpiidfile")
isula-build ctr-img rm "$imageID" > /dev/null
rm -f "$tmpiidfile"
}
# start build images tests
function tests() {
while IFS= read -r dockerfiledir; do
if ! find "${dockerfiledir}" -maxdepth 1 -iname "Dockerfile" | grep . > /dev/null 2>&1; then
continue
fi
pushd "${dockerfiledir}" > /dev/null 2>&1 || exit 1
image_name=$(basename "${dockerfiledir}")
echo -e "test Dockerfile in ${dockerfiledir}:\c"
test_build_without_output
test_build_with_docker_archive_output
test_build_with_docker_daemon_output
test_build_with_isulad_output
echo "PASS"
popd > /dev/null 2>&1 || exit 1
done < <(find ./tests -maxdepth 1 -type d -print)
}
function cleanup() {
isula-build ctr-img rm -p > /dev/null 2>&1
kill -9 "${pidofbuilder}" > /dev/null 2>&1
rm -f /tmp/buildlog-*
}
function main() {
pre_check
start_isula_builder
tests
cleanup
if ! isula-build ctr-img rm isula/"$1":latest > /tmp/buildlog-client 2>&1; then
echo "FAIL"
echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with isulad output)"
kill -9 "${pidofbuilder}"
exit 1
fi
}
main
echo "SUCCESS: all tests success"
#!/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: Danni Xia
# Create: 2020-08-27
# Description: dockerfile test add-chown-basic
top_dir=$(git rev-parse --show-toplevel)
source "$top_dir"/tests/lib/common.sh
image_name=add-chown-basic
context_dir="$top_dir"/tests/data/add-chown-basic
test_build_without_output "$image_name" "$context_dir"
test_build_with_docker_archive_output "$image_name" "$context_dir"
test_build_with_docker_daemon_output "$image_name" "$context_dir"
test_build_with_isulad_output "$image_name" "$context_dir"
echo "PASS"
#!/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: Danni Xia
# Create: 2020-08-27
# Description: dockerfile test test-build-from-scratch
top_dir=$(git rev-parse --show-toplevel)
source "$top_dir"/tests/lib/common.sh
image_name=build-from-scratch
context_dir="$top_dir"/tests/data/build-from-scratch
test_build_without_output "$image_name" "$context_dir"
test_build_with_docker_archive_output "$image_name" "$context_dir"
test_build_with_docker_daemon_output "$image_name" "$context_dir"
test_build_with_isulad_output "$image_name" "$context_dir"
echo "PASS"
#!/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: Danni Xia
# Create: 2020-08-27
# Description: dockerfile test multi-files-env
top_dir=$(git rev-parse --show-toplevel)
source "$top_dir"/tests/lib/common.sh
image_name=multi-files-env
context_dir="$top_dir"/tests/data/multi-files-env
test_build_without_output "$image_name" "$context_dir"
test_build_with_docker_archive_output "$image_name" "$context_dir"
test_build_with_docker_daemon_output "$image_name" "$context_dir"
test_build_with_isulad_output "$image_name" "$context_dir"
echo "PASS"
#!/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: Danni Xia
# Create: 2020-08-27
# Description: dockerfile test multi-stage-builds
top_dir=$(git rev-parse --show-toplevel)
source "$top_dir"/tests/lib/common.sh
image_name=multi-stage-builds
context_dir="$top_dir"/tests/data/multi-stage-builds
test_build_without_output "$image_name" "$context_dir"
test_build_with_docker_archive_output "$image_name" "$context_dir"
test_build_with_docker_daemon_output "$image_name" "$context_dir"
test_build_with_isulad_output "$image_name" "$context_dir"
echo "PASS"
#!/bin/bash
top_dir=$(git rev-parse --show-toplevel)
source "$top_dir"/tests/lib/common.sh
pre_check
start_isula_builder
while IFS= read -r testfile; do
echo -e "test $testfile:\c"
if ! bash "$testfile"; then
exit 1
fi
done < <(find "$top_dir"/tests/src -maxdepth 1 -type f -print)
cleanup
......@@ -57,6 +57,7 @@ func GetTestingArgs(t *testing.T) map[string]string {
return args
}
// Immutable is used to set immutable
func Immutable(path string, set bool) error {
var op string
if set {
......@@ -64,7 +65,7 @@ func Immutable(path string, set bool) error {
} else {
op = "-i" // set mutable
}
cmd := exec.Command("chattr", op, path)
cmd := exec.Command("chattr", op, path) // nolint:gosec
err := cmd.Run()
if err != nil {
return errors.Wrapf(err, "chattr %s for %s failed", op, path)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册