支持单元测试

This commit is contained in:
白茶清欢 2022-07-01 17:19:46 +08:00
parent 0057825613
commit 09e47648bc

54
rpc_test.go Normal file
View File

@ -0,0 +1,54 @@
// Package rpc ...
//
// Description : rpc ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-07-01 16:00
package rpc
import (
"encoding/json"
"fmt"
"net/http"
"testing"
)
func TestInitRPC(t *testing.T) {
proxyServiceInfo := &Service{
Flag: "goproxy",
Domain: "https://goproxy.cn/",
CodeField: "-",
MessageField: "-",
DataField: "-",
SuccessCodeList: []string{},
SuccessHttpCodeList: []int{http.StatusOK},
ApiTable: map[string]*Api{
"package_info": {
Flag: "package_info",
URI: "/stats/{{package_name}}",
Method: http.MethodGet,
BindURIParamList: []string{"package_name"},
Timeout: ApiTimeout{
Connect: 5000,
Read: 5000,
},
},
},
ApiRetry: ApiRetry{},
}
if err := InitRPC(map[string]*Service{
"goproxy": proxyServiceInfo,
}, nil); nil != err {
panic(err.Error())
}
var result map[string]interface{}
if err := Request.Send(nil, "goproxy", "package_info", map[string]interface{}{
"package_name": "golang.org/x/text",
}, &result); nil != err {
fmt.Println("请求出现异常 : " + err.Error())
return
}
byteData, _ := json.Marshal(result)
fmt.Println(string(byteData))
}