go-zero/zrpc/internal/rpcpubserver_test.go

51 lines
863 B
Go
Raw Normal View History

2021-02-17 21:42:22 +08:00
package internal
import (
"testing"
"github.com/stretchr/testify/assert"
2023-01-24 12:03:05 +08:00
"github.com/zeromicro/go-zero/core/discov"
"github.com/zeromicro/go-zero/core/netx"
2021-02-17 21:42:22 +08:00
)
2023-01-24 12:03:05 +08:00
func TestNewRpcPubServer(t *testing.T) {
s, err := NewRpcPubServer(discov.EtcdConf{
User: "user",
Pass: "pass",
2023-03-11 14:57:56 +08:00
ID: 10,
}, "")
2023-01-24 12:03:05 +08:00
assert.NoError(t, err)
assert.NotPanics(t, func() {
s.Start(nil)
})
}
2021-02-17 21:42:22 +08:00
func TestFigureOutListenOn(t *testing.T) {
tests := []struct {
input string
expect string
}{
{
input: "192.168.0.5:1234",
expect: "192.168.0.5:1234",
},
{
input: "0.0.0.0:8080",
expect: netx.InternalIp() + ":8080",
},
{
input: ":8080",
expect: netx.InternalIp() + ":8080",
},
2023-01-24 12:03:05 +08:00
{
input: "",
expect: netx.InternalIp(),
},
2021-02-17 21:42:22 +08:00
}
for _, test := range tests {
val := figureOutListenOn(test.input)
assert.Equal(t, test.expect, val)
}
}