Add tests for metrics server check

This commit is contained in:
stefanprodan
2018-12-27 12:42:12 +02:00
parent 6ec3d7a76f
commit cbf9e1011d
+33 -2
View File
@@ -10,7 +10,6 @@ import (
func TestCanaryObserver_GetDeploymentCounter(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
json := `{"status":"success","data":{"resultType":"vector","result":[{"metric":{},"value":[1545905245.458,"100"]}]}}`
w.WriteHeader(http.StatusAccepted)
w.Write([]byte(json))
}))
defer ts.Close()
@@ -33,7 +32,6 @@ func TestCanaryObserver_GetDeploymentCounter(t *testing.T) {
func TestCanaryObserver_GetDeploymentHistogram(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
json := `{"status":"success","data":{"resultType":"vector","result":[{"metric":{},"value":[1545905245.596,"0.2"]}]}}`
w.WriteHeader(http.StatusAccepted)
w.Write([]byte(json))
}))
defer ts.Close()
@@ -51,3 +49,36 @@ func TestCanaryObserver_GetDeploymentHistogram(t *testing.T) {
t.Errorf("Got %v wanted %v", val, 200*time.Millisecond)
}
}
func TestCheckMetricsServer(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
json := `{"status":"success","data":{"config.file":"/etc/prometheus/prometheus.yml"}}`
w.Write([]byte(json))
}))
defer ts.Close()
ok, err := CheckMetricsServer(ts.URL)
if err != nil {
t.Fatal(err.Error())
}
if !ok {
t.Errorf("Got %v wanted %v", ok, true)
}
}
func TestCheckMetricsServer_Offline(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadGateway)
}))
defer ts.Close()
ok, err := CheckMetricsServer(ts.URL)
if err == nil {
t.Errorf("Got no error wanted %v", http.StatusBadGateway)
}
if ok {
t.Errorf("Got %v wanted %v", ok, true)
}
}