move some magic numbers to constants in test harness
This commit is contained in:
1 parent
21e1fb3451
commit
32d3f82325
1 file changed
+9
-3
@@ -4,14 +4,20 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
port = 8765
|
||||||
|
baseURL = "http://localhost:8765/"
|
||||||
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
// start our simple web server
|
// start our simple web server
|
||||||
l, err := net.Listen("tcp", ":8765")
|
l, err := net.Listen("tcp", ":"+strconv.Itoa(port))
|
||||||
if err != nil {
|
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")))
|
http.Handle("/", http.FileServer(http.Dir("./testsite")))
|
||||||
go func() {
|
go func() {
|
||||||
@@ -32,7 +38,7 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestServerRunning(t *testing.T) {
|
func TestServerRunning(t *testing.T) {
|
||||||
resp, err := http.Get("http://localhost:8765/")
|
resp, err := http.Get(baseURL)
|
||||||
if resp.StatusCode != 200 || err != nil {
|
if resp.StatusCode != 200 || err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user