mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
proxy: add a test for configHandler
This commit is contained in:
parent
e079f87410
commit
ac29432aab
@ -15,9 +15,12 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadonlyHandler(t *testing.T) {
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user