|
@@ -6,6 +6,7 @@ import (
|
|
|
"os"
|
|
|
"testing"
|
|
|
|
|
|
+ "github.com/docker/docker/pkg/ioutils"
|
|
|
_ "github.com/docker/libnetwork/netutils"
|
|
|
)
|
|
|
|
|
@@ -18,9 +19,16 @@ func TestGet(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if string(resolvConfUtils) != string(resolvConfSystem) {
|
|
|
+ if string(resolvConfUtils.Content) != string(resolvConfSystem) {
|
|
|
t.Fatalf("/etc/resolv.conf and GetResolvConf have different content.")
|
|
|
}
|
|
|
+ hashSystem, err := ioutils.HashData(bytes.NewReader(resolvConfSystem))
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ if resolvConfUtils.Hash != hashSystem {
|
|
|
+ t.Fatalf("/etc/resolv.conf and GetResolvConf have different hashes.")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func TestGetNameservers(t *testing.T) {
|
|
@@ -214,51 +222,51 @@ func TestFilterResolvDns(t *testing.T) {
|
|
|
ns0 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\n"
|
|
|
|
|
|
if result, _ := FilterResolvDNS([]byte(ns0), false); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed No Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed No Localhost: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ns1 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\nnameserver 127.0.0.1\n"
|
|
|
if result, _ := FilterResolvDNS([]byte(ns1), false); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ns1 = "nameserver 10.16.60.14\nnameserver 127.0.0.1\nnameserver 10.16.60.21\n"
|
|
|
if result, _ := FilterResolvDNS([]byte(ns1), false); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ns1 = "nameserver 127.0.1.1\nnameserver 10.16.60.14\nnameserver 10.16.60.21\n"
|
|
|
if result, _ := FilterResolvDNS([]byte(ns1), false); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ns1 = "nameserver ::1\nnameserver 10.16.60.14\nnameserver 127.0.2.1\nnameserver 10.16.60.21\n"
|
|
|
if result, _ := FilterResolvDNS([]byte(ns1), false); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ns1 = "nameserver 10.16.60.14\nnameserver ::1\nnameserver 10.16.60.21\nnameserver ::1"
|
|
|
if result, _ := FilterResolvDNS([]byte(ns1), false); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// with IPv6 disabled (false param), the IPv6 nameserver should be removed
|
|
|
ns1 = "nameserver 10.16.60.14\nnameserver 2002:dead:beef::1\nnameserver 10.16.60.21\nnameserver ::1"
|
|
|
if result, _ := FilterResolvDNS([]byte(ns1), false); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed Localhost+IPv6 off: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed Localhost+IPv6 off: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -266,8 +274,8 @@ func TestFilterResolvDns(t *testing.T) {
|
|
|
ns0 = "nameserver 10.16.60.14\nnameserver 2002:dead:beef::1\nnameserver 10.16.60.21\n"
|
|
|
ns1 = "nameserver 10.16.60.14\nnameserver 2002:dead:beef::1\nnameserver 10.16.60.21\nnameserver ::1"
|
|
|
if result, _ := FilterResolvDNS([]byte(ns1), true); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed Localhost+IPv6 on: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed Localhost+IPv6 on: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -275,8 +283,8 @@ func TestFilterResolvDns(t *testing.T) {
|
|
|
ns0 = "\nnameserver 8.8.8.8\nnameserver 8.8.4.4\nnameserver 2001:4860:4860::8888\nnameserver 2001:4860:4860::8844"
|
|
|
ns1 = "nameserver 127.0.0.1\nnameserver ::1\nnameserver 127.0.2.1"
|
|
|
if result, _ := FilterResolvDNS([]byte(ns1), true); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed no Localhost+IPv6 enabled: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed no Localhost+IPv6 enabled: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -284,8 +292,8 @@ func TestFilterResolvDns(t *testing.T) {
|
|
|
ns0 = "\nnameserver 8.8.8.8\nnameserver 8.8.4.4"
|
|
|
ns1 = "nameserver 127.0.0.1\nnameserver ::1\nnameserver 127.0.2.1"
|
|
|
if result, _ := FilterResolvDNS([]byte(ns1), false); result != nil {
|
|
|
- if ns0 != string(result) {
|
|
|
- t.Fatalf("Failed no Localhost+IPv6 enabled: expected \n<%s> got \n<%s>", ns0, string(result))
|
|
|
+ if ns0 != string(result.Content) {
|
|
|
+ t.Fatalf("Failed no Localhost+IPv6 enabled: expected \n<%s> got \n<%s>", ns0, string(result.Content))
|
|
|
}
|
|
|
}
|
|
|
}
|