Browse code

inte/networking: test DNS resolution for non swarm-scoped nws

Previous commit reverted a faulty change that broke DNS resolution for
non swarm-scoped networks once a node has joined a Swarm cluster.

This commit adds an integration test to verify that we don't break DNS
resolution again.

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>

Albin Kerouanton authored on 2025/11/12 23:00:18
Showing 1 changed files
... ...
@@ -2032,3 +2032,29 @@ func TestLegacyLinksEnvVars(t *testing.T) {
2032 2032
 		})
2033 2033
 	}
2034 2034
 }
2035
+
2036
+// TestDNSNamesForNonSwarmScopedNetworks checks that container names can be resolved for non-swarm-scoped networks once
2037
+// a node has joined a Swarm cluster.
2038
+//
2039
+// Regression test for https://github.com/moby/moby/issues/51491.
2040
+func TestDNSNamesForNonSwarmScopedNetworks(t *testing.T) {
2041
+	ctx := setupTest(t)
2042
+
2043
+	d := daemon.New(t)
2044
+	d.StartAndSwarmInit(ctx, t)
2045
+	defer d.Stop(t)
2046
+
2047
+	c := d.NewClientT(t)
2048
+	defer c.Close()
2049
+
2050
+	const bridgeName = "dnsnames-with-swarm"
2051
+	network.CreateNoError(ctx, t, c, bridgeName)
2052
+	defer network.RemoveNoError(ctx, t, c, bridgeName)
2053
+
2054
+	res := container.RunAttach(ctx, t, c,
2055
+		container.WithName("test"),
2056
+		container.WithCmd("nslookup", "-type=a", "test."),
2057
+		container.WithNetworkMode(bridgeName),
2058
+		container.WithAutoRemove)
2059
+	assert.Equal(t, res.ExitCode, 0, "exit code: %d, expected 0; stdout:\n%s", res.ExitCode, res.Stdout)
2060
+}