From 32d3f82325218bfeb11a9ec7ae90395efa43f2f0 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sat, 14 Feb 2015 22:18:31 -0800 Subject: [PATCH] move some magic numbers to constants in test harness --- src/docrawler/docrawler_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/docrawler/docrawler_test.go b/src/docrawler/docrawler_test.go index d7177c4..2331cef 100644 --- a/src/docrawler/docrawler_test.go +++ b/src/docrawler/docrawler_test.go @@ -4,14 +4,20 @@ import ( "net" "net/http" "os" + "strconv" "testing" ) +const ( + port = 8765 + baseURL = "http://localhost:8765/" +) + func TestMain(m *testing.M) { // start our simple web server - l, err := net.Listen("tcp", ":8765") + l, err := net.Listen("tcp", ":"+strconv.Itoa(port)) if err != nil { - panic("unable to listen on port 8765") // TODO remove panic? + panic("unable to open port for http server") // TODO remove panic? } http.Handle("/", http.FileServer(http.Dir("./testsite"))) go func() { @@ -32,7 +38,7 @@ func TestMain(m *testing.M) { } func TestServerRunning(t *testing.T) { - resp, err := http.Get("http://localhost:8765/") + resp, err := http.Get(baseURL) if resp.StatusCode != 200 || err != nil { t.Error(err) }