MCPcopy
hub / github.com/moby/moby / TestNetworkLoopbackNat

Function TestNetworkLoopbackNat

integration/container/nat_test.go:81–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

79}
80
81func TestNetworkLoopbackNat(t *testing.T) {
82 skip.If(t, testEnv.GitHubActions, "FIXME: https://github.com/moby/moby/issues/41561")
83 skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
84 skip.If(t, testEnv.IsRemoteDaemon)
85
86 ctx := setupTest(t)
87
88 msg := "it works"
89 serverContainerID := startServerContainer(ctx, t, msg, 8080)
90
91 endpoint := getExternalAddress(t)
92
93 apiClient := testEnv.APIClient()
94
95 cID := container.Run(ctx, t, apiClient,
96 container.WithCmd("sh", "-c", fmt.Sprintf("stty raw && nc -w 1 %s 8080", endpoint.String())),
97 container.WithTty(true),
98 container.WithNetworkMode("container:"+serverContainerID),
99 )
100
101 poll.WaitOn(t, container.IsStopped(ctx, apiClient, cID))
102
103 logs, err := apiClient.ContainerLogs(ctx, cID, client.ContainerLogsOptions{
104 ShowStdout: true,
105 })
106 assert.NilError(t, err)
107 defer logs.Close()
108
109 var b bytes.Buffer
110 _, err = io.Copy(&b, logs)
111 assert.NilError(t, err)
112
113 assert.Check(t, is.Equal(msg, strings.TrimSpace(b.String())))
114}
115
116func startServerContainer(ctx context.Context, t *testing.T, msg string, port uint16) string {
117 t.Helper()

Callers

nothing calls this directly

Calls 15

RunFunction · 0.92
WithCmdFunction · 0.92
WithTtyFunction · 0.92
WithNetworkModeFunction · 0.92
IsStoppedFunction · 0.92
startServerContainerFunction · 0.85
getExternalAddressFunction · 0.85
APIClientMethod · 0.80
CheckMethod · 0.80
EqualMethod · 0.80
setupTestFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…