aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2018-03-06 09:17:03 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2018-03-06 09:17:03 +0800
commit4e13eabc333ec3b69009a266738c335eff01f2c3 (patch)
tree6999cc0aef28e93c8fe175ba68f7bcb597663a12 /src
parent817d8346892314a97ab0110df83cf0b066c85e17 (diff)
add ut for addService of msb
Issue-ID: MSB-173 Change-Id: Ia0b557ec4cb367e8ae111b3c2488e7fa10eeadda Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
Diffstat (limited to 'src')
-rw-r--r--src/kube2msb/msb_work_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/kube2msb/msb_work_test.go b/src/kube2msb/msb_work_test.go
index e271d22..9f5a823 100644
--- a/src/kube2msb/msb_work_test.go
+++ b/src/kube2msb/msb_work_test.go
@@ -16,9 +16,62 @@ limitations under the License.
package main
import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "net/http/httptest"
"testing"
)
+func TestAddServiceMsb(t *testing.T) {
+ handler := func(res http.ResponseWriter, req *http.Request) {
+ if req.Method != "POST" {
+ t.Errorf("Register() request method should be 'Post' not %s", req.Method)
+ } else if urlPrefix != req.URL.String() {
+ t.Errorf("Register() url should be %s, not %s", urlPrefix, req.URL)
+ } else {
+ body, err := ioutil.ReadAll(req.Body)
+ if err != nil {
+ t.Errorf("Register() fail to read request body")
+ }
+ var su = ServiceUnit{}
+ parseError := json.Unmarshal([]byte(body), &su)
+ if parseError != nil {
+ t.Errorf("Register() request body can not parse to ServiceUnit, %s", body)
+ return
+ } else {
+ res.WriteHeader(200)
+ res.Header().Set("Content-Type", "application/xml")
+ fmt.Fprintln(res, "regist success")
+ }
+ }
+
+ }
+ server := httptest.NewServer(http.HandlerFunc(handler))
+ defer server.Close()
+
+ client := MSBAgentWorker{
+ agent: &MSBAgent{
+ url: server.URL,
+ },
+ }
+
+ serviceInfo := `[{
+ "port":"8080",
+ "serviceName":"resgisterTest",
+ "version":"v1",
+ "url":"/register/test",
+ "protocol":"http",
+ "lb_policy":"random",
+ "visualRange":"1",
+ "path":"rt",
+ "enable_ssl":true
+ }]`
+
+ client.AddService("192.168.1.10", serviceInfo)
+}
+
func TestMergeIP(t *testing.T) {
cases := []struct{ ip, sInfo, want string }{
{"127.0.0.1", "{}", "{\"ip\":\"127.0.0.1\",}"},