add test harness web server

* plus "make autotest" runs "make test" once first
* add .hgignore
This commit is contained in:
swaits committed 2015-02-14 21:46:52 -08:00
1 parent da7c5ba57c
commit 3bce3ccd2a
4 files changed
+42 -1

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
syntax: glob
.vendor/bin
+1 -1
View File
@@ -33,7 +33,7 @@ vet:
test:
go test ./src/...
autotest:
autotest: test
fswatch -or ./src | xargs -n1 -I{} go test ./src/...
run: build
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"net"
"net/http"
"os"
"testing"
)
func TestMain(m *testing.M) {
// start our simple web server
l, err := net.Listen("tcp", ":8765")
if err != nil {
panic("unable to listen on port 8765") // TODO remove panic?
}
http.Handle("/", http.FileServer(http.Dir("./testsite")))
go func() {
err = http.Serve(l, nil)
if err != nil {
panic("unable to start http server") // TODO remove panic?
}
}()
// run tests
exitcode := m.Run()
// tear down web server
l.Close()
// tell OS our result
os.Exit(exitcode)
}
func TestServerRunning(t *testing.T) {
resp, err := http.Get("http://localhost:8765/")
if resp.StatusCode != 200 || err != nil {
t.Error(err)
}
}
View File
Whitespace-only changes.