libnetwork: move TestDNSOptions to a non-windows file
It was only testing stub implementations on Windows that are not used in production code. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
e0da5cb929
commit
1e4e9161c5
3 changed files with 87 additions and 86 deletions
87
libnetwork/sandbox_dns_unix_test.go
Normal file
87
libnetwork/sandbox_dns_unix_test.go
Normal file
|
@ -0,0 +1,87 @@
|
|||
//go:build !windows
|
||||
|
||||
package libnetwork
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/libnetwork/resolvconf"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
"gotest.tools/v3/skip"
|
||||
)
|
||||
|
||||
func TestDNSOptions(t *testing.T) {
|
||||
skip.If(t, runtime.GOOS == "windows", "test only works on linux")
|
||||
|
||||
c, err := New()
|
||||
assert.NilError(t, err)
|
||||
|
||||
sb, err := c.NewSandbox("cnt1", nil)
|
||||
assert.NilError(t, err)
|
||||
|
||||
cleanup := func(s *Sandbox) {
|
||||
if err := s.Delete(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
defer cleanup(sb)
|
||||
sb.startResolver(false)
|
||||
|
||||
err = sb.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
err = sb.rebuildDNS()
|
||||
assert.NilError(t, err)
|
||||
currRC, err := resolvconf.GetSpecific(sb.config.resolvConfPath)
|
||||
assert.NilError(t, err)
|
||||
dnsOptionsList := resolvconf.GetOptions(currRC.Content)
|
||||
assert.Check(t, is.Len(dnsOptionsList, 1))
|
||||
assert.Check(t, is.Equal("ndots:0", dnsOptionsList[0]))
|
||||
|
||||
sb.config.dnsOptionsList = []string{"ndots:5"}
|
||||
err = sb.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
currRC, err = resolvconf.GetSpecific(sb.config.resolvConfPath)
|
||||
assert.NilError(t, err)
|
||||
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
|
||||
assert.Check(t, is.Len(dnsOptionsList, 1))
|
||||
assert.Check(t, is.Equal("ndots:5", dnsOptionsList[0]))
|
||||
|
||||
err = sb.rebuildDNS()
|
||||
assert.NilError(t, err)
|
||||
currRC, err = resolvconf.GetSpecific(sb.config.resolvConfPath)
|
||||
assert.NilError(t, err)
|
||||
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
|
||||
assert.Check(t, is.Len(dnsOptionsList, 1))
|
||||
assert.Check(t, is.Equal("ndots:5", dnsOptionsList[0]))
|
||||
|
||||
sb2, err := c.NewSandbox("cnt2", nil)
|
||||
assert.NilError(t, err)
|
||||
defer cleanup(sb2)
|
||||
sb2.startResolver(false)
|
||||
|
||||
sb2.config.dnsOptionsList = []string{"ndots:0"}
|
||||
err = sb2.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
err = sb2.rebuildDNS()
|
||||
assert.NilError(t, err)
|
||||
currRC, err = resolvconf.GetSpecific(sb2.config.resolvConfPath)
|
||||
assert.NilError(t, err)
|
||||
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
|
||||
assert.Check(t, is.Len(dnsOptionsList, 1))
|
||||
assert.Check(t, is.Equal("ndots:0", dnsOptionsList[0]))
|
||||
|
||||
sb2.config.dnsOptionsList = []string{"ndots:foobar"}
|
||||
err = sb2.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
err = sb2.rebuildDNS()
|
||||
assert.Error(t, err, "invalid number for ndots option: foobar")
|
||||
|
||||
sb2.config.dnsOptionsList = []string{"ndots:-1"}
|
||||
err = sb2.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
err = sb2.rebuildDNS()
|
||||
assert.Error(t, err, "invalid number for ndots option: -1")
|
||||
}
|
|
@ -20,18 +20,8 @@ func (sb *Sandbox) updateHostsFile(ifaceIP []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (sb *Sandbox) addHostsEntries(recs []etchosts.Record) {}
|
||||
|
||||
func (sb *Sandbox) deleteHostsEntries(recs []etchosts.Record) {}
|
||||
|
||||
func (sb *Sandbox) updateDNS(ipv6Enabled bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sb *Sandbox) setupDNS() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sb *Sandbox) rebuildDNS() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,9 +6,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/docker/internal/testutils/netnsutils"
|
||||
"github.com/docker/docker/libnetwork/resolvconf"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
"gotest.tools/v3/skip"
|
||||
)
|
||||
|
||||
|
@ -56,77 +54,3 @@ func TestCleanupServiceDiscovery(t *testing.T) {
|
|||
t.Fatalf("Service record not cleaned correctly:%v", c.svcRecords)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDNSOptions(t *testing.T) {
|
||||
skip.If(t, runtime.GOOS == "windows", "test only works on linux")
|
||||
|
||||
c, err := New()
|
||||
assert.NilError(t, err)
|
||||
|
||||
sb, err := c.NewSandbox("cnt1", nil)
|
||||
assert.NilError(t, err)
|
||||
|
||||
cleanup := func(s *Sandbox) {
|
||||
if err := s.Delete(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
defer cleanup(sb)
|
||||
sb.startResolver(false)
|
||||
|
||||
err = sb.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
err = sb.rebuildDNS()
|
||||
assert.NilError(t, err)
|
||||
currRC, err := resolvconf.GetSpecific(sb.config.resolvConfPath)
|
||||
assert.NilError(t, err)
|
||||
dnsOptionsList := resolvconf.GetOptions(currRC.Content)
|
||||
assert.Check(t, is.Len(dnsOptionsList, 1))
|
||||
assert.Check(t, is.Equal("ndots:0", dnsOptionsList[0]))
|
||||
|
||||
sb.config.dnsOptionsList = []string{"ndots:5"}
|
||||
err = sb.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
currRC, err = resolvconf.GetSpecific(sb.config.resolvConfPath)
|
||||
assert.NilError(t, err)
|
||||
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
|
||||
assert.Check(t, is.Len(dnsOptionsList, 1))
|
||||
assert.Check(t, is.Equal("ndots:5", dnsOptionsList[0]))
|
||||
|
||||
err = sb.rebuildDNS()
|
||||
assert.NilError(t, err)
|
||||
currRC, err = resolvconf.GetSpecific(sb.config.resolvConfPath)
|
||||
assert.NilError(t, err)
|
||||
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
|
||||
assert.Check(t, is.Len(dnsOptionsList, 1))
|
||||
assert.Check(t, is.Equal("ndots:5", dnsOptionsList[0]))
|
||||
|
||||
sb2, err := c.NewSandbox("cnt2", nil)
|
||||
assert.NilError(t, err)
|
||||
defer cleanup(sb2)
|
||||
sb2.startResolver(false)
|
||||
|
||||
sb2.config.dnsOptionsList = []string{"ndots:0"}
|
||||
err = sb2.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
err = sb2.rebuildDNS()
|
||||
assert.NilError(t, err)
|
||||
currRC, err = resolvconf.GetSpecific(sb2.config.resolvConfPath)
|
||||
assert.NilError(t, err)
|
||||
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
|
||||
assert.Check(t, is.Len(dnsOptionsList, 1))
|
||||
assert.Check(t, is.Equal("ndots:0", dnsOptionsList[0]))
|
||||
|
||||
sb2.config.dnsOptionsList = []string{"ndots:foobar"}
|
||||
err = sb2.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
err = sb2.rebuildDNS()
|
||||
assert.Error(t, err, "invalid number for ndots option: foobar")
|
||||
|
||||
sb2.config.dnsOptionsList = []string{"ndots:-1"}
|
||||
err = sb2.setupDNS()
|
||||
assert.NilError(t, err)
|
||||
err = sb2.rebuildDNS()
|
||||
assert.Error(t, err, "invalid number for ndots option: -1")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue