summaryrefslogtreecommitdiff
path: root/libnetwork/endpoint_test.go
diff options
context:
space:
mode:
authorKamil Domański <kamil@domanski.co>2019-08-30 23:24:43 +0200
committerKamil Domański <kamil@domanski.co>2019-09-04 01:58:00 +0200
commitc4fcd7059c0cefdf1e055bffaf73f129abe0913c (patch)
tree4f64eb1a337135bb44eee2c6efb8ad2fb64739c6 /libnetwork/endpoint_test.go
parent226fde5cddd7c505ef415b0c0b756b299c39888f (diff)
downloaddocker-c4fcd7059c0cefdf1e055bffaf73f129abe0913c.tar.gz
etchosts: additionally include the container's IPv6 address if available
Signed-off-by: Kamil Domański <kamil@domanski.co>
Diffstat (limited to 'libnetwork/endpoint_test.go')
-rw-r--r--libnetwork/endpoint_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/libnetwork/endpoint_test.go b/libnetwork/endpoint_test.go
new file mode 100644
index 0000000000..675c7a8c17
--- /dev/null
+++ b/libnetwork/endpoint_test.go
@@ -0,0 +1,76 @@
+// +build !windows
+
+package libnetwork
+
+import (
+ "io/ioutil"
+ "os"
+ "testing"
+
+ "github.com/docker/libnetwork/ipamapi"
+ "github.com/docker/libnetwork/osl"
+ "github.com/docker/libnetwork/testutils"
+)
+
+func TestHostsEntries(t *testing.T) {
+ if !testutils.IsRunningInContainer() {
+ defer testutils.SetupTestOSContext(t)()
+ }
+
+ expectedHostsFile := `127.0.0.1 localhost
+::1 localhost ip6-localhost ip6-loopback
+fe00::0 ip6-localnet
+ff00::0 ip6-mcastprefix
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters
+192.168.222.2 somehost.example.com somehost
+fe90::2 somehost.example.com somehost
+`
+
+ opts := []NetworkOption{NetworkOptionEnableIPv6(true), NetworkOptionIpam(ipamapi.DefaultIPAM, "",
+ []*IpamConf{{PreferredPool: "192.168.222.0/24", Gateway: "192.168.222.1"}},
+ []*IpamConf{{PreferredPool: "fe90::/64", Gateway: "fe90::1"}},
+ nil)}
+
+ c, nws := getTestEnv(t, opts)
+ ctrlr := c.(*controller)
+
+ hostsFile, err := ioutil.TempFile("", "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.Remove(hostsFile.Name())
+
+ sbx, err := ctrlr.NewSandbox("sandbox1", OptionHostsPath(hostsFile.Name()), OptionHostname("somehost.example.com"))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ep1, err := nws[0].CreateEndpoint("ep1")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if err := ep1.Join(sbx, JoinOptionPriority(ep1, 1)); err != nil {
+ t.Fatal(err)
+ }
+
+ data, err := ioutil.ReadFile(hostsFile.Name())
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if string(data) != expectedHostsFile {
+ t.Fatalf("expected the hosts file to read:\n%q\nbut instead got the following:\n%q\n", expectedHostsFile, string(data))
+ }
+
+ if err := sbx.Delete(); err != nil {
+ t.Fatal(err)
+ }
+
+ if len(ctrlr.sandboxes) != 0 {
+ t.Fatalf("controller sandboxes is not empty. len = %d", len(ctrlr.sandboxes))
+ }
+
+ osl.GC()
+}