diff --git a/e2e/context/context_test.go b/e2e/context/context_test.go new file mode 100644 index 0000000000..b427217116 --- /dev/null +++ b/e2e/context/context_test.go @@ -0,0 +1,21 @@ +package context + +import ( + "testing" + + "gotest.tools/golden" + "gotest.tools/icmd" +) + +func TestContextList(t *testing.T) { + cmd := icmd.Command("docker", "context", "ls") + cmd.Env = append(cmd.Env, + "DOCKER_CONFIG=./testdata/test-dockerconfig", + "KUBECONFIG=./testdata/test-kubeconfig", + ) + result := icmd.RunCmd(cmd).Assert(t, icmd.Expected{ + Err: icmd.None, + ExitCode: 0, + }) + golden.Assert(t, result.Stdout(), "context-ls.golden") +} diff --git a/e2e/context/main_test.go b/e2e/context/main_test.go new file mode 100644 index 0000000000..a3b1c53016 --- /dev/null +++ b/e2e/context/main_test.go @@ -0,0 +1,17 @@ +package context + +import ( + "fmt" + "os" + "testing" + + "github.com/docker/cli/internal/test/environment" +) + +func TestMain(m *testing.M) { + if err := environment.Setup(); err != nil { + fmt.Println(err.Error()) + os.Exit(3) + } + os.Exit(m.Run()) +} diff --git a/e2e/context/testdata/context-ls.golden b/e2e/context/testdata/context-ls.golden new file mode 100644 index 0000000000..2e2569ce10 --- /dev/null +++ b/e2e/context/testdata/context-ls.golden @@ -0,0 +1,3 @@ +NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR +default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock https://someserver (zoinx) swarm +remote my remote cluster ssh://someserver https://someserver (default) kubernetes diff --git a/e2e/context/testdata/test-dockerconfig/config.json b/e2e/context/testdata/test-dockerconfig/config.json new file mode 100644 index 0000000000..832b5c10b6 --- /dev/null +++ b/e2e/context/testdata/test-dockerconfig/config.json @@ -0,0 +1,7 @@ +{ + "auths": {}, + "HttpHeaders": { + "User-Agent": "Docker-Client/19.09.0-dev (linux)" + }, + "credsStore": "secretservice" +} \ No newline at end of file diff --git a/e2e/context/testdata/test-dockerconfig/contexts/meta/b71199ebd070b36beab7317920c2c2f1d777df8d05e5527d8458fda57cb17a7a/meta.json b/e2e/context/testdata/test-dockerconfig/contexts/meta/b71199ebd070b36beab7317920c2c2f1d777df8d05e5527d8458fda57cb17a7a/meta.json new file mode 100644 index 0000000000..11c9b4126e --- /dev/null +++ b/e2e/context/testdata/test-dockerconfig/contexts/meta/b71199ebd070b36beab7317920c2c2f1d777df8d05e5527d8458fda57cb17a7a/meta.json @@ -0,0 +1 @@ +{"Name":"remote","Metadata":{"Description":"my remote cluster","StackOrchestrator":"kubernetes"},"Endpoints":{"docker":{"Host":"ssh://someserver","SkipTLSVerify":false},"kubernetes":{"Host":"https://someserver","SkipTLSVerify":false,"DefaultNamespace":"default","Exec":{"command":"heptio-authenticator-aws","args":["token","-i","eks-cf"],"env":null,"apiVersion":"client.authentication.k8s.io/v1alpha1"}}}} diff --git a/e2e/context/testdata/test-kubeconfig b/e2e/context/testdata/test-kubeconfig new file mode 100644 index 0000000000..e96df74a50 --- /dev/null +++ b/e2e/context/testdata/test-kubeconfig @@ -0,0 +1,20 @@ +apiVersion: v1 +clusters: +- cluster: + certificate-authority-data: dGhlLWNh + server: https://someserver + name: test-cluster +contexts: +- context: + cluster: test-cluster + user: test-user + namespace: zoinx + name: test +current-context: test +kind: Config +preferences: {} +users: +- name: test-user + user: + client-certificate-data: dGhlLWNlcnQ= + client-key-data: dGhlLWtleQ==