Browse Source

Add moby backend e2e tests

Djordje Lukic 5 years ago
parent
commit
1c3673c421
3 changed files with 59 additions and 3 deletions
  1. 1 1
      Makefile
  2. 2 2
      moby/backend.go
  3. 56 0
      moby/e2e/backend_test.go

+ 1 - 1
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

+ 2 - 2
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 {

+ 56 - 0
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))
+}