From 11ec66111a146fd2c894a0d8a11766dc3d06e600 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 14 Oct 2014 17:00:14 +0100 Subject: [PATCH] Check duplicate add --- server/http_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/http_test.go b/server/http_test.go index ac81f70c..662f86d8 100644 --- a/server/http_test.go +++ b/server/http_test.go @@ -34,7 +34,8 @@ func TestHttp(t *testing.T) { // Ask the http server to add our test address into the database addr_parts := strings.Split(test_addr1, "/") - resp, err := genForm("PUT", fmt.Sprintf("http://localhost:%d/name/%s/%s", port, container_id, addr_parts[0]), + addr_url := fmt.Sprintf("http://localhost:%d/name/%s/%s", port, container_id, addr_parts[0]) + resp, err := genForm("PUT", addr_url, url.Values{"fqdn": {success_test_name}, "local_ip": {docker_ip}, "routing_prefix": {addr_parts[1]}}) if err != nil { t.Fatal(err) @@ -53,6 +54,15 @@ func TestHttp(t *testing.T) { t.Fatal("Unexpected result for", success_test_name, ip) } + // Now try adding the same address again - should fail + resp, err = genForm("PUT", addr_url, + url.Values{"fqdn": {success_test_name}, "local_ip": {docker_ip}, "routing_prefix": {addr_parts[1]}}) + if err != nil { + t.Fatal(err) + } + if resp.StatusCode != http.StatusConflict { + t.Fatal("Unexpected http response", resp.Status) + } // Would like to shut down the http server at the end of this test // but it's complicated. // See https://groups.google.com/forum/#!topic/golang-nuts/vLHWa5sHnCE