Skip to content

Commit

Permalink
Fix various modification in e2e tests
Browse files Browse the repository at this point in the history
By example we do not display the full reference anymore but use relocation map

Signed-off-by: Yves Brissaud <[email protected]>
  • Loading branch information
eunomie committed Nov 6, 2019
1 parent 8e4bcca commit 5ff8896
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 37 deletions.
27 changes: 17 additions & 10 deletions e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ func readFile(t *testing.T, path string) string {
}

type dindSwarmAndRegistryInfo struct {
swarmAddress string
registryAddress string
configuredCmd icmd.Cmd
stopRegistry func()
registryLogs func() string
swarmAddress string
registryAddress string
insecureRegistryAddress string
configuredCmd icmd.Cmd
stopRegistry func()
registryLogs func() string
}

func runWithDindSwarmAndRegistry(t *testing.T, todo func(dindSwarmAndRegistryInfo)) {
Expand Down Expand Up @@ -91,15 +92,21 @@ func runWithDindSwarmAndRegistry(t *testing.T, todo func(dindSwarmAndRegistryInf
icmd.RunCmd(cmd).Assert(t, icmd.Success)

info := dindSwarmAndRegistryInfo{
configuredCmd: cmd,
registryAddress: registry.GetAddress(t),
swarmAddress: swarm.GetAddress(t),
stopRegistry: registry.StopNoFail,
registryLogs: registry.Logs(t),
configuredCmd: cmd,
registryAddress: registry.GetAddress(t),
insecureRegistryAddress: strings.Split(swarm.GetPrivateAddress(t), ":")[0] + strconv.Itoa(registryPort),
swarmAddress: swarm.GetAddress(t),
stopRegistry: registry.StopNoFail,
registryLogs: registry.Logs(t),
}
todo(info)
}

func build(t *testing.T, cmd icmd.Cmd, dockerCli dockerCliCommand, ref, path string) {
cmd.Command = dockerCli.Command("app", "build", "-t", ref, path)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
}

// Container represents a docker container
type Container struct {
image string
Expand Down
56 changes: 29 additions & 27 deletions e2e/pushpull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,50 @@ package e2e

import (
"fmt"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
"gotest.tools/icmd"
"path/filepath"
"strings"
"testing"

"gotest.tools/assert"
"gotest.tools/assert/cmp"
"gotest.tools/icmd"
)

func TestPushInsecureRegistry(t *testing.T) {
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
ref := info.registryAddress + "/test/push-insecure"
cmd := info.configuredCmd
path := filepath.Join("testdata", "local")

// create a command outside of the dind context so without the insecure registry configured
cmdNoInsecureRegistry, cleanupNoInsecureRegistryCommand := dockerCli.createTestCmd()
defer cleanupNoInsecureRegistryCommand()
cmdNoInsecureRegistry.Command = dockerCli.Command("app", "push", "--tag", ref, filepath.Join("testdata", "push-pull", "push-pull.dockerapp"))
icmd.RunCmd(cmdNoInsecureRegistry).Assert(t, icmd.Expected{ExitCode: 1})
// build for local (authorized) registry
ref := info.registryAddress + "/test/local"
build(t, cmd, dockerCli, ref, path)
// push it
cmd.Command = dockerCli.Command("app", "push", ref)
icmd.RunCmd(cmd).Assert(t, icmd.Success)

// run the push with the command inside dind context configured to allow access to the insecure registry
cmd := info.configuredCmd
cmd.Command = dockerCli.Command("app", "push", "--tag", ref, filepath.Join("testdata", "push-pull", "push-pull.dockerapp"))
// tag it with dind private address that is not part of insecure registry configuration
insecureRef := info.insecureRegistryAddress + "/test/local"
cmd.Command = dockerCli.Command("app", "image", "tag", ref, insecureRef)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
// push it
cmd.Command = dockerCli.Command("app", "push", insecureRef)
icmd.RunCmd(cmd).Assert(t, icmd.Expected{ExitCode: 1})
})
}

func TestPushInstall(t *testing.T) {
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
cmd := info.configuredCmd
ref := info.registryAddress + "/test/push-pull"
path := filepath.Join("testdata", "push-pull")
cmd.Command = dockerCli.Command("app", "build", "-f", filepath.Join(path, "push-pull.dockerapp"), "-t", ref, path)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
build(t, cmd, dockerCli, ref, filepath.Join("testdata", "push-pull"))

cmd.Command = dockerCli.Command("app", "push", ref)
icmd.RunCmd(cmd).Assert(t, icmd.Success)

cmd.Command = dockerCli.Command("app", "run", ref, "--name", t.Name())
icmd.RunCmd(cmd).Assert(t, icmd.Success)
cmd.Command = dockerCli.Command("service", "ls")
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), ref))
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), t.Name()))
})
}

