mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 18:32:19 +00:00
Wait 1 second after the web server got served to avoid a request that came too early
This commit is contained in:
parent
cb14434091
commit
cc4c556f2c
@ -3,6 +3,7 @@ package web
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestHTTPServe tries to serve a real HTTP server and load some pages
|
||||
@ -13,20 +14,39 @@ func TestHTTPServe(t *testing.T) {
|
||||
}
|
||||
|
||||
go Serve(nil, nil, &Options{ListenAddress: "127.0.0.1:8081"})
|
||||
|
||||
// Sleep 1 second to ensure that the web server is running, to avoid fails because the request came too early
|
||||
time.Sleep(1000000000)
|
||||
|
||||
// Test GET request
|
||||
resp, _ := http.Get("http://localhost:8081/")
|
||||
resp, err := http.Get("http://localhost:8081/")
|
||||
if err != nil {
|
||||
t.Error("Error while getting /:", err)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
||||
}
|
||||
resp, _ = http.Get("http://localhost:8081/demo")
|
||||
|
||||
resp, err = http.Get("http://localhost:8081/demo")
|
||||
if err != nil {
|
||||
t.Error("Error while getting /demo:", err)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
||||
}
|
||||
resp, _ = http.Get("http://localhost:8081/static/js/viewer.js")
|
||||
|
||||
resp, err = http.Get("http://localhost:8081/static/js/viewer.js")
|
||||
if err != nil {
|
||||
t.Error("Error while getting /static/js/viewer/js:", err)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
||||
}
|
||||
resp, _ = http.Get("http://localhost:8081/_stats")
|
||||
|
||||
resp, err = http.Get("http://localhost:8081/_stats")
|
||||
if err != nil {
|
||||
t.Error("Error while getting /_stats:", err)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user