compose/local/e2e/backend_test.go

64 lines
1.9 KiB
Go
Raw Normal View History

2020-05-22 17:05:46 +02:00
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 LocalBackendTestSuite struct {
2020-05-22 17:05:46 +02:00
framework.Suite
}
func (m *LocalBackendTestSuite) BeforeTest(suiteName string, testName string) {
m.NewDockerCommand("context", "create", "local", "test-context").ExecOrDie()
2020-05-22 17:05:46 +02:00
m.NewDockerCommand("context", "use", "test-context").ExecOrDie()
}
func (m *LocalBackendTestSuite) AfterTest(suiteName string, testName string) {
m.NewDockerCommand("context", "rm", "-f", "test-context").ExecOrDie()
2020-05-22 17:05:46 +02:00
}
func (m *LocalBackendTestSuite) TestPs() {
2020-05-22 17:05:46 +02:00
out := m.NewDockerCommand("ps").ExecOrDie()
require.Equal(m.T(), "CONTAINER ID IMAGE COMMAND STATUS PORTS\n", out)
}
func (m *LocalBackendTestSuite) TestRun() {
2020-05-22 17:05:46 +02:00
_, 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 *LocalBackendTestSuite) TestRunWithPorts() {
2020-05-22 17:05:46 +02:00
_, 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")
out = m.NewDockerCommand("inspect", "nginx").ExecOrDie()
assert.Contains(m.T(), out, "\"Status\": \"running\"")
}
func (m *LocalBackendTestSuite) TestInspectNotFound() {
out, _ := m.NewDockerCommand("inspect", "nonexistentcontainer").Exec()
assert.Contains(m.T(), out, "Error: No such container: nonexistentcontainer")
2020-05-22 17:05:46 +02:00
}
func TestLocalBackendTestSuite(t *testing.T) {
suite.Run(t, new(LocalBackendTestSuite))
2020-05-22 17:05:46 +02:00
}