Move tests to each backend folder
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
8
.github/labeler.yml
vendored
@ -10,15 +10,15 @@ local:
|
|||||||
cli:
|
cli:
|
||||||
- cli/**/*
|
- cli/**/*
|
||||||
|
|
||||||
|
metrics:
|
||||||
|
- cli/metrics/**/*
|
||||||
|
|
||||||
api:
|
api:
|
||||||
- api/**/*
|
- api/**/*
|
||||||
- protos/**/*
|
- cli/server/protos/**/*
|
||||||
|
|
||||||
ci:
|
ci:
|
||||||
- .github/**/*
|
- .github/**/*
|
||||||
|
|
||||||
documentation:
|
documentation:
|
||||||
- docs/**/*
|
- docs/**/*
|
||||||
|
|
||||||
metrics:
|
|
||||||
- metrics/**/*
|
|
||||||
|
1
.github/workflows/ci.yml
vendored
@ -64,7 +64,6 @@ jobs:
|
|||||||
run: make -f builder.Makefile cross
|
run: make -f builder.Makefile cross
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
env:
|
|
||||||
run: make -f builder.Makefile test
|
run: make -f builder.Makefile test
|
||||||
|
|
||||||
- name: Build for local E2E
|
- name: Build for local E2E
|
||||||
|
8
Makefile
@ -44,16 +44,16 @@ cli: ## Compile the cli
|
|||||||
--output ./bin
|
--output ./bin
|
||||||
|
|
||||||
e2e-local: ## Run End to end local tests. Set E2E_TEST=TestName to run a single test
|
e2e-local: ## Run End to end local tests. Set E2E_TEST=TestName to run a single test
|
||||||
go test -count=1 -v $(TEST_FLAGS) ./tests/e2e ./tests/compose-e2e ./tests/skip-win-ci-e2e ./local/e2e
|
go test -count=1 -v $(TEST_FLAGS) ./local/e2e/compose ./local/e2e/container ./local/e2e/cli-only
|
||||||
|
|
||||||
e2e-win-ci: ## Run end to end local tests on Windows CI, no Docker for Linux containers available ATM. Set E2E_TEST=TestName to run a single test
|
e2e-win-ci: ## Run end to end local tests on Windows CI, no Docker for Linux containers available ATM. Set E2E_TEST=TestName to run a single test
|
||||||
go test -count=1 -v $(TEST_FLAGS) ./tests/e2e
|
go test -count=1 -v $(TEST_FLAGS) ./local/e2e/cli-only
|
||||||
|
|
||||||
e2e-aci: ## Run End to end ACI tests. Set E2E_TEST=TestName to run a single test
|
e2e-aci: ## Run End to end ACI tests. Set E2E_TEST=TestName to run a single test
|
||||||
go test -count=1 -v $(TEST_FLAGS) ./tests/aci-e2e
|
go test -count=1 -v $(TEST_FLAGS) ./aci/e2e
|
||||||
|
|
||||||
e2e-ecs: ## Run End to end ECS tests. Set E2E_TEST=TestName to run a single test
|
e2e-ecs: ## Run End to end ECS tests. Set E2E_TEST=TestName to run a single test
|
||||||
go test -timeout 20m -count=1 -v $(TEST_FLAGS) ./tests/ecs-e2e
|
go test -timeout 20m -count=1 -v $(TEST_FLAGS) ./ecs/e2e/ecs ./ecs/e2e/ecs-local
|
||||||
|
|
||||||
cross: ## Compile the CLI for linux, darwin and windows
|
cross: ## Compile the CLI for linux, darwin and windows
|
||||||
@docker build . --target cross \
|
@docker build . --target cross \
|
||||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 85 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@ -542,10 +542,9 @@ func TestUpSecretsResources(t *testing.T) {
|
|||||||
secret2Name = "mysecret2"
|
secret2Name = "mysecret2"
|
||||||
secret2Value = "another_password\n"
|
secret2Value = "another_password\n"
|
||||||
)
|
)
|
||||||
var (
|
|
||||||
basefilePath = filepath.Join("..", "composefiles", "aci_secrets_resources")
|
composefilePath := filepath.Join("aci_secrets_resources", "compose.yml")
|
||||||
composefilePath = filepath.Join(basefilePath, "compose.yml")
|
|
||||||
)
|
|
||||||
c := NewParallelE2eCLI(t, binDir)
|
c := NewParallelE2eCLI(t, binDir)
|
||||||
_, _, _ = setupTestResourceGroup(t, c)
|
_, _, _ = setupTestResourceGroup(t, c)
|
||||||
|
|
||||||
@ -660,13 +659,12 @@ func TestUpUpdate(t *testing.T) {
|
|||||||
composeAccountName := strings.ToLower(strings.ReplaceAll(groupID, "-", "") + "sa")
|
composeAccountName := strings.ToLower(strings.ReplaceAll(groupID, "-", "") + "sa")
|
||||||
|
|
||||||
dstDir := filepath.Join(os.TempDir(), "e2e-aci-volume-"+composeAccountName)
|
dstDir := filepath.Join(os.TempDir(), "e2e-aci-volume-"+composeAccountName)
|
||||||
srcDir := filepath.Join("..", "composefiles", "aci-demo")
|
err := fileutil.CopyDirs("aci-demo", dstDir)
|
||||||
err := fileutil.CopyDirs(srcDir, dstDir)
|
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
assert.NilError(t, os.RemoveAll(dstDir))
|
assert.NilError(t, os.RemoveAll(dstDir))
|
||||||
})
|
})
|
||||||
_, err = fileutils.CopyFile(filepath.Join(filepath.Join("..", "composefiles"), multiPortComposefile), filepath.Join(dstDir, multiPortComposefile))
|
_, err = fileutils.CopyFile(filepath.Join(filepath.Join("aci-demo"), multiPortComposefile), filepath.Join(dstDir, multiPortComposefile))
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
singlePortVolumesComposefile = filepath.Join(dstDir, singlePortVolumesComposefile)
|
singlePortVolumesComposefile = filepath.Join(dstDir, singlePortVolumesComposefile)
|
@ -81,7 +81,7 @@ func TestCompose(t *testing.T) {
|
|||||||
c, stack := setupTest(t)
|
c, stack := setupTest(t)
|
||||||
|
|
||||||
t.Run("compose up", func(t *testing.T) {
|
t.Run("compose up", func(t *testing.T) {
|
||||||
c.RunDockerCmd("compose", "up", "--project-name", stack, "-f", "../composefiles/ecs_e2e/multi_port_secrets.yaml")
|
c.RunDockerCmd("compose", "up", "--project-name", stack, "-f", "./multi_port_secrets.yaml")
|
||||||
})
|
})
|
||||||
|
|
||||||
var webURL, wordsURL, secretsURL string
|
var webURL, wordsURL, secretsURL string
|
||||||
@ -133,7 +133,7 @@ func TestCompose(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Words GET validating cross service connection", func(t *testing.T) {
|
t.Run("Words GET validating cross service connection", func(t *testing.T) {
|
||||||
out := HTTPGetWithRetry(t, wordsURL, http.StatusOK, 5*time.Second, 240*time.Second)
|
out := HTTPGetWithRetry(t, wordsURL, http.StatusOK, 5*time.Second, 300*time.Second)
|
||||||
assert.Assert(t, strings.Contains(out, `"word":`))
|
assert.Assert(t, strings.Contains(out, `"word":`))
|
||||||
})
|
})
|
||||||
|
|
@ -264,7 +264,7 @@ func TestLocalComposeVolume(t *testing.T) {
|
|||||||
res := c.RunDockerCmd("inspect", "compose-e2e-volume_nginx2_1", "--format", "{{ json .Mounts }}")
|
res := c.RunDockerCmd("inspect", "compose-e2e-volume_nginx2_1", "--format", "{{ json .Mounts }}")
|
||||||
output := res.Stdout()
|
output := res.Stdout()
|
||||||
//nolint
|
//nolint
|
||||||
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"","RW":true,"Propagation":""`))
|
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"","RW":true,"Propagation":""`), output)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("check container bind-mounts specs", func(t *testing.T) {
|
t.Run("check container bind-mounts specs", func(t *testing.T) {
|
@ -17,6 +17,7 @@
|
|||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -24,10 +25,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/assert/cmp"
|
|
||||||
"gotest.tools/v3/icmd"
|
"gotest.tools/v3/icmd"
|
||||||
"gotest.tools/v3/poll"
|
"gotest.tools/v3/poll"
|
||||||
|
|
||||||
|
"github.com/docker/compose-cli/cli/cmd"
|
||||||
. "github.com/docker/compose-cli/tests/framework"
|
. "github.com/docker/compose-cli/tests/framework"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,15 +81,38 @@ func TestLocalBackendRun(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("run with ports", func(t *testing.T) {
|
t.Run("run with ports", func(t *testing.T) {
|
||||||
res := c.RunDockerCmd("run", "-d", "-p", "80", "nginx")
|
res := c.RunDockerCmd("run", "-d", "-p", "85:80", "nginx")
|
||||||
containerName := strings.TrimSpace(res.Combined())
|
containerName := strings.TrimSpace(res.Combined())
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
_ = c.RunDockerOrExitError("rm", "-f", containerName)
|
_ = c.RunDockerOrExitError("rm", "-f", containerName)
|
||||||
})
|
})
|
||||||
res = c.RunDockerCmd("inspect", containerName)
|
res = c.RunDockerCmd("inspect", containerName)
|
||||||
res.Assert(t, icmd.Expected{Out: `"Status": "running"`})
|
|
||||||
|
inspect := &cmd.ContainerInspectView{}
|
||||||
|
err := json.Unmarshal([]byte(res.Stdout()), inspect)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, inspect.Status, "running")
|
||||||
|
nginxID := inspect.ID
|
||||||
|
|
||||||
res = c.RunDockerCmd("ps")
|
res = c.RunDockerCmd("ps")
|
||||||
assert.Assert(t, cmp.Regexp(`0\.0\.0\.0:\d*->80/tcp`, res.Stdout()))
|
nginxFound := false
|
||||||
|
lines := Lines(res.Stdout())
|
||||||
|
for _, line := range lines {
|
||||||
|
fields := strings.Fields(line)
|
||||||
|
if fields[0] == nginxID {
|
||||||
|
nginxFound = true
|
||||||
|
assert.Equal(t, fields[1], "nginx")
|
||||||
|
assert.Equal(t, fields[2], "/docker-entrypoint.sh")
|
||||||
|
assert.Equal(t, fields[len(fields)-1], "0.0.0.0:85->80/tcp")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.Assert(t, nginxFound, res.Stdout())
|
||||||
|
|
||||||
|
res = c.RunDockerCmd("ps", "--format", "json")
|
||||||
|
res.Assert(t, icmd.Expected{Out: `"Image":"nginx","Status":"Up Less than a second","Command":"/docker-entrypoint.sh nginx -g 'daemon off;'","Ports":["0.0.0.0:85->80/tcp"`})
|
||||||
|
|
||||||
|
res = c.RunDockerCmd("ps", "--quiet")
|
||||||
|
res.Assert(t, icmd.Expected{Out: nginxID + "\n"})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("run with volume", func(t *testing.T) {
|
t.Run("run with volume", func(t *testing.T) {
|
83
local/e2e/container/skip_win_ci_test.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 Docker Compose CLI authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package e2e
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gotest.tools/v3/assert"
|
||||||
|
"gotest.tools/v3/icmd"
|
||||||
|
"gotest.tools/v3/poll"
|
||||||
|
|
||||||
|
. "github.com/docker/compose-cli/tests/framework"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestKillChildProcess(t *testing.T) {
|
||||||
|
assert.Assert(t, runtime.GOOS != "windows", "cannot test process signals on windows")
|
||||||
|
c := NewParallelE2eCLI(t, binDir)
|
||||||
|
|
||||||
|
image := "test-sleep-image"
|
||||||
|
psCmd := icmd.Command("ps", "-x")
|
||||||
|
psRes := icmd.RunCmd(psCmd)
|
||||||
|
psRes.Assert(t, icmd.Success)
|
||||||
|
assert.Assert(t, !strings.Contains(psRes.Combined(), image))
|
||||||
|
|
||||||
|
d := writeDockerfile(t)
|
||||||
|
buildArgs := []string{"build", "--no-cache", "-t", image, "."}
|
||||||
|
cmd := c.NewDockerCmd(buildArgs...)
|
||||||
|
cmd.Dir = d
|
||||||
|
res := icmd.StartCmd(cmd)
|
||||||
|
|
||||||
|
buildRunning := func(t poll.LogT) poll.Result {
|
||||||
|
res := icmd.RunCmd(psCmd)
|
||||||
|
if strings.Contains(res.Combined(), strings.Join(buildArgs, " ")) {
|
||||||
|
return poll.Success()
|
||||||
|
}
|
||||||
|
return poll.Continue("waiting for child process to be running")
|
||||||
|
}
|
||||||
|
poll.WaitOn(t, buildRunning, poll.WithDelay(1*time.Second))
|
||||||
|
|
||||||
|
err := res.Cmd.Process.Signal(syscall.SIGTERM)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
buildStopped := func(t poll.LogT) poll.Result {
|
||||||
|
res := icmd.RunCmd(psCmd)
|
||||||
|
if !strings.Contains(res.Combined(), strings.Join(buildArgs, " ")) {
|
||||||
|
return poll.Success()
|
||||||
|
}
|
||||||
|
return poll.Continue("waiting for child process to be killed")
|
||||||
|
}
|
||||||
|
poll.WaitOn(t, buildStopped, poll.WithDelay(1*time.Second), poll.WithTimeout(60*time.Second))
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeDockerfile(t *testing.T) string {
|
||||||
|
d, err := ioutil.TempDir("", "")
|
||||||
|
assert.NilError(t, err)
|
||||||
|
t.Cleanup(func() {
|
||||||
|
_ = os.RemoveAll(d)
|
||||||
|
})
|
||||||
|
err = ioutil.WriteFile(filepath.Join(d, "Dockerfile"), []byte(`FROM alpine:3.10
|
||||||
|
RUN sleep 100`), 0644)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
return d
|
||||||
|
}
|
@ -1,161 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 Docker Compose CLI authors
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gotest.tools/golden"
|
|
||||||
"gotest.tools/v3/assert"
|
|
||||||
"gotest.tools/v3/icmd"
|
|
||||||
"gotest.tools/v3/poll"
|
|
||||||
|
|
||||||
"github.com/docker/compose-cli/cli/cmd"
|
|
||||||
. "github.com/docker/compose-cli/tests/framework"
|
|
||||||
)
|
|
||||||
|
|
||||||
var binDir string
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
p, cleanup, err := SetupExistingCLI()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
binDir = p
|
|
||||||
exitCode := m.Run()
|
|
||||||
cleanup()
|
|
||||||
os.Exit(exitCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestKillChildProcess(t *testing.T) {
|
|
||||||
c := NewParallelE2eCLI(t, binDir)
|
|
||||||
|
|
||||||
image := "test-sleep-image"
|
|
||||||
pCmd := icmd.Command("ps", "-x")
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
pCmd = icmd.Command("tasklist")
|
|
||||||
}
|
|
||||||
pRes := icmd.RunCmd(pCmd)
|
|
||||||
pRes.Assert(t, icmd.Success)
|
|
||||||
assert.Assert(t, !strings.Contains(pRes.Combined(), image))
|
|
||||||
|
|
||||||
d := writeDockerfile(t)
|
|
||||||
buildArgs := []string{"build", "--no-cache", "-t", image, "."}
|
|
||||||
cmd := c.NewDockerCmd(buildArgs...)
|
|
||||||
cmd.Dir = d
|
|
||||||
res := icmd.StartCmd(cmd)
|
|
||||||
|
|
||||||
buildRunning := func(t poll.LogT) poll.Result {
|
|
||||||
res := icmd.RunCmd(pCmd)
|
|
||||||
if strings.Contains(res.Combined(), strings.Join(buildArgs, " ")) {
|
|
||||||
return poll.Success()
|
|
||||||
}
|
|
||||||
return poll.Continue("waiting for child process to be running")
|
|
||||||
}
|
|
||||||
poll.WaitOn(t, buildRunning, poll.WithDelay(1*time.Second))
|
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
err := res.Cmd.Process.Kill()
|
|
||||||
assert.NilError(t, err)
|
|
||||||
} else {
|
|
||||||
err := res.Cmd.Process.Signal(syscall.SIGTERM)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
}
|
|
||||||
buildStopped := func(t poll.LogT) poll.Result {
|
|
||||||
res := icmd.RunCmd(pCmd)
|
|
||||||
if !strings.Contains(res.Combined(), strings.Join(buildArgs, " ")) {
|
|
||||||
return poll.Success()
|
|
||||||
}
|
|
||||||
return poll.Continue("waiting for child process to be killed")
|
|
||||||
}
|
|
||||||
poll.WaitOn(t, buildStopped, poll.WithDelay(1*time.Second), poll.WithTimeout(60*time.Second))
|
|
||||||
}
|
|
||||||
|
|
||||||
// no linux containers on GHA Windows CI nodes (windows server)
|
|
||||||
func TestLocalContainers(t *testing.T) {
|
|
||||||
c := NewParallelE2eCLI(t, binDir)
|
|
||||||
c.RunDockerCmd("context", "create", "local", "test-local")
|
|
||||||
res := c.RunDockerCmd("context", "use", "test-local")
|
|
||||||
res.Assert(t, icmd.Expected{Out: "test-local"})
|
|
||||||
|
|
||||||
t.Run("use", func(t *testing.T) {
|
|
||||||
res := c.RunDockerCmd("context", "show")
|
|
||||||
res.Assert(t, icmd.Expected{Out: "test-local"})
|
|
||||||
res = c.RunDockerCmd("context", "ls")
|
|
||||||
golden.Assert(t, res.Stdout(), GoldenFile("ls-out-test-local"))
|
|
||||||
})
|
|
||||||
|
|
||||||
var nginxContainerName string
|
|
||||||
t.Run("run", func(t *testing.T) {
|
|
||||||
res := c.RunDockerCmd("run", "-d", "-p", "85:80", "nginx")
|
|
||||||
nginxContainerName = strings.TrimSpace(res.Stdout())
|
|
||||||
})
|
|
||||||
defer c.RunDockerOrExitError("rm", "-f", nginxContainerName)
|
|
||||||
|
|
||||||
var nginxID string
|
|
||||||
t.Run("inspect", func(t *testing.T) {
|
|
||||||
res = c.RunDockerCmd("inspect", nginxContainerName)
|
|
||||||
|
|
||||||
inspect := &cmd.ContainerInspectView{}
|
|
||||||
err := json.Unmarshal([]byte(res.Stdout()), inspect)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
nginxID = inspect.ID
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("ps", func(t *testing.T) {
|
|
||||||
res = c.RunDockerCmd("ps")
|
|
||||||
lines := Lines(res.Stdout())
|
|
||||||
nginxFound := false
|
|
||||||
for _, line := range lines {
|
|
||||||
fields := strings.Fields(line)
|
|
||||||
if fields[0] == nginxID {
|
|
||||||
nginxFound = true
|
|
||||||
assert.Equal(t, fields[1], "nginx")
|
|
||||||
assert.Equal(t, fields[2], "/docker-entrypoint.sh")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert.Assert(t, nginxFound, res.Stdout())
|
|
||||||
|
|
||||||
res = c.RunDockerCmd("ps", "--format", "json")
|
|
||||||
res.Assert(t, icmd.Expected{Out: `"Image":"nginx","Status":"Up Less than a second","Command":"/docker-entrypoint.sh nginx -g 'daemon off;'","Ports":["0.0.0.0:85->80/tcp"`})
|
|
||||||
|
|
||||||
res = c.RunDockerCmd("ps", "--quiet")
|
|
||||||
res.Assert(t, icmd.Expected{Out: nginxID + "\n"})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeDockerfile(t *testing.T) string {
|
|
||||||
d, err := ioutil.TempDir("", "")
|
|
||||||
assert.NilError(t, err)
|
|
||||||
t.Cleanup(func() {
|
|
||||||
_ = os.RemoveAll(d)
|
|
||||||
})
|
|
||||||
err = ioutil.WriteFile(filepath.Join(d, "Dockerfile"), []byte(`FROM alpine:3.10
|
|
||||||
RUN sleep 100`), 0644)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
return d
|
|
||||||
}
|
|