mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-18 14:50:26 +08:00
增加测试用例
This commit is contained in:
@@ -36,6 +36,7 @@ func TestRPC_Dial_HTTP(t *testing.T) {
|
|||||||
client, err := NewRPCClient(&configs.APIConfig{
|
client, err := NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPC: struct {
|
||||||
Endpoints []string `yaml:"endpoints"`
|
Endpoints []string `yaml:"endpoints"`
|
||||||
|
DisableUpdate bool `yaml:"disableUpdate"`
|
||||||
}{
|
}{
|
||||||
Endpoints: []string{"http://127.0.0.1:8004"},
|
Endpoints: []string{"http://127.0.0.1:8004"},
|
||||||
},
|
},
|
||||||
@@ -57,6 +58,7 @@ func TestRPC_Dial_HTTP_2(t *testing.T) {
|
|||||||
client, err := NewRPCClient(&configs.APIConfig{
|
client, err := NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPC: struct {
|
||||||
Endpoints []string `yaml:"endpoints"`
|
Endpoints []string `yaml:"endpoints"`
|
||||||
|
DisableUpdate bool `yaml:"disableUpdate"`
|
||||||
}{
|
}{
|
||||||
Endpoints: []string{"https://127.0.0.1:8003"},
|
Endpoints: []string{"https://127.0.0.1:8003"},
|
||||||
},
|
},
|
||||||
@@ -78,6 +80,7 @@ func TestRPC_Dial_HTTPS(t *testing.T) {
|
|||||||
client, err := NewRPCClient(&configs.APIConfig{
|
client, err := NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPC: struct {
|
||||||
Endpoints []string `yaml:"endpoints"`
|
Endpoints []string `yaml:"endpoints"`
|
||||||
|
DisableUpdate bool `yaml:"disableUpdate"`
|
||||||
}{
|
}{
|
||||||
Endpoints: []string{"https://127.0.0.1:8004"},
|
Endpoints: []string{"https://127.0.0.1:8004"},
|
||||||
},
|
},
|
||||||
@@ -94,3 +97,53 @@ func TestRPC_Dial_HTTPS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log(resp.Node)
|
t.Log(resp.Node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkNewRPCClient(b *testing.B) {
|
||||||
|
config, err := configs.LoadAPIConfig()
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
rpc, err := NewRPCClient(config, true)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
resp, err := rpc.AdminRPC().LoginAdmin(rpc.Context(0), &pb.LoginAdminRequest{
|
||||||
|
Username: "admin",
|
||||||
|
Password: stringutil.Md5("123456"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
_ = resp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkNewRPCClient_2(b *testing.B) {
|
||||||
|
config, err := configs.LoadAPIConfig()
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
rpc, err := NewRPCClient(config, true)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var conn = rpc.AdminRPC()
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
resp, err := conn.LoginAdmin(rpc.Context(0), &pb.LoginAdminRequest{
|
||||||
|
Username: "admin",
|
||||||
|
Password: stringutil.Md5("123456"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
_ = resp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user