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