Ver Fonte

Fixed #TSB-1234 test

ilucky.si há 1 ano atrás
pai
commit
899e015da3
4 ficheiros alterados com 67 adições e 3 exclusões
  1. 6 1
      containers/registry.go
  2. 29 0
      containers/registry_test.go
  3. 1 2
      utils/httputil.go
  4. 31 0
      utils/httputil_test.go

+ 6 - 1
containers/registry.go

@@ -142,7 +142,7 @@ func (r *Registry) Close() {
 	close(r.events)
 	close(r.events)
 }
 }
 
 
-// "code":1000,"msg":"send ok","data"
+// "code":1000,"msg":"send ok","data"...
 type WhilteListMsg struct {
 type WhilteListMsg struct {
 	Code    string        `json:"code"`
 	Code    string        `json:"code"`
 	Message string        `json:"msg"`
 	Message string        `json:"msg"`
@@ -154,6 +154,7 @@ type WhiteListParam struct {
 	AccountID int32  `json:"account_id"`
 	AccountID int32  `json:"account_id"`
 }
 }
 
 
+// func (r *Registry) getWhiteList() {
 func (r *Registry) getWhiteList() {
 func (r *Registry) getWhiteList() {
 	ticker := time.NewTicker(60)
 	ticker := time.NewTicker(60)
 	defer ticker.Stop()
 	defer ticker.Stop()
@@ -162,6 +163,10 @@ func (r *Registry) getWhiteList() {
 		case <-ticker.C:
 		case <-ticker.C:
 			param := WhiteListParam{HostID: "1618154815414545", AccountID: 110}
 			param := WhiteListParam{HostID: "1618154815414545", AccountID: 110}
 			paramByte, err := json.Marshal(param)
 			paramByte, err := json.Marshal(param)
+			if err != nil {
+				// log.Errorf("agent[cdc] get runner status error:%s ", err)
+				continue
+			}
 			resp, err := utils.HTTPConnect("POST", "http://10.0.12.192:18080/api/v1/agent/whitelist", "", paramByte)
 			resp, err := utils.HTTPConnect("POST", "http://10.0.12.192:18080/api/v1/agent/whitelist", "", paramByte)
 			if err != nil {
 			if err != nil {
 				// log.Errorf("agent[cdc] get runner status error:%s ", err)
 				// log.Errorf("agent[cdc] get runner status error:%s ", err)

+ 29 - 0
containers/registry_test.go

@@ -0,0 +1,29 @@
+//package containers
+//
+//import (
+//	"encoding/json"
+//	"fmt"
+//	"github.com/coroot/coroot-node-agent/utils"
+//	"testing"
+//)
+//
+//func TestGetWhiteList(t *testing.T) {
+//	// reg := NewRegistry(nil, "", nil)
+//	// getWhiteList()
+//	param := WhiteListParam{HostID: "1618154815414545", AccountID: 110}
+//	paramByte, err := json.Marshal(param)
+//	if err != nil {
+//		// log.Errorf("agent[cdc] get runner status error:%s ", err)
+//		// continue
+//	}
+//	resp, err := utils.HTTPConnect("POST", "http://10.0.12.192:18080/api/v1/agent/whitelist", "", paramByte)
+//	if err != nil {
+//		// log.Errorf("agent[cdc] get runner status error:%s ", err)
+//	}
+//	result := WhilteListMsg{}
+//	err = json.Unmarshal(resp, &result)
+//	if err != nil {
+//		// log.Errorf("agent[cdc] get runner status error:%s", err)
+//	}
+//	fmt.Println(result)
+//}

+ 1 - 2
utils/httputil.go

@@ -2,7 +2,6 @@ package utils
 
 
 import (
 import (
 	"bytes"
 	"bytes"
-	"fmt"
 	"io/ioutil"
 	"io/ioutil"
 	"net/http"
 	"net/http"
 	"runtime"
 	"runtime"
@@ -47,6 +46,6 @@ func HTTPConnect(method, url, token string, data []byte) ([]byte, error) {
 		// log.Errorf("http read body error:%s", err)
 		// log.Errorf("http read body error:%s", err)
 		return nil, err
 		return nil, err
 	}
 	}
-	fmt.Println(result)
+	// fmt.Println(result)
 	return result, nil
 	return result, nil
 }
 }

+ 31 - 0
utils/httputil_test.go

@@ -0,0 +1,31 @@
+package utils
+
+//type WhilteListMsg struct {
+//	Code    string        `json:"code"`
+//	Message string        `json:"msg"`
+//	Data    []interface{} `json:"data"`
+//}
+//
+//type WhiteListParam struct {
+//	HostID    string `json:"host_id"`
+//	AccountID int32  `json:"account_id"`
+//}
+
+// func TestGetWhiteList(t *testing.T) {
+//param := WhiteListParam{HostID: "1618154815414545", AccountID: 110}
+//paramByte, err := json.Marshal(param)
+//if err != nil {
+//	// log.Errorf("agent[cdc] get runner status error:%s ", err)
+//	// continue
+//}
+//resp, err := utils.HTTPConnect("POST", "http://10.0.12.192:18080/api/v1/agent/whitelist", "", paramByte)
+//if err != nil {
+//	// log.Errorf("agent[cdc] get runner status error:%s ", err)
+//}
+//result := WhilteListMsg{}
+//err = json.Unmarshal(resp, &result)
+//if err != nil {
+//	// log.Errorf("agent[cdc] get runner status error:%s", err)
+//}
+//fmt.Println(result)
+// }