From 1c3673c42160fbdc59aa601cdd5ed2113dae4da6 Mon Sep 17 00:00:00 2001 From: Djordje Lukic Date: Fri, 22 May 2020 17:05:46 +0200 Subject: [PATCH] Add moby backend e2e tests --- Makefile | 2 +- moby/backend.go | 4 +-- moby/e2e/backend_test.go | 56 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 moby/e2e/backend_test.go diff --git a/Makefile b/Makefile index f2988dfdf..32d3d894e 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ cli: ## Compile the cli --target cli e2e-local: ## Run End to end local tests - go test -v ./tests/e2e + go test -v ./tests/e2e ./moby/e2e e2e-aci: ## Run End to end ACI tests (requires azure login) go test -v ./tests/aci-e2e diff --git a/moby/backend.go b/moby/backend.go index 91623a12a..5c6616a7d 100644 --- a/moby/backend.go +++ b/moby/backend.go @@ -3,7 +3,6 @@ package moby import ( "bufio" "context" - "fmt" "io" "strconv" "time" @@ -108,8 +107,9 @@ func (ms *mobyService) Run(ctx context.Context, r containers.ContainerConfig) er return err } scanner := bufio.NewScanner(io) + + // Read the whole body, otherwise the pulling stops for scanner.Scan() { - fmt.Println(string(scanner.Bytes())) } if err = scanner.Err(); err != nil { diff --git a/moby/e2e/backend_test.go b/moby/e2e/backend_test.go new file mode 100644 index 000000000..90b72c863 --- /dev/null +++ b/moby/e2e/backend_test.go @@ -0,0 +1,56 @@ +package e2e + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "github.com/docker/api/tests/framework" +) + +type MobyBackendTestSuite struct { + framework.Suite +} + +func (m *MobyBackendTestSuite) BeforeTest(suiteName string, testName string) { + m.NewDockerCommand("context", "create", "test-context", "moby").ExecOrDie() + m.NewDockerCommand("context", "use", "test-context").ExecOrDie() +} + +func (m *MobyBackendTestSuite) AfterTest(suiteName string, testName string) { + m.NewDockerCommand("context", "rm", "test-context").ExecOrDie() + m.NewDockerCommand("context", "use", "default").ExecOrDie() +} + +func (m *MobyBackendTestSuite) TestPs() { + out := m.NewDockerCommand("ps").ExecOrDie() + require.Equal(m.T(), "CONTAINER ID IMAGE COMMAND STATUS PORTS\n", out) +} + +func (m *MobyBackendTestSuite) TestRun() { + _, err := m.NewDockerCommand("run", "--name", "nginx", "nginx").Exec() + require.Nil(m.T(), err) + out := m.NewDockerCommand("ps").ExecOrDie() + defer func() { + m.NewDockerCommand("rm", "-f", "nginx").ExecOrDie() + }() + lines := strings.Split(out, "\n") + assert.Equal(m.T(), 3, len(lines)) +} + +func (m *MobyBackendTestSuite) TestRunWithPorts() { + _, err := m.NewDockerCommand("run", "--name", "nginx", "-p", "8080:80", "nginx").Exec() + require.Nil(m.T(), err) + out := m.NewDockerCommand("ps").ExecOrDie() + defer func() { + m.NewDockerCommand("rm", "-f", "nginx").ExecOrDie() + }() + assert.Contains(m.T(), out, "8080") +} + +func TestMobyBackendTestSuite(t *testing.T) { + suite.Run(t, new(MobyBackendTestSuite)) +}