mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 09:12:19 +00:00
35 lines
958 B
Go
35 lines
958 B
Go
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)
|
|
}
|
|
}
|