MCPcopy
hub / github.com/docker/compose / TestNetworks

Function TestNetworks

pkg/e2e/networks_test.go:31–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestNetworks(t *testing.T) {
32 // fixture is shared with TestNetworkModes and is not safe to run concurrently
33 const projectName = "network-e2e"
34 c := NewCLI(t, WithEnv(
35 "COMPOSE_PROJECT_NAME="+projectName,
36 "COMPOSE_FILE=./fixtures/network-test/compose.yaml",
37 ))
38
39 c.RunDockerComposeCmd(t, "down", "-t0", "-v")
40
41 c.RunDockerComposeCmd(t, "up", "-d")
42
43 res := c.RunDockerComposeCmd(t, "ps")
44 res.Assert(t, icmd.Expected{Out: `web`})
45
46 endpoint := "http://localhost:80"
47 output := HTTPGetWithRetry(t, endpoint+"/words/noun", http.StatusOK, 2*time.Second, 20*time.Second)
48 assert.Assert(t, strings.Contains(output, `"word":`))
49
50 res = c.RunDockerCmd(t, "network", "ls")
51 res.Assert(t, icmd.Expected{Out: projectName + "_dbnet"})
52 res.Assert(t, icmd.Expected{Out: "microservices"})
53
54 res = c.RunDockerComposeCmd(t, "port", "words", "8080")
55 res.Assert(t, icmd.Expected{Out: `0.0.0.0:8080`})
56
57 c.RunDockerComposeCmd(t, "down", "-t0", "-v")
58 res = c.RunDockerCmd(t, "network", "ls")
59 assert.Assert(t, !strings.Contains(res.Combined(), projectName), res.Combined())
60 assert.Assert(t, !strings.Contains(res.Combined(), "microservices"), res.Combined())
61}
62
63func TestNetworkAliases(t *testing.T) {
64 c := NewParallelCLI(t)

Callers

nothing calls this directly

Calls 5

RunDockerComposeCmdMethod · 0.95
RunDockerCmdMethod · 0.95
NewCLIFunction · 0.85
WithEnvFunction · 0.85
HTTPGetWithRetryFunction · 0.85

Tested by

no test coverage detected