Expand All @@ -49,9 +54,8 @@ func TestPushPullInstall(t *testing.T) {
cmd := info.configuredCmd
ref := info.registryAddress + "/test/push-pull"
tag := ":v.0.0.1"
path := filepath.Join("testdata", "push-pull")
cmd.Command = dockerCli.Command("app", "build", "-f", filepath.Join(path, "push-pull.dockerapp"), "-t", ref+tag, path)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
build(t, cmd, dockerCli, ref+tag, filepath.Join("testdata", "push-pull"))

cmd.Command = dockerCli.Command("app", "push", ref+tag)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
cmd.Command = dockerCli.Command("app", "pull", ref+tag)
Expand Down Expand Up @@ -90,8 +94,7 @@ func TestPushInstallBundle(t *testing.T) {
ref := info.registryAddress + "/test/push-bundle"

// render the app to a bundle, we use the app from the push pull test above.
cmd.Command = dockerCli.Command("app", "build", "--tag", "a-simple-app:1.0.0", filepath.Join("testdata", "push-pull"))
icmd.RunCmd(cmd).Assert(t, icmd.Success)
build(t, cmd, dockerCli, "a-simple-app:1.0.0", filepath.Join("testdata", "push-pull"))

// push it and install to check it is available
t.Run("push-bundle", func(t *testing.T) {
Expand All @@ -104,14 +107,14 @@ func TestPushInstallBundle(t *testing.T) {
cmd.Command = dockerCli.Command("app", "run", ref, "--name", name)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
cmd.Command = dockerCli.Command("service", "ls")
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), ref))
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), name))

// ensure it doesn't confuse the next test
cmd.Command = dockerCli.Command("app", "rm", name)
icmd.RunCmd(cmd).Assert(t, icmd.Success)

cmd.Command = dockerCli.Command("service", "ls")
assert.Check(t, !strings.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), ref))
assert.Check(t, !strings.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), name))
})

// push it again using the first ref and install from the new ref to check it is also available
Expand All @@ -126,7 +129,7 @@ func TestPushInstallBundle(t *testing.T) {
cmd.Command = dockerCli.Command("app", "run", ref2, "--name", name)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
cmd.Command = dockerCli.Command("service", "ls")
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), ref2))
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), name))
})

// push it again using an app pre-bundled and tagged in the bundle store and install it to check it is also available
Expand All @@ -142,8 +145,7 @@ func TestPushInstallBundle(t *testing.T) {
cmdIsolatedStore.Env = append(cmdIsolatedStore.Env, "DOCKER_CONTEXT=swarm-context")

// bundle the app again but this time with a tag to store it into the bundle store
cmdIsolatedStore.Command = dockerCli.Command("app", "build", "--tag", ref2, filepath.Join("testdata", "push-pull"))
icmd.RunCmd(cmdIsolatedStore).Assert(t, icmd.Success)
build(t, cmdIsolatedStore, dockerCli, ref2, filepath.Join("testdata", "push-pull"))
// Push the app without tagging it explicitly
cmdIsolatedStore.Command = dockerCli.Command("app", "push", ref2)
icmd.RunCmd(cmdIsolatedStore).Assert(t, icmd.Success)
Expand All @@ -153,7 +155,7 @@ func TestPushInstallBundle(t *testing.T) {
cmd.Command = dockerCli.Command("app", "run", ref2, "--name", name)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
cmd.Command = dockerCli.Command("service", "ls")
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), ref))
assert.Check(t, cmp.Contains(icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(), name))
})
})
}
15 changes: 15 additions & 0 deletions e2e/testdata/local/local.dockerapp/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.6"
services:
web:
image: web
build: ./web
ports:
- "${services.web.port}:8080"
worker:
image: worker
build:
context: ./worker
args:
- REPLACE_BY_BUILD_ARG=original
- STATIC_ARG=static
dockerfile: Dockerfile.worker
6 changes: 6 additions & 0 deletions e2e/testdata/local/local.dockerapp/metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 1.1.0-beta1
name: local
description: "new fancy webapp with microservices"
maintainers:
- name: John Developer
email: [email protected]
3 changes: 3 additions & 0 deletions e2e/testdata/local/local.dockerapp/parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
web:
port: 1234
3 changes: 3 additions & 0 deletions e2e/testdata/local/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch

COPY . .
7 changes: 7 additions & 0 deletions e2e/testdata/local/worker/Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM nginx
ARG REPLACE_BY_BUILD_ARG
ARG STATIC_ARG
LABEL com.docker.labelled.arg=$REPLACE_BY_BUILD_ARG
LABEL com.docker.labelled.optional=$STATIC_ARG

COPY . .

0 comments on commit 5ff8896

Please sign in to comment.