add test harness web server
* plus "make autotest" runs "make test" once first * add .hgignore
This commit is contained in:
1 parent
da7c5ba57c
commit
3bce3ccd2a
4 files changed
+42
-1
No files matched your search
@@ -33,7 +33,7 @@ vet:
|
|||||||
test:
|
test:
|
||||||
go test ./src/...
|
go test ./src/...
|
||||||
|
|
||||||
autotest:
|
autotest: test
|
||||||
fswatch -or ./src | xargs -n1 -I{} go test ./src/...
|
fswatch -or ./src | xargs -n1 -I{} go test ./src/...
|
||||||
|
|
||||||
run: build
|
run: build
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Whitespace-only changes.
Reference in new issue
Block a user