Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit e630ace

Browse files
authored
Merge pull request #154 from docker/fix_context_inspect_shellout
Fix shell out to docker-classic when invoking
2 parents 4c4ebbd + d2648da commit e630ace

8 files changed

Lines changed: 26 additions & 70 deletions

File tree

cli/cmd/context/ls_test.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

context/store/store_test.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,6 @@ func (suite *StoreTestSuite) TestGet() {
107107
require.Equal(suite.T(), "type", meta.Type)
108108
}
109109

110-
func (suite *StoreTestSuite) TestList() {
111-
err := suite.store.Create("test1", "type", "description", ContextMetadata{})
112-
require.Nil(suite.T(), err)
113-
114-
err = suite.store.Create("test2", "type", "description", ContextMetadata{})
115-
require.Nil(suite.T(), err)
116-
117-
contexts, err := suite.store.List()
118-
require.Nil(suite.T(), err)
119-
120-
require.Equal(suite.T(), len(contexts), 3)
121-
require.Equal(suite.T(), "test1", contexts[0].Name)
122-
require.Equal(suite.T(), "test2", contexts[1].Name)
123-
require.Equal(suite.T(), "default", contexts[2].Name)
124-
}
125-
126110
func (suite *StoreTestSuite) TestRemoveNotFound() {
127111
err := suite.store.Remove("notfound")
128112
require.EqualError(suite.T(), err, `context "notfound": not found`)
@@ -132,17 +116,18 @@ func (suite *StoreTestSuite) TestRemoveNotFound() {
132116
func (suite *StoreTestSuite) TestRemove() {
133117
err := suite.store.Create("testremove", "type", "description", ContextMetadata{})
134118
require.Nil(suite.T(), err)
135-
contexts, err := suite.store.List()
119+
120+
meta, err := suite.store.Get("testremove")
136121
require.Nil(suite.T(), err)
137-
require.Equal(suite.T(), len(contexts), 2)
122+
require.NotNil(suite.T(), meta)
138123

139124
err = suite.store.Remove("testremove")
140125
require.Nil(suite.T(), err)
141-
contexts, err = suite.store.List()
142-
require.Nil(suite.T(), err)
143-
// The default context is always here, that's why we
144-
// have len(contexts) == 1
145-
require.Equal(suite.T(), len(contexts), 1)
126+
127+
meta, err = suite.store.Get("testremove")
128+
require.EqualError(suite.T(), err, `context "testremove": not found`)
129+
require.Nil(suite.T(), meta)
130+
146131
}
147132

148133
func TestExampleTestSuite(t *testing.T) {

context/store/storedefault.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type endpoint struct {
3232
}
3333

3434
func dockerDefaultContext() (*Metadata, error) {
35-
cmd := exec.Command("docker", "context", "inspect", "default")
35+
cmd := exec.Command("docker-classic", "context", "inspect", "default")
3636
var stdout bytes.Buffer
3737
cmd.Stdout = &stdout
3838
err := cmd.Run()

context/store/storedefault_test.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/e2e/e2e_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import (
3535
"testing"
3636
"time"
3737

38+
"gotest.tools/golden"
39+
3840
. "github.com/onsi/gomega"
3941
"github.com/stretchr/testify/suite"
4042

@@ -57,12 +59,10 @@ func (s *E2eSuite) TestContextHelp() {
5759

5860
func (s *E2eSuite) TestContextDefault() {
5961
It("should be initialized with default context", func() {
60-
s.NewDockerCommand("context", "use", "default").ExecOrDie()
6162
output := s.NewDockerCommand("context", "show").ExecOrDie()
6263
Expect(output).To(ContainSubstring("default"))
6364
output = s.NewCommand("docker", "context", "ls").ExecOrDie()
64-
Expect(output).To(Not(ContainSubstring("test-example")))
65-
Expect(output).To(ContainSubstring("default *"))
65+
golden.Assert(s.T(), output, "ls-out-default.golden")
6666
})
6767
}
6868

@@ -107,7 +107,7 @@ func (s *E2eSuite) TestMockBackend() {
107107
currentContext := s.NewDockerCommand("context", "use", "test-example").ExecOrDie()
108108
Expect(currentContext).To(ContainSubstring("test-example"))
109109
output := s.NewDockerCommand("context", "ls").ExecOrDie()
110-
Expect(output).To(ContainSubstring("test-example *"))
110+
golden.Assert(s.T(), output, "ls-out-test-example.golden")
111111
output = s.NewDockerCommand("context", "show").ExecOrDie()
112112
Expect(output).To(ContainSubstring("test-example"))
113113
})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NAME TYPE DESCRIPTION DOCKER ENPOINT KUBERNETES ENDPOINT ORCHESTRATOR
2+
default * docker Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
NAME TYPE DESCRIPTION DOCKER ENPOINT KUBERNETES ENDPOINT ORCHESTRATOR
22
default docker Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
3-
example * example
3+
test-example * example

tests/framework/suite.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,17 @@ func dirContents(dir string) []string {
8080
}
8181

8282
func (s *Suite) linkClassicDocker() {
83-
p, err := exec.LookPath("docker")
83+
p, err := exec.LookPath("docker-classic")
84+
if err != nil {
85+
p, err = exec.LookPath("docker")
86+
}
8487
gomega.Expect(err).To(gomega.BeNil())
8588
err = os.Symlink(p, filepath.Join(s.BinDir, "docker-classic"))
8689
gomega.Expect(err).To(gomega.BeNil())
90+
dockerPath, err := filepath.Abs("../../bin/docker")
91+
gomega.Expect(err).To(gomega.BeNil())
92+
err = os.Symlink(dockerPath, filepath.Join(s.BinDir, "docker"))
93+
gomega.Expect(err).To(gomega.BeNil())
8794
err = os.Setenv("PATH", fmt.Sprintf("%s:%s", s.BinDir, os.Getenv("PATH")))
8895
gomega.Expect(err).To(gomega.BeNil())
8996
}
@@ -111,9 +118,9 @@ func (s *Suite) NewCommand(command string, args ...string) *CmdContext {
111118

112119
func dockerExecutable() string {
113120
if runtime.GOOS == "windows" {
114-
return "../../bin/docker.exe"
121+
return "docker.exe"
115122
}
116-
return "../../bin/docker"
123+
return "docker"
117124
}
118125

119126
// NewDockerCommand creates a docker builder.

0 commit comments

Comments
 (0)