Skip to content

Commit

Permalink
Test DNS on Windows 'nat' networks
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Murray <rob.murray@docker.com>
  • Loading branch information
robmry authored and Dzejrou committed Mar 5, 2024
1 parent 611610f commit 56ae6ef
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions integration/networking/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,66 @@ func TestBridgeICC(t *testing.T) {
}
}

// TestBridgeICCWindows tries to ping container ctr1 from container ctr2 using its hostname.
// Checks DNS resolution, and whether containers can communicate with each other.
// Regression test for https://github.com/moby/moby/issues/47370
func TestBridgeICCWindows(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "windows")

ctx := setupTest(t)
c := testEnv.APIClient()

testcases := []struct {
name string
netName string
}{
{
name: "Default nat network",
netName: "nat",
},
{
name: "User defined nat network",
netName: "mynat",
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
ctx := testutil.StartSpan(ctx, t)

if tc.netName != "nat" {
network.CreateNoError(ctx, t, c, tc.netName,
network.WithDriver("nat"),
)
defer network.RemoveNoError(ctx, t, c, tc.netName)
}

const ctr1Name = "ctr1"
id1 := container.Run(ctx, t, c,
container.WithName(ctr1Name),
container.WithNetworkMode(tc.netName),
)
defer c.ContainerRemove(ctx, id1, containertypes.RemoveOptions{Force: true})

pingCmd := []string{"ping", "-n", "1", "-w", "3000", ctr1Name}

const ctr2Name = "ctr2"
attachCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
res := container.RunAttach(attachCtx, t, c,
container.WithName(ctr2Name),
container.WithCmd(pingCmd...),
container.WithNetworkMode(tc.netName),
)
defer c.ContainerRemove(ctx, res.ContainerID, containertypes.RemoveOptions{Force: true})

assert.Check(t, is.Equal(res.ExitCode, 0))
assert.Check(t, is.Equal(res.Stderr.Len(), 0))
assert.Check(t, is.Contains(res.Stdout.String(), "Sent = 1, Received = 1, Lost = 0"))
})
}
}

// TestBridgeINC makes sure two containers on two different bridge networks can't communicate with each other.
func TestBridgeINC(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
Expand Down

0 comments on commit 56ae6ef

Please sign in to comment.