git » dnss » commit 134fed8

Merge monitoring_test.go into dnss_test.go

author Alberto Bertogli
2017-07-30 15:48:44 UTC
committer Alberto Bertogli
2017-07-30 16:21:46 UTC
parent 7c060030db44aad8eca9d883e56622370d2b53cd

Merge monitoring_test.go into dnss_test.go

There's no good reason for monitoring_test.go to exist separate from
dnss_test.go, so merge the former into the latter, to avoid clutter.

dnss_test.go +32 -0
monitoring_test.go +0 -42

diff --git a/dnss_test.go b/dnss_test.go
index 353f08b..8c573aa 100644
--- a/dnss_test.go
+++ b/dnss_test.go
@@ -4,6 +4,7 @@ package main
 import (
 	"flag"
 	"fmt"
+	"net/http"
 	"os"
 	"strings"
 	"sync"
@@ -240,3 +241,34 @@ func TestDumpFlags(t *testing.T) {
 		t.Errorf("Flags string missing canary value: %v", f)
 	}
 }
+
+func TestMonitoringServer(t *testing.T) {
+	addr := testutil.GetFreePort()
+	launchMonitoringServer(addr)
+	testutil.WaitForHTTPServer(addr)
+
+	checkGet(t, "http://"+addr+"/")
+	checkGet(t, "http://"+addr+"/debug/requests")
+	checkGet(t, "http://"+addr+"/debug/pprof/goroutine")
+	checkGet(t, "http://"+addr+"/debug/flags")
+	checkGet(t, "http://"+addr+"/debug/vars")
+
+	// Check that we emit 404 for non-existing paths.
+	r, _ := http.Get("http://" + addr + "/doesnotexist")
+	if r.StatusCode != 404 {
+		t.Errorf("expected 404, got %s", r.Status)
+	}
+}
+
+func checkGet(t *testing.T, url string) {
+	r, err := http.Get(url)
+	if err != nil {
+		t.Error(err)
+		return
+	}
+
+	if r.StatusCode != 200 {
+		t.Errorf("%q - invalid status: %s", url, r.Status)
+	}
+
+}
diff --git a/monitoring_test.go b/monitoring_test.go
deleted file mode 100644
index 496a8c4..0000000
--- a/monitoring_test.go
+++ /dev/null
@@ -1,42 +0,0 @@
-package main
-
-// Tests for the monitoring server.
-//
-// Note that functional tests for dnss are in the testing/ directory, here we
-// only test the monitoring server created in dnss.go.
-
-import (
-	"net/http"
-	"testing"
-)
-
-func TestMonitoringServer(t *testing.T) {
-	// TODO: Don't hard-code this.
-	const addr = "localhost:19395"
-	launchMonitoringServer(addr)
-
-	checkGet(t, "http://"+addr+"/")
-	checkGet(t, "http://"+addr+"/debug/requests")
-	checkGet(t, "http://"+addr+"/debug/pprof/goroutine")
-	checkGet(t, "http://"+addr+"/debug/flags")
-	checkGet(t, "http://"+addr+"/debug/vars")
-
-	// Check that we emit 404 for non-existing paths.
-	r, _ := http.Get("http://" + addr + "/doesnotexist")
-	if r.StatusCode != 404 {
-		t.Errorf("expected 404, got %s", r.Status)
-	}
-}
-
-func checkGet(t *testing.T, url string) {
-	r, err := http.Get(url)
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	if r.StatusCode != 200 {
-		t.Errorf("%q - invalid status: %s", url, r.Status)
-	}
-
-}