ghostream/web/web_test.go

49 lines
1.4 KiB
Go
Raw Normal View History

2020-09-30 14:11:51 +00:00
package web
import (
"net/http"
"testing"
"time"
2020-09-30 14:11:51 +00:00
)
// TestHTTPServe tries to serve a real HTTP server and load some pages
func TestHTTPServe(t *testing.T) {
2020-10-09 20:20:35 +00:00
go Serve(nil, nil, &Options{Enabled: true, ListenAddress: "127.0.0.1:8081"})
// Sleep 500ms to ensure that the web server is running, to avoid fails because the request came too early
time.Sleep(500 * time.Millisecond)
2020-09-30 14:11:51 +00:00
// Test GET request
resp, err := http.Get("http://localhost:8081/")
if err != nil {
t.Error("Error while getting /:", err)
}
2020-09-30 14:11:51 +00:00
if resp.StatusCode != http.StatusOK {
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
}
resp, err = http.Get("http://localhost:8081/demo")
if err != nil {
t.Error("Error while getting /demo:", err)
}
2020-09-30 14:11:51 +00:00
if resp.StatusCode != http.StatusOK {
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
}
resp, err = http.Get("http://localhost:8081/static/js/viewer.js")
if err != nil {
t.Error("Error while getting /static/js/viewer/js:", err)
}
2020-09-30 14:11:51 +00:00
if resp.StatusCode != http.StatusOK {
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
}
2020-10-06 07:32:41 +00:00
resp, err = http.Get("http://localhost:8081/_stats/demo/")
if err != nil {
t.Error("Error while getting /_stats:", err)
}
2020-09-30 14:11:51 +00:00
if resp.StatusCode != http.StatusOK {
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
}
}