1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 10:22:19 +00:00

Add monitoring tests

This commit is contained in:
Alexandre Iooss 2020-10-09 23:26:26 +02:00
parent 0fd1611836
commit aba6215bbc
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02

View File

@ -1 +1,34 @@
package monitoring 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)
}
}