mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Signed-off-by: rohit01 <hello@rohit.io>
This commit is contained in:
parent
d13db89548
commit
30c3e02864
|
@ -336,6 +336,10 @@ func fetchApps(client *http.Client, url string) (*AppList, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resp.StatusCode < 200) || (resp.StatusCode >= 300) {
|
||||||
|
return nil, fmt.Errorf("Non 2xx status '%v' response during marathon service discovery", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -16,7 +16,9 @@ package marathon
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -326,6 +328,33 @@ func TestMarathonZeroTaskPorts(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test500ErrorHttpResponseWithValidJSONBody(t *testing.T) {
|
||||||
|
var (
|
||||||
|
ch = make(chan []*targetgroup.Group, 1)
|
||||||
|
client = fetchApps
|
||||||
|
)
|
||||||
|
// Simulate 500 error with a valid JSON response.
|
||||||
|
respHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
io.WriteString(w, `{}`)
|
||||||
|
}
|
||||||
|
// Create a test server with mock HTTP handler.
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(respHandler))
|
||||||
|
defer ts.Close()
|
||||||
|
// Backup conf for future tests.
|
||||||
|
backupConf := conf
|
||||||
|
defer func() {
|
||||||
|
conf = backupConf
|
||||||
|
}()
|
||||||
|
// Setup conf for the test case.
|
||||||
|
conf = SDConfig{Servers: []string{ts.URL}}
|
||||||
|
// Execute test case and validate behaviour.
|
||||||
|
if err := testUpdateServices(client, ch); err == nil {
|
||||||
|
t.Fatalf("Expected error for 5xx HTTP response from marathon server")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func marathonTestAppListWithoutPortMappings(labels map[string]string, runningTasks int) *AppList {
|
func marathonTestAppListWithoutPortMappings(labels map[string]string, runningTasks int) *AppList {
|
||||||
var (
|
var (
|
||||||
task = Task{
|
task = Task{
|
||||||
|
|
Loading…
Reference in a new issue