From e4f3bcb696d3ea3580ab7c93d2e41f02108aa011 Mon Sep 17 00:00:00 2001 From: Flavio Crisciani Date: Mon, 23 Oct 2017 10:52:33 +0200 Subject: [PATCH] Add test for dns options Validate that passing an option into the daemon config does not corrupt the option set into the container resolv.conf Signed-off-by: Flavio Crisciani --- libnetwork/service_common_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libnetwork/service_common_test.go b/libnetwork/service_common_test.go index 3a0c2f1807..5b6cae937c 100644 --- a/libnetwork/service_common_test.go +++ b/libnetwork/service_common_test.go @@ -4,6 +4,8 @@ import ( "net" "testing" + "github.com/docker/libnetwork/resolvconf" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -43,3 +45,25 @@ func TestCleanupServiceDiscovery(t *testing.T) { t.Fatalf("Service record not cleaned correctly:%v", c.(*controller).svcRecords) } } + +func TestDNSOptions(t *testing.T) { + c, err := New() + require.NoError(t, err) + + sb, err := c.(*controller).NewSandbox("cnt1", nil) + require.NoError(t, err) + defer sb.Delete() + sb.(*sandbox).startResolver(false) + + sb.(*sandbox).config.dnsOptionsList = []string{"ndots:5"} + err = sb.(*sandbox).setupDNS() + require.NoError(t, err) + err = sb.(*sandbox).rebuildDNS() + require.NoError(t, err) + + currRC, err := resolvconf.GetSpecific(sb.(*sandbox).config.resolvConfPath) + require.NoError(t, err) + dnsOptionsList := resolvconf.GetOptions(currRC.Content) + assert.Equal(t, 1, len(dnsOptionsList), "There should be only 1 option instead:", dnsOptionsList) + assert.Equal(t, "ndots:0", dnsOptionsList[0], "The option must be ndots:0 instead:", dnsOptionsList[0]) +}