From 8ea7c9e0d29873151b8fec6257327123182b13eb Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Wed, 15 Nov 2023 17:19:27 +0100 Subject: [PATCH] Make it context aware and add test skipping options Signed-off-by: Ulysses Souza --- Makefile | 10 +++++++--- go.mod | 5 +++-- go.sum | 12 ++++++++---- pkg/e2e/framework.go | 24 ++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 0a68e65bc6..3a5c9cf6f4 100644 --- a/Makefile +++ b/Makefile @@ -32,9 +32,13 @@ endif BUILD_FLAGS?= TEST_FLAGS?= E2E_TEST?= -ifeq ($(E2E_TEST),) -else - TEST_FLAGS=-run $(E2E_TEST) +ifneq ($(E2E_TEST),) + TEST_FLAGS:=$(TEST_FLAGS) -run '$(E2E_TEST)' +endif + +EXCLUDE_E2E_TESTS?= +ifneq ($(EXCLUDE_E2E_TESTS),) + TEST_FLAGS:=$(TEST_FLAGS) -skip '$(EXCLUDE_E2E_TESTS)' endif BUILDX_CMD ?= docker buildx diff --git a/go.mod b/go.mod index f06ef26a64..5bd3fa9553 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/morikuni/aec v1.0.0 github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/image-spec v1.1.0-rc5 + github.com/otiai10/copy v1.14.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 @@ -44,8 +45,8 @@ require ( go.opentelemetry.io/otel/trace v1.14.0 go.uber.org/goleak v1.3.0 golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 - golang.org/x/sync v0.4.0 - golang.org/x/sys v0.11.0 + golang.org/x/sync v0.5.0 + golang.org/x/sys v0.14.0 google.golang.org/grpc v1.59.0 gotest.tools/v3 v3.5.1 ) diff --git a/go.sum b/go.sum index 0c7c004a4c..868282c876 100644 --- a/go.sum +++ b/go.sum @@ -502,6 +502,10 @@ github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaL github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= +github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks= +github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg= @@ -766,8 +770,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= -golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -821,8 +825,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/pkg/e2e/framework.go b/pkg/e2e/framework.go index 58f7debafd..ba1358b725 100644 --- a/pkg/e2e/framework.go +++ b/pkg/e2e/framework.go @@ -30,6 +30,7 @@ import ( "testing" "time" + cp "github.com/otiai10/copy" "github.com/stretchr/testify/require" "gotest.tools/v3/assert" "gotest.tools/v3/icmd" @@ -95,6 +96,7 @@ func NewCLI(t testing.TB, opts ...CLIOption) *CLI { configDir := t.TempDir() initializePlugins(t, configDir) + initializeContextDir(t, configDir) c := &CLI{ ConfigDir: configDir, @@ -152,6 +154,22 @@ func initializePlugins(t testing.TB, configDir string) { } } +func initializeContextDir(t testing.TB, configDir string) { + dockerUserDir := ".docker/contexts" + userDir, err := os.UserHomeDir() + require.NoError(t, err, "Failed to get user home directory") + userContextsDir := filepath.Join(userDir, dockerUserDir) + if checkExists(userContextsDir) { + dstContexts := filepath.Join(configDir, "contexts") + require.NoError(t, cp.Copy(userContextsDir, dstContexts), "Failed to copy contexts directory") + } +} + +func checkExists(path string) bool { + _, err := os.Stat(path) + return err == nil +} + func dirContents(dir string) []string { var res []string _ = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { @@ -221,7 +239,13 @@ func (c *CLI) BaseEnvironment() []string { "USER=" + os.Getenv("USER"), "DOCKER_CONFIG=" + c.ConfigDir, "KUBECONFIG=invalid", + "PATH=" + os.Getenv("PATH"), } + dockerContextEnv, ok := os.LookupEnv("DOCKER_CONTEXT") + if ok { + env = append(env, "DOCKER_CONTEXT="+dockerContextEnv) + } + if coverdir, ok := os.LookupEnv("GOCOVERDIR"); ok { _, filename, _, _ := runtime.Caller(0) root := filepath.Join(filepath.Dir(filename), "..", "..")