diff options
author | Lvbo163 <lv.bo163@zte.com.cn> | 2018-03-07 16:09:14 +0800 |
---|---|---|
committer | Lvbo163 <lv.bo163@zte.com.cn> | 2018-03-07 16:09:14 +0800 |
commit | 3aaf336fe722034b287dcbfc9fdf5bfb2ca23366 (patch) | |
tree | 8329da5705d8dd096913220b9c29b6d917b40184 | |
parent | b2b8cf15b00fff79137e69d3c52be1dc148f0c30 (diff) |
add ut for msb deregister
Issue-ID: MSB-172
Change-Id: I42b7617be1b1cf87c6b33ee07321a889f68b7424
Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
-rw-r--r-- | src/kube2msb/msb_client_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/kube2msb/msb_client_test.go b/src/kube2msb/msb_client_test.go index 72ff6fb..2897085 100644 --- a/src/kube2msb/msb_client_test.go +++ b/src/kube2msb/msb_client_test.go @@ -118,3 +118,61 @@ func TestRegister(t *testing.T) { client.Register(serviceInfo) } + +func TestDeRegister(t *testing.T) { + cases := []struct{ url, serviceInfo string }{ + { // Version is "" + urlPrefix + "/resgisterTest1/version/null/nodes/192.168.1.10/8080", + `[{ + "ip":"192.168.1.10", + "port":"8080", + "serviceName":"resgisterTest1", + "version":"", + "url":"/register/test", + "protocol":"http", + "lb_policy":"random", + "visualRange":"1", + "path":"rt", + "enable_ssl":true + }]`, + }, { // version is not "" + urlPrefix + "/resgisterTest2/version/v1/nodes/192.168.1.10/8080", + `[{ + "ip":"192.168.1.10", + "port":"8080", + "serviceName":"resgisterTest2", + "version":"v1", + "url":"/register/test", + "protocol":"http", + "lb_policy":"random", + "visualRange":"1", + "path":"rt", + "enable_ssl":true + }]`, + }, + } + + for _, c := range cases { + handler := func(res http.ResponseWriter, req *http.Request) { + if req.Method != "DELETE" { + t.Errorf("DeRegister() request method should be 'DELETE' not %s", req.Method) + } else if c.url != req.URL.String() { + t.Errorf("DeRegister() url should be %s, not %s", c.url, req.URL) + } else { + res.WriteHeader(200) + res.Header().Set("Content-Type", "application/xml") + fmt.Fprintln(res, "deregist success") + } + + } + server := httptest.NewServer(http.HandlerFunc(handler)) + defer server.Close() + + client := MSBAgent{ + url: server.URL, + } + + client.DeRegister(c.serviceInfo) + } + +} |