72 lines
2.5 KiB
Diff
72 lines
2.5 KiB
Diff
From dd1e6907ec841d378699fdbbbf0033666b1b43c7 Mon Sep 17 00:00:00 2001
|
|
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
|
Date: Mon, 8 May 2023 17:38:38 +0800
|
|
Subject: [PATCH 61/79] add testcase for hook env
|
|
|
|
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
|
---
|
|
.../container_cases/hook_spec_test.sh | 30 +++++++++++++++++++
|
|
.../test_data/env-hookspec.json | 9 ++++++
|
|
2 files changed, 39 insertions(+)
|
|
create mode 100644 CI/test_cases/container_cases/test_data/env-hookspec.json
|
|
|
|
diff --git a/CI/test_cases/container_cases/hook_spec_test.sh b/CI/test_cases/container_cases/hook_spec_test.sh
|
|
index a0f70e37..c88ed340 100755
|
|
--- a/CI/test_cases/container_cases/hook_spec_test.sh
|
|
+++ b/CI/test_cases/container_cases/hook_spec_test.sh
|
|
@@ -59,6 +59,36 @@ function test_hook_spec()
|
|
|
|
rm -rf $runlog
|
|
|
|
+ cat > /tmp/env.sh <<EOF
|
|
+#!/bin/bash
|
|
+
|
|
+env > /tmp/envfile
|
|
+EOF
|
|
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to generate env shell" && ((ret++))
|
|
+
|
|
+ chmod +x /tmp/env.sh
|
|
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to chmod env shell" && ((ret++))
|
|
+
|
|
+ CONT=`isula run -itd --hook-spec ${test_data_path}/env-hookspec.json ${image}`
|
|
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
|
|
+
|
|
+ isula stop -t 0 ${CONT}
|
|
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stop ${CONT}" && ((ret++))
|
|
+
|
|
+ isula rm ${CONT}
|
|
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm ${CONT}" && ((ret++))
|
|
+
|
|
+ # debug
|
|
+ cat /tmp/envfile
|
|
+ cat /tmp/envfile | grep "PATH=/usr/local/bin:/usr/bin"
|
|
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - set ocihook PATH env failed" && ((ret++))
|
|
+
|
|
+ cat /tmp/envfile | grep "AAA=bbb"
|
|
+ [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - set ocihook env failed" && ((ret++))
|
|
+
|
|
+ rm -rf /tmp/env.sh
|
|
+ rm -rf /tmp/envfile
|
|
+
|
|
msg_info "${test} finished with return ${ret}..."
|
|
return ${ret}
|
|
}
|
|
diff --git a/CI/test_cases/container_cases/test_data/env-hookspec.json b/CI/test_cases/container_cases/test_data/env-hookspec.json
|
|
new file mode 100644
|
|
index 00000000..2a63a355
|
|
--- /dev/null
|
|
+++ b/CI/test_cases/container_cases/test_data/env-hookspec.json
|
|
@@ -0,0 +1,9 @@
|
|
+{
|
|
+ "prestart": [
|
|
+ {
|
|
+ "args": ["/tmp/env.sh"],
|
|
+ "path": "/tmp/env.sh",
|
|
+ "env": ["PATH=/usr/local/bin:/usr/bin", "AAA=bbb"]
|
|
+ }
|
|
+ ]
|
|
+}
|
|
--
|
|
2.25.1
|
|
|