mirror of
https://github.com/docker/compose.git
synced 2025-07-13 08:44:33 +02:00
Fix shell out to docker-classic when invoking
This commit is contained in:
parent
d876f9e779
commit
d2648da2d9
@ -1,25 +0,0 @@
|
|||||||
package context
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/stretchr/testify/suite"
|
|
||||||
"gotest.tools/v3/golden"
|
|
||||||
|
|
||||||
"github.com/docker/api/tests/framework"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ContextSuite struct {
|
|
||||||
framework.CliSuite
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sut *ContextSuite) TestLs() {
|
|
||||||
err := runList(sut.Context())
|
|
||||||
require.Nil(sut.T(), err)
|
|
||||||
golden.Assert(sut.T(), sut.GetStdOut(), "ls-out.golden")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPs(t *testing.T) {
|
|
||||||
suite.Run(t, new(ContextSuite))
|
|
||||||
}
|
|
@ -107,22 +107,6 @@ func (suite *StoreTestSuite) TestGet() {
|
|||||||
require.Equal(suite.T(), "type", meta.Type)
|
require.Equal(suite.T(), "type", meta.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *StoreTestSuite) TestList() {
|
|
||||||
err := suite.store.Create("test1", "type", "description", ContextMetadata{})
|
|
||||||
require.Nil(suite.T(), err)
|
|
||||||
|
|
||||||
err = suite.store.Create("test2", "type", "description", ContextMetadata{})
|
|
||||||
require.Nil(suite.T(), err)
|
|
||||||
|
|
||||||
contexts, err := suite.store.List()
|
|
||||||
require.Nil(suite.T(), err)
|
|
||||||
|
|
||||||
require.Equal(suite.T(), len(contexts), 3)
|
|
||||||
require.Equal(suite.T(), "test1", contexts[0].Name)
|
|
||||||
require.Equal(suite.T(), "test2", contexts[1].Name)
|
|
||||||
require.Equal(suite.T(), "default", contexts[2].Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *StoreTestSuite) TestRemoveNotFound() {
|
func (suite *StoreTestSuite) TestRemoveNotFound() {
|
||||||
err := suite.store.Remove("notfound")
|
err := suite.store.Remove("notfound")
|
||||||
require.EqualError(suite.T(), err, `context "notfound": not found`)
|
require.EqualError(suite.T(), err, `context "notfound": not found`)
|
||||||
@ -132,17 +116,18 @@ func (suite *StoreTestSuite) TestRemoveNotFound() {
|
|||||||
func (suite *StoreTestSuite) TestRemove() {
|
func (suite *StoreTestSuite) TestRemove() {
|
||||||
err := suite.store.Create("testremove", "type", "description", ContextMetadata{})
|
err := suite.store.Create("testremove", "type", "description", ContextMetadata{})
|
||||||
require.Nil(suite.T(), err)
|
require.Nil(suite.T(), err)
|
||||||
contexts, err := suite.store.List()
|
|
||||||
|
meta, err := suite.store.Get("testremove")
|
||||||
require.Nil(suite.T(), err)
|
require.Nil(suite.T(), err)
|
||||||
require.Equal(suite.T(), len(contexts), 2)
|
require.NotNil(suite.T(), meta)
|
||||||
|
|
||||||
err = suite.store.Remove("testremove")
|
err = suite.store.Remove("testremove")
|
||||||
require.Nil(suite.T(), err)
|
require.Nil(suite.T(), err)
|
||||||
contexts, err = suite.store.List()
|
|
||||||
require.Nil(suite.T(), err)
|
meta, err = suite.store.Get("testremove")
|
||||||
// The default context is always here, that's why we
|
require.EqualError(suite.T(), err, `context "testremove": not found`)
|
||||||
// have len(contexts) == 1
|
require.Nil(suite.T(), meta)
|
||||||
require.Equal(suite.T(), len(contexts), 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExampleTestSuite(t *testing.T) {
|
func TestExampleTestSuite(t *testing.T) {
|
||||||
|
@ -32,7 +32,7 @@ type endpoint struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dockerDefaultContext() (*Metadata, error) {
|
func dockerDefaultContext() (*Metadata, error) {
|
||||||
cmd := exec.Command("docker", "context", "inspect", "default")
|
cmd := exec.Command("docker-classic", "context", "inspect", "default")
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
cmd.Stdout = &stdout
|
cmd.Stdout = &stdout
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
package store
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestDefaultContext(t *testing.T) {
|
|
||||||
s, err := dockerDefaultContext()
|
|
||||||
assert.Nil(t, err)
|
|
||||||
assert.Equal(t, "default", s.Name)
|
|
||||||
}
|
|
@ -34,6 +34,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gotest.tools/golden"
|
||||||
|
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
@ -56,12 +58,10 @@ func (s *E2eSuite) TestContextHelp() {
|
|||||||
|
|
||||||
func (s *E2eSuite) TestContextDefault() {
|
func (s *E2eSuite) TestContextDefault() {
|
||||||
It("should be initialized with default context", func() {
|
It("should be initialized with default context", func() {
|
||||||
s.NewDockerCommand("context", "use", "default").ExecOrDie()
|
|
||||||
output := s.NewDockerCommand("context", "show").ExecOrDie()
|
output := s.NewDockerCommand("context", "show").ExecOrDie()
|
||||||
Expect(output).To(ContainSubstring("default"))
|
Expect(output).To(ContainSubstring("default"))
|
||||||
output = s.NewCommand("docker", "context", "ls").ExecOrDie()
|
output = s.NewCommand("docker", "context", "ls").ExecOrDie()
|
||||||
Expect(output).To(Not(ContainSubstring("test-example")))
|
golden.Assert(s.T(), output, "ls-out-default.golden")
|
||||||
Expect(output).To(ContainSubstring("default *"))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ func (s *E2eSuite) TestMockBackend() {
|
|||||||
currentContext := s.NewDockerCommand("context", "use", "test-example").ExecOrDie()
|
currentContext := s.NewDockerCommand("context", "use", "test-example").ExecOrDie()
|
||||||
Expect(currentContext).To(ContainSubstring("test-example"))
|
Expect(currentContext).To(ContainSubstring("test-example"))
|
||||||
output := s.NewDockerCommand("context", "ls").ExecOrDie()
|
output := s.NewDockerCommand("context", "ls").ExecOrDie()
|
||||||
Expect(output).To(ContainSubstring("test-example *"))
|
golden.Assert(s.T(), output, "ls-out-test-example.golden")
|
||||||
output = s.NewDockerCommand("context", "show").ExecOrDie()
|
output = s.NewDockerCommand("context", "show").ExecOrDie()
|
||||||
Expect(output).To(ContainSubstring("test-example"))
|
Expect(output).To(ContainSubstring("test-example"))
|
||||||
})
|
})
|
||||||
|
2
tests/e2e/testdata/ls-out-default.golden
vendored
Normal file
2
tests/e2e/testdata/ls-out-default.golden
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
NAME TYPE DESCRIPTION DOCKER ENPOINT KUBERNETES ENDPOINT ORCHESTRATOR
|
||||||
|
default * docker Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
|
@ -1,3 +1,3 @@
|
|||||||
NAME TYPE DESCRIPTION DOCKER ENPOINT KUBERNETES ENDPOINT ORCHESTRATOR
|
NAME TYPE DESCRIPTION DOCKER ENPOINT KUBERNETES ENDPOINT ORCHESTRATOR
|
||||||
default docker Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
|
default docker Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
|
||||||
example * example
|
test-example * example
|
@ -80,10 +80,17 @@ func dirContents(dir string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) linkClassicDocker() {
|
func (s *Suite) linkClassicDocker() {
|
||||||
p, err := exec.LookPath("docker")
|
p, err := exec.LookPath("docker-classic")
|
||||||
|
if err != nil {
|
||||||
|
p, err = exec.LookPath("docker")
|
||||||
|
}
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
err = os.Symlink(p, filepath.Join(s.BinDir, "docker-classic"))
|
err = os.Symlink(p, filepath.Join(s.BinDir, "docker-classic"))
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
|
dockerPath, err := filepath.Abs("../../bin/docker")
|
||||||
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
|
err = os.Symlink(dockerPath, filepath.Join(s.BinDir, "docker"))
|
||||||
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
err = os.Setenv("PATH", fmt.Sprintf("%s:%s", s.BinDir, os.Getenv("PATH")))
|
err = os.Setenv("PATH", fmt.Sprintf("%s:%s", s.BinDir, os.Getenv("PATH")))
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
}
|
}
|
||||||
@ -111,9 +118,9 @@ func (s *Suite) NewCommand(command string, args ...string) *CmdContext {
|
|||||||
|
|
||||||
func dockerExecutable() string {
|
func dockerExecutable() string {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return "../../bin/docker.exe"
|
return "docker.exe"
|
||||||
}
|
}
|
||||||
return "../../bin/docker"
|
return "docker"
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDockerCommand creates a docker builder.
|
// NewDockerCommand creates a docker builder.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user