From c9eeb95cb8b7a8f70f6b0573756cf2a00eb0140e Mon Sep 17 00:00:00 2001 From: Yan Song Date: Mon, 30 Jan 2023 09:08:36 +0000 Subject: [PATCH] smoke: fix lost compatibility test case We skipped compatibility test cases because of incorrect env configuration, this patch fixes it. See previous action: https://github.com/dragonflyoss/image-service/actions/runs/4042014250/jobs/6949286202#step:7:70 Signed-off-by: Yan Song --- .github/workflows/smoke.yml | 10 ++++----- smoke/Makefile | 2 +- smoke/tests/compatibility_test.go | 26 +++++------------------ smoke/tests/image_test.go | 2 +- smoke/tests/native_layer_test.go | 2 +- smoke/tests/tool/context.go | 10 ++++----- smoke/tests/tool/util.go | 35 ++++++++++++++++++------------- smoke/tests/zran_layer_test.go | 6 +++--- 8 files changed, 41 insertions(+), 52 deletions(-) diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml index 30158b28354..1f6e695afeb 100644 --- a/.github/workflows/smoke.yml +++ b/.github/workflows/smoke.yml @@ -102,12 +102,12 @@ jobs: done - name: Integration Test run: | - sudo install -D -m 755 contrib/nydusify/cmd/nydusify /usr/bin - sudo install -D -m 755 target/release/nydusd target/release/nydus-image /usr/bin - sudo mkdir -p /home/runner/work/workdir + sudo mkdir -p /usr/bin/nydus-latest /home/runner/work/workdir + sudo install -D -m 755 contrib/nydusify/cmd/nydusify /usr/bin/nydus-latest + sudo install -D -m 755 target/release/nydusd target/release/nydus-image /usr/bin/nydus-latest - versions=(v0.1.0 v2.1.2) - version_exports=(v0_1_0 v2_1_2) + versions=(v0.1.0 v2.1.2 latest) + version_exports=(v0_1_0 v2_1_2 latest) for i in ${!version_exports[@]}; do version=${versions[$i]} version_export=${version_exports[$i]} diff --git a/smoke/Makefile b/smoke/Makefile index d87966ee5bc..f54dbe2865e 100644 --- a/smoke/Makefile +++ b/smoke/Makefile @@ -19,7 +19,7 @@ lint: # NYDUS_NYDUSIFY=/path/to/latest/nydusify \ # make test test: build lint - sudo -E ./smoke.test -test.v -test.timeout 5m -test.parallel=8 -test.run=$(TESTS) + sudo -E ./smoke.test -test.v -test.timeout 10m -test.parallel=8 -test.run=$(TESTS) # WORK_DIR=/tmp \ # NYDUS_BUILDER=/path/to/latest/nydus-image \ diff --git a/smoke/tests/compatibility_test.go b/smoke/tests/compatibility_test.go index bca38777ba8..125d028bae8 100644 --- a/smoke/tests/compatibility_test.go +++ b/smoke/tests/compatibility_test.go @@ -5,9 +5,6 @@ package tests import ( - "fmt" - "os" - "strings" "testing" "github.com/dragonflyoss/image-service/smoke/tests/tool" @@ -20,19 +17,6 @@ const ( paramNydusifyVersion = "nydusify_version" ) -func getFromEnv(t *testing.T, env, version string) string { - version = strings.ReplaceAll(version, ".", "_") - key := fmt.Sprintf("%s_%s", env, version) - if version == "latest" { - key = env - } - binary := os.Getenv(key) - if binary == "" { - t.Skipf("skip compatibility test because no env `%s` specified", key) - } - return binary -} - func TestCompatibility(t *testing.T) { params := tool.DescartesIterator{} @@ -72,12 +56,12 @@ func TestCompatibility(t *testing.T) { nydusifyNotSupportCompressor := param.GetString(paramNydusifyVersion) == "v0.1.0" nydusifyOnlySupportV5 := param.GetString(paramNydusifyVersion) == "v0.1.0" - builderPath := getFromEnv(t, "NYDUS_BUILDER", param.GetString(paramNydusImageVersion)) - nydusdPath := getFromEnv(t, "NYDUS_NYDUSD", param.GetString(paramNydusdVersion)) - nydusifyPath := getFromEnv(t, "NYDUS_NYDUSIFY", param.GetString(paramNydusifyVersion)) - nydusifyCheckerPath := getFromEnv(t, "NYDUS_NYDUSIFY", "latest") + builderPath := tool.GetBinary(t, "NYDUS_BUILDER", param.GetString(paramNydusImageVersion)) + nydusdPath := tool.GetBinary(t, "NYDUS_NYDUSD", param.GetString(paramNydusdVersion)) + nydusifyPath := tool.GetBinary(t, "NYDUS_NYDUSIFY", param.GetString(paramNydusifyVersion)) + nydusifyCheckerPath := tool.GetBinary(t, "NYDUS_NYDUSIFY", "latest") - ctx := tool.DefaultContext() + ctx := tool.DefaultContext(t) ctx.Binary = tool.BinaryContext{ Builder: builderPath, Nydusd: nydusdPath, diff --git a/smoke/tests/image_test.go b/smoke/tests/image_test.go index 44e976c8422..ea008db65d6 100644 --- a/smoke/tests/image_test.go +++ b/smoke/tests/image_test.go @@ -81,7 +81,7 @@ func TestImage(t *testing.T) { preparedImages[image] = tool.PrepareImage(t, image) } - ctx := tool.DefaultContext() + ctx := tool.DefaultContext(t) ctx.Build.FSVersion = param.GetString(paramFSVersion) ctx.Build.OCIRef = param.GetBool(paramZran) diff --git a/smoke/tests/native_layer_test.go b/smoke/tests/native_layer_test.go index 2d2134cee75..60df98ed620 100644 --- a/smoke/tests/native_layer_test.go +++ b/smoke/tests/native_layer_test.go @@ -150,5 +150,5 @@ func testNativeLayer(t *testing.T, ctx tool.Context) { } func TestNativeLayer(t *testing.T) { - testNativeLayer(t, *tool.DefaultContext()) + testNativeLayer(t, *tool.DefaultContext(t)) } diff --git a/smoke/tests/tool/context.go b/smoke/tests/tool/context.go index e45624e0a7d..4eb8c7b884a 100644 --- a/smoke/tests/tool/context.go +++ b/smoke/tests/tool/context.go @@ -54,13 +54,13 @@ type Context struct { Env EnvContext } -func DefaultContext() *Context { +func DefaultContext(t *testing.T) *Context { return &Context{ Binary: BinaryContext{ - Builder: "nydus-image", - Nydusd: "nydusd", - Nydusify: "nydusify", - NydusifyChecker: "nydusify", + Builder: GetBinary(t, "NYDUS_BUILDER", "latest"), + Nydusd: GetBinary(t, "NYDUS_NYDUSD", "latest"), + Nydusify: GetBinary(t, "NYDUS_NYDUSIFY", "latest"), + NydusifyChecker: GetBinary(t, "NYDUS_NYDUSIFY", "latest"), NydusifyOnlySupportV5: false, }, Build: BuildContext{ diff --git a/smoke/tests/tool/util.go b/smoke/tests/tool/util.go index 762e3f8f49e..85462a250f1 100644 --- a/smoke/tests/tool/util.go +++ b/smoke/tests/tool/util.go @@ -5,13 +5,21 @@ package tool import ( + "fmt" "os" "os/exec" + "strings" "testing" "github.com/stretchr/testify/assert" ) +var defaultBinary = map[string]string{ + "NYDUS_BUILDER": "nydus-image", + "NYDUS_NYDUSD": "nydusd", + "NYDUS_NYDUSIFY": "nydusify", +} + func Run(t *testing.T, cmd string) { _cmd := exec.Command("sh", "-c", cmd) _cmd.Stdout = os.Stdout @@ -32,21 +40,18 @@ func RunWithOutput(cmd string) string { return string(output) } -func GetBinaries(t *testing.T) (string, string, string) { - builderPath := os.Getenv("NYDUS_BUILDER") - if builderPath == "" { - builderPath = "nydus-image" - } - - nydusdPath := os.Getenv("NYDUS_NYDUSD") - if nydusdPath == "" { - nydusdPath = "nydusd" +func GetBinary(t *testing.T, env, version string) string { + version = strings.ReplaceAll(version, ".", "_") + key := fmt.Sprintf("%s_%s", env, version) + if version == "latest" && os.Getenv(key) == "" { + key = env } - - nydusifyPath := os.Getenv("NYDUS_NYDUSIFY") - if nydusifyPath == "" { - nydusifyPath = "nydusify" + binary := os.Getenv(key) + if binary == "" { + if version == "latest" && defaultBinary[env] != "" { + return defaultBinary[env] + } + t.Fatalf("not found binary from env `%s`, version %s", env, version) } - - return builderPath, nydusdPath, nydusifyPath + return binary } diff --git a/smoke/tests/zran_layer_test.go b/smoke/tests/zran_layer_test.go index e06a9a10b75..7ca1c9c5256 100644 --- a/smoke/tests/zran_layer_test.go +++ b/smoke/tests/zran_layer_test.go @@ -21,6 +21,8 @@ const ( func makeZranLayerTest(ctx tool.Context) func(t *testing.T) { return func(t *testing.T) { + t.Parallel() + // Prepare work directory ctx.PrepareWorkDir(t) defer ctx.Destroy(t) @@ -47,15 +49,13 @@ func makeZranLayerTest(ctx tool.Context) func(t *testing.T) { } func TestZranLayer(t *testing.T) { - t.Parallel() - params := tool.DescartesIterator{} params. Register(paramGzip, []interface{}{false, true}). Register(paramCacheCompressed, []interface{}{true, false}). Register(paramEnablePrefetch, []interface{}{false, true}) - ctx := tool.DefaultContext() + ctx := tool.DefaultContext(t) for params.HasNext() { param := params.Next()