diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go index 99fb92ec3..735068ac4 100644 --- a/proxy/proxy_test.go +++ b/proxy/proxy_test.go @@ -15,9 +15,12 @@ package proxy import ( + "io/ioutil" "net/http" "net/http/httptest" + "net/url" "testing" + "time" ) func TestReadonlyHandler(t *testing.T) { @@ -51,3 +54,45 @@ func TestReadonlyHandler(t *testing.T) { } } } + +func TestConfigHandlerGET(t *testing.T) { + var err error + us := make([]*url.URL, 3) + us[0], err = url.Parse("http://example1.com") + if err != nil { + t.Fatal(err) + } + us[1], err = url.Parse("http://example2.com") + if err != nil { + t.Fatal(err) + } + us[2], err = url.Parse("http://example3.com") + if err != nil { + t.Fatal(err) + } + + rp := reverseProxy{ + director: &director{ + ep: []*endpoint{ + newEndpoint(*us[0], 1*time.Second), + newEndpoint(*us[1], 1*time.Second), + newEndpoint(*us[2], 1*time.Second), + }, + }, + } + + req, _ := http.NewRequest("GET", "http://example.com//v2/config/local/proxy", nil) + rr := httptest.NewRecorder() + rp.configHandler(rr, req) + + wbody := "{\"endpoints\":[\"http://example1.com\",\"http://example2.com\",\"http://example3.com\"]}\n" + + body, err := ioutil.ReadAll(rr.Body) + if err != nil { + t.Fatal(err) + } + + if string(body) != wbody { + t.Errorf("body = %s, want %s", string(body), wbody) + } +}