Skip to content

Commit 137a9d6

Browse files
authored
Merge pull request moby#47395 from robmry/47370_windows_natnw_dns_test
Test DNS on Windows 'nat' networks
2 parents f8e6801 + 9083c2f commit 137a9d6

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

integration/networking/bridge_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,66 @@ func TestBridgeICC(t *testing.T) {
191191
}
192192
}
193193

194+
// TestBridgeICCWindows tries to ping container ctr1 from container ctr2 using its hostname.
195+
// Checks DNS resolution, and whether containers can communicate with each other.
196+
// Regression test for https://github.com/moby/moby/issues/47370
197+
func TestBridgeICCWindows(t *testing.T) {
198+
skip.If(t, testEnv.DaemonInfo.OSType != "windows")
199+
200+
ctx := setupTest(t)
201+
c := testEnv.APIClient()
202+
203+
testcases := []struct {
204+
name string
205+
netName string
206+
}{
207+
{
208+
name: "Default nat network",
209+
netName: "nat",
210+
},
211+
{
212+
name: "User defined nat network",
213+
netName: "mynat",
214+
},
215+
}
216+
217+
for _, tc := range testcases {
218+
t.Run(tc.name, func(t *testing.T) {
219+
ctx := testutil.StartSpan(ctx, t)
220+
221+
if tc.netName != "nat" {
222+
network.CreateNoError(ctx, t, c, tc.netName,
223+
network.WithDriver("nat"),
224+
)
225+
defer network.RemoveNoError(ctx, t, c, tc.netName)
226+
}
227+
228+
const ctr1Name = "ctr1"
229+
id1 := container.Run(ctx, t, c,
230+
container.WithName(ctr1Name),
231+
container.WithNetworkMode(tc.netName),
232+
)
233+
defer c.ContainerRemove(ctx, id1, containertypes.RemoveOptions{Force: true})
234+
235+
pingCmd := []string{"ping", "-n", "1", "-w", "3000", ctr1Name}
236+
237+
const ctr2Name = "ctr2"
238+
attachCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
239+
defer cancel()
240+
res := container.RunAttach(attachCtx, t, c,
241+
container.WithName(ctr2Name),
242+
container.WithCmd(pingCmd...),
243+
container.WithNetworkMode(tc.netName),
244+
)
245+
defer c.ContainerRemove(ctx, res.ContainerID, containertypes.RemoveOptions{Force: true})
246+
247+
assert.Check(t, is.Equal(res.ExitCode, 0))
248+
assert.Check(t, is.Equal(res.Stderr.Len(), 0))
249+
assert.Check(t, is.Contains(res.Stdout.String(), "Sent = 1, Received = 1, Lost = 0"))
250+
})
251+
}
252+
}
253+
194254
// TestBridgeINC makes sure two containers on two different bridge networks can't communicate with each other.
195255
func TestBridgeINC(t *testing.T) {
196256
skip.If(t, testEnv.DaemonInfo.OSType == "windows")

0 commit comments

Comments
 (0)