mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 04:32:19 +00:00
Add monitoring tests
This commit is contained in:
parent
0fd1611836
commit
aba6215bbc
@ -1 +1,34 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestMonitoringServe(t *testing.T) {
|
||||
go Serve(&Options{Enabled: false, ListenAddress: "127.0.0.1:2112"})
|
||||
|
||||
// Sleep 0.5 second 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://127.0.0.1:2112/metrics")
|
||||
if err == nil {
|
||||
t.Error("Failed to fail task")
|
||||
}
|
||||
|
||||
go Serve(&Options{Enabled: true, ListenAddress: "127.0.0.1:2112"})
|
||||
|
||||
// Sleep 0.5 second 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
|
||||
resp, err = http.Get("http://127.0.0.1:2112/metrics")
|
||||
if err != nil {
|
||||
t.Error("Error while getting /metrics:", err)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("Metric page returned %v != %v on GET", resp.StatusCode, http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user