Skip to content

Commit 8ea7c9e

Browse files
committed
Make it context aware and add test skipping options
Signed-off-by: Ulysses Souza <[email protected]>
1 parent c169436 commit 8ea7c9e

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ endif
3232
BUILD_FLAGS?=
3333
TEST_FLAGS?=
3434
E2E_TEST?=
35-
ifeq ($(E2E_TEST),)
36-
else
37-
TEST_FLAGS=-run $(E2E_TEST)
35+
ifneq ($(E2E_TEST),)
36+
TEST_FLAGS:=$(TEST_FLAGS) -run '$(E2E_TEST)'
37+
endif
38+
39+
EXCLUDE_E2E_TESTS?=
40+
ifneq ($(EXCLUDE_E2E_TESTS),)
41+
TEST_FLAGS:=$(TEST_FLAGS) -skip '$(EXCLUDE_E2E_TESTS)'
3842
endif
3943

4044
BUILDX_CMD ?= docker buildx

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/morikuni/aec v1.0.0
3232
github.com/opencontainers/go-digest v1.0.0
3333
github.com/opencontainers/image-spec v1.1.0-rc5
34+
github.com/otiai10/copy v1.14.0
3435
github.com/sirupsen/logrus v1.9.3
3536
github.com/spf13/cobra v1.7.0
3637
github.com/spf13/pflag v1.0.5
@@ -44,8 +45,8 @@ require (
4445
go.opentelemetry.io/otel/trace v1.14.0
4546
go.uber.org/goleak v1.3.0
4647
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
47-
golang.org/x/sync v0.4.0
48-
golang.org/x/sys v0.11.0
48+
golang.org/x/sync v0.5.0
49+
golang.org/x/sys v0.14.0
4950
google.golang.org/grpc v1.59.0
5051
gotest.tools/v3 v3.5.1
5152
)

go.sum

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,10 @@ github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaL
502502
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
503503
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
504504
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
505+
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
506+
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
507+
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
508+
github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
505509
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
506510
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
507511
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
766770
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
767771
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
768772
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
769-
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
770-
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
773+
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
774+
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
771775
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
772776
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
773777
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
821825
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
822826
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
823827
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
824-
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
825-
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
828+
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
829+
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
826830
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
827831
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
828832
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

pkg/e2e/framework.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"testing"
3131
"time"
3232

33+
cp "github.com/otiai10/copy"
3334
"github.com/stretchr/testify/require"
3435
"gotest.tools/v3/assert"
3536
"gotest.tools/v3/icmd"
@@ -95,6 +96,7 @@ func NewCLI(t testing.TB, opts ...CLIOption) *CLI {
9596

9697
configDir := t.TempDir()
9798
initializePlugins(t, configDir)
99+
initializeContextDir(t, configDir)
98100

99101
c := &CLI{
100102
ConfigDir: configDir,
@@ -152,6 +154,22 @@ func initializePlugins(t testing.TB, configDir string) {
152154
}
153155
}
154156

157+
func initializeContextDir(t testing.TB, configDir string) {
158+
dockerUserDir := ".docker/contexts"
159+
userDir, err := os.UserHomeDir()
160+
require.NoError(t, err, "Failed to get user home directory")
161+
userContextsDir := filepath.Join(userDir, dockerUserDir)
162+
if checkExists(userContextsDir) {
163+
dstContexts := filepath.Join(configDir, "contexts")
164+
require.NoError(t, cp.Copy(userContextsDir, dstContexts), "Failed to copy contexts directory")
165+
}
166+
}
167+
168+
func checkExists(path string) bool {
169+
_, err := os.Stat(path)
170+
return err == nil
171+
}
172+
155173
func dirContents(dir string) []string {
156174
var res []string
157175
_ = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
@@ -221,7 +239,13 @@ func (c *CLI) BaseEnvironment() []string {
221239
"USER=" + os.Getenv("USER"),
222240
"DOCKER_CONFIG=" + c.ConfigDir,
223241
"KUBECONFIG=invalid",
242+
"PATH=" + os.Getenv("PATH"),
224243
}
244+
dockerContextEnv, ok := os.LookupEnv("DOCKER_CONTEXT")
245+
if ok {
246+
env = append(env, "DOCKER_CONTEXT="+dockerContextEnv)
247+
}
248+
225249
if coverdir, ok := os.LookupEnv("GOCOVERDIR"); ok {
226250
_, filename, _, _ := runtime.Caller(0)
227251
root := filepath.Join(filepath.Dir(filename), "..", "..")

0 commit comments

Comments
 (0)