1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-23 01:32:19 +00:00
ghostream/web/web_test.go

54 lines
1.5 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) {
// Load templates
if err := loadTemplates(); err != nil {
t.Errorf("Failed to load templates: %v", err)
}
2020-10-09 20:20:35 +00:00
go Serve(nil, nil, &Options{Enabled: true, 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)
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)
}
}