diff --git a/nameserver/http_test.go b/nameserver/http_test.go index 8b2b778a..f3cee7a9 100644 --- a/nameserver/http_test.go +++ b/nameserver/http_test.go @@ -24,6 +24,7 @@ func TestHttp(t *testing.T) { testDomain = "weave.local." successTestName = "test1." + testDomain testAddr1 = "10.2.2.1/24" + testAddr2 = "10.2.2.2/24" dockerIP = "9.8.7.6" ) @@ -69,6 +70,31 @@ func TestHttp(t *testing.T) { wt.AssertNoErr(t, err) wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response") + // Adding a new IP for the same name should be OK + addrParts2 := strings.Split(testAddr2, "/") + addrURL2 := fmt.Sprintf("http://localhost:%d/name/%s/%s", port, containerID, addrParts2[0]) + resp, err = genForm("PUT", addrURL2, + url.Values{"fqdn": {successTestName}, "local_ip": {dockerIP}, "routing_prefix": {addrParts2[1]}}) + wt.AssertNoErr(t, err) + wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http success response for second IP") + + // Check that we can get two IPs for that name + ip2, _, _ := net.ParseCIDR(testAddr2) + foundIP, err = zone.LookupName(successTestName) + wt.AssertNoErr(t, err) + if len(foundIP) != 2 { + t.Logf("IPs found: %s", foundIP) + t.Fatalf("Unexpected result length: received %d responses", len(foundIP)) + } + if !(foundIP[0].IP().Equal(ip) || foundIP[0].IP().Equal(ip2)) { + t.Logf("IPs found: %s", foundIP) + t.Fatalf("Unexpected result for %s: received %s, expected %s", successTestName, foundIP, ip) + } + if !(foundIP[1].IP().Equal(ip) || foundIP[1].IP().Equal(ip2)) { + t.Logf("IPs found: %s", foundIP) + t.Fatalf("Unexpected result for %s: received %s, expected %s", successTestName, foundIP, ip) + } + // Delete the address resp, err = genForm("DELETE", addrURL, nil) wt.AssertNoErr(t, err) @@ -84,6 +110,11 @@ func TestHttp(t *testing.T) { wt.AssertNoErr(t, err) wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response") + // Delete the second IP + resp, err = genForm("DELETE", addrURL2, nil) + wt.AssertNoErr(t, err) + wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response") + // Check that the address is gone x, err = zone.LookupName(successTestName) t.Logf("Got %s", x)