Fix up nameserver tests for previous refactoring

This commit is contained in:
Bryan Boreham committed 2015-01-02 17:12:21 +00:00
1 parent 734a3abae8
commit 0af9b2cbab
4 files changed
+37 -33

No files matched your search

+14 -13
View File
@@ -2,6 +2,7 @@ package nameserver
import (
"fmt"
wt "github.com/zettio/weave/common"
"math/rand"
"net"
"net/http"
@@ -38,12 +39,12 @@ func TestHttp(t *testing.T) {
addrUrl := fmt.Sprintf("http://localhost:%d/name/%s/%s", port, containerID, addrParts[0])
resp, err := genForm("PUT", addrUrl,
url.Values{"fqdn": {successTestName}, "local_ip": {dockerIP}, "routing_prefix": {addrParts[1]}})
assertNoErr(t, err)
assertStatus(t, resp.StatusCode, http.StatusOK, "http response")
wt.AssertNoErr(t, err)
wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response")
// Check that the address is now there.
foundIP, err := zone.LookupLocal(successTestName)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
ip, _, _ := net.ParseCIDR(testAddr1)
if !foundIP.Equal(ip) {
t.Fatal("Unexpected result for", successTestName, foundIP)
@@ -52,34 +53,34 @@ func TestHttp(t *testing.T) {
// Adding exactly the same address should be OK
resp, err = genForm("PUT", addrUrl,
url.Values{"fqdn": {successTestName}, "local_ip": {dockerIP}, "routing_prefix": {addrParts[1]}})
assertNoErr(t, err)
assertStatus(t, resp.StatusCode, http.StatusOK, "http success response for duplicate add")
wt.AssertNoErr(t, err)
wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http success response for duplicate add")
// Now try adding the same address again with a different ident --
// again should be fine
otherUrl := fmt.Sprintf("http://localhost:%d/name/%s/%s", port, "other", addrParts[0])
resp, err = genForm("PUT", otherUrl,
url.Values{"fqdn": {successTestName}, "local_ip": {dockerIP}, "routing_prefix": {addrParts[1]}})
assertNoErr(t, err)
assertStatus(t, resp.StatusCode, http.StatusOK, "http response")
wt.AssertNoErr(t, err)
wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response")
// Delete the address
resp, err = genForm("DELETE", addrUrl, nil)
assertNoErr(t, err)
assertStatus(t, resp.StatusCode, http.StatusOK, "http response")
wt.AssertNoErr(t, err)
wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response")
// Check that the address is still resolvable.
_, err = zone.LookupLocal(successTestName)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
// Delete the address record mentioning the other container
resp, err = genForm("DELETE", otherUrl, nil)
assertNoErr(t, err)
assertStatus(t, resp.StatusCode, http.StatusOK, "http response")
wt.AssertNoErr(t, err)
wt.AssertStatus(t, resp.StatusCode, http.StatusOK, "http response")
// Check that the address is gone
_, err = zone.LookupLocal(successTestName)
assertErrorType(t, err, (*LookupError)(nil), "fully-removed address")
wt.AssertErrorType(t, err, (*LookupError)(nil), "fully-removed address")
// Would like to shut down the http server at the end of this test
// but it's complicated.
+4 -3
View File
@@ -2,6 +2,7 @@ package nameserver
import (
"github.com/miekg/dns"
wt "github.com/zettio/weave/common"
"log"
"net"
"testing"
@@ -61,9 +62,9 @@ func RunLocalMulticastServer() (*dns.Server, error) {
func setup(t *testing.T) (*MDNSClient, *dns.Server, error) {
mdnsClient, err := NewMDNSClient()
assertNoErr(t, err)
wt.AssertNoErr(t, err)
err = mdnsClient.Start(nil)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
server, err := RunLocalMulticastServer()
if err != nil {
@@ -87,7 +88,7 @@ func (c *testContext) checkResponse(t *testing.T, channelOk bool, resp *Response
c.channel = nil
return
}
assertNoErr(t, resp.Err)
wt.AssertNoErr(t, resp.Err)
log.Printf("Got address response %s addr %s", resp.Name, resp.Addr)
c.receivedAddr = resp.Addr
c.receivedCount++
+4 -3
View File
@@ -2,6 +2,7 @@ package nameserver
import (
"github.com/miekg/dns"
wt "github.com/zettio/weave/common"
"log"
"net"
"testing"
@@ -36,16 +37,16 @@ func TestServerSimpleQuery(t *testing.T) {
zone.AddRecord(containerID, "test.weave.", ip)
mdnsServer, err := NewMDNSServer(zone)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
err = mdnsServer.Start(nil)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
var receivedAddr net.IP
receivedCount := 0
// Implement a minimal listener for responses
multicast, err := LinkLocalMulticastListener(nil)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
handleMDNS := func(w dns.ResponseWriter, r *dns.Msg) {
// Only handle responses here
+15 -14
View File
@@ -1,6 +1,7 @@
package nameserver
import (
wt "github.com/zettio/weave/common"
"net"
"testing"
)
@@ -17,17 +18,17 @@ func TestZone(t *testing.T) {
ip, _, _ := net.ParseCIDR(testAddr1)
err := zone.AddRecord(containerID, successTestName, ip)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
// Add a few more records to make the job harder
err = zone.AddRecord("abcdef0123", "adummy.weave.", net.ParseIP("10.0.0.1"))
assertNoErr(t, err)
wt.AssertNoErr(t, err)
err = zone.AddRecord("0123abcdef", "zdummy.weave.", net.ParseIP("10.0.0.2"))
assertNoErr(t, err)
wt.AssertNoErr(t, err)
// Check that the address is now there.
foundIP, err := zone.LookupLocal(successTestName)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
if !foundIP.Equal(ip) {
t.Fatal("Unexpected result for", successTestName, foundIP)
@@ -35,33 +36,33 @@ func TestZone(t *testing.T) {
// See if we can find the address by IP.
foundName, err := zone.ReverseLookupLocal(ip)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
if foundName != successTestName {
t.Fatal("Unexpected result for", ip, foundName)
}
err = zone.AddRecord(containerID, successTestName, ip)
assertErrorType(t, err, (*DuplicateError)(nil), "duplicate add")
wt.AssertErrorType(t, err, (*DuplicateError)(nil), "duplicate add")
err = zone.AddRecord(otherContainerID, successTestName, ip)
// Delete the record for the original container
err = zone.DeleteRecord(containerID, ip)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
_, err = zone.LookupLocal(successTestName)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
err = zone.DeleteRecord(otherContainerID, ip)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
// Check that the address is not there now.
_, err = zone.LookupLocal(successTestName)
assertErrorType(t, err, (*LookupError)(nil), "after deleting record")
wt.AssertErrorType(t, err, (*LookupError)(nil), "after deleting record")
// Delete a record that isn't there
err = zone.DeleteRecord(containerID, net.ParseIP("0.0.0.0"))
assertErrorType(t, err, (*LookupError)(nil), "when deleting record that doesn't exist")
wt.AssertErrorType(t, err, (*LookupError)(nil), "when deleting record that doesn't exist")
}
func TestDeleteFor(t *testing.T) {
@@ -75,13 +76,13 @@ func TestDeleteFor(t *testing.T) {
for _, addr := range []string{addr1, addr2} {
ip, _, _ := net.ParseCIDR(addr)
err := zone.AddRecord(id, name, ip)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
}
_, err := zone.LookupLocal(name)
assertNoErr(t, err)
wt.AssertNoErr(t, err)
err = zone.DeleteRecordsFor(id)
_, err = zone.LookupLocal(name)
assertErrorType(t, err, (*LookupError)(nil), "after deleting records for ident")
wt.AssertErrorType(t, err, (*LookupError)(nil), "after deleting records for ident")
}