Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smoke: fix lost compatibility test case #1036

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
Expand Down
2 changes: 1 addition & 1 deletion smoke/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
26 changes: 5 additions & 21 deletions smoke/tests/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
package tests

import (
"fmt"
"os"
"strings"
"testing"

"github.com/dragonflyoss/image-service/smoke/tests/tool"
Expand All @@ -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{}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/native_layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
10 changes: 5 additions & 5 deletions smoke/tests/tool/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
35 changes: 20 additions & 15 deletions smoke/tests/tool/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions smoke/tests/zran_layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down