Skip to content

Commit

Permalink
Merge pull request moby#47395 from robmry/47370_windows_natnw_dns_test
Browse files Browse the repository at this point in the history
Test DNS on Windows 'nat' networks
  • Loading branch information
thaJeztah authored Mar 1, 2024
2 parents f8e6801 + 9083c2f commit 137a9d6
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 137a9d6

Please sign in to comment.