mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 19:42:20 +00:00
Also test web server desactivation
This commit is contained in:
parent
fe43fdb4ae
commit
5f457a1e6a
@ -85,7 +85,7 @@ func Serve(rSdpChan chan struct {
|
|||||||
cfg = c
|
cfg = c
|
||||||
|
|
||||||
if !cfg.Enabled {
|
if !cfg.Enabled {
|
||||||
// SRT is not enabled, ignore
|
// Web server is not enabled, ignore
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,39 +8,54 @@ import (
|
|||||||
|
|
||||||
// TestHTTPServe tries to serve a real HTTP server and load some pages
|
// TestHTTPServe tries to serve a real HTTP server and load some pages
|
||||||
func TestHTTPServe(t *testing.T) {
|
func TestHTTPServe(t *testing.T) {
|
||||||
|
go Serve(nil, nil, &Options{Enabled: false, 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)
|
||||||
|
|
||||||
|
// Test GET request, should fail
|
||||||
|
resp, err := http.Get("http://localhost:8081/")
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Web server did init with Enabled=false")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now let's really start the web server
|
||||||
go Serve(nil, nil, &Options{Enabled: true, ListenAddress: "127.0.0.1:8081"})
|
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
|
// Sleep 500ms to ensure that the web server is running, to avoid fails because the request came too early
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
// Test GET request
|
// Test home page
|
||||||
resp, err := http.Get("http://localhost:8081/")
|
resp, err = http.Get("http://localhost:8081/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error while getting /:", err)
|
t.Errorf("Error while getting /: %s", err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test viewer page
|
||||||
resp, err = http.Get("http://localhost:8081/demo")
|
resp, err = http.Get("http://localhost:8081/demo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error while getting /demo:", err)
|
t.Errorf("Error while getting /demo: %s", err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test viewer static file
|
||||||
resp, err = http.Get("http://localhost:8081/static/js/viewer.js")
|
resp, err = http.Get("http://localhost:8081/static/js/viewer.js")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error while getting /static/js/viewer/js:", err)
|
t.Errorf("Error while getting /static/js/viewer/js: %s", err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
t.Errorf("Viewer page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test viewer statistic endpoint
|
||||||
resp, err = http.Get("http://localhost:8081/_stats/demo/")
|
resp, err = http.Get("http://localhost:8081/_stats/demo/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error while getting /_stats:", err)
|
t.Errorf("Error while getting /_stats: %s", err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Errorf("Viewer page returned %v != %v on GET", 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