chore: add more tests (#3187)

This commit is contained in:
Kevin Wan
2023-04-29 22:59:07 +08:00
committed by GitHub
parent 14caf5c799
commit a31256b327
4 changed files with 42 additions and 1 deletions

View File

@@ -10,7 +10,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/discov"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/logx/logtest"
"github.com/zeromicro/go-zero/internal/mock"
"github.com/zeromicro/go-zero/rest/httpc"
"github.com/zeromicro/go-zero/zrpc"
@@ -51,6 +53,8 @@ func TestMustNewServer(t *testing.T) {
s := MustNewServer(c, withDialer(func(conf zrpc.RpcClientConf) zrpc.Client {
return zrpc.MustNewClient(conf, zrpc.WithDialOption(grpc.WithContextDialer(dialer())))
}), WithHeaderProcessor(func(header http.Header) []string {
return []string{"foo"}
}))
s.upstreams = []Upstream{
{
@@ -77,6 +81,7 @@ func TestMustNewServer(t *testing.T) {
assert.NoError(t, s.build())
go s.Server.Start()
defer s.Stop()
time.Sleep(time.Millisecond * 200)
@@ -103,3 +108,20 @@ func TestServer_ensureUpstreamNames(t *testing.T) {
assert.NoError(t, s.ensureUpstreamNames())
assert.Equal(t, "target", s.upstreams[0].Name)
}
func TestServer_ensureUpstreamNames_badEtcd(t *testing.T) {
var s = Server{
upstreams: []Upstream{
{
Grpc: zrpc.RpcClientConf{
Etcd: discov.EtcdConf{},
},
},
},
}
logtest.PanicOnFatal(t)
assert.Panics(t, func() {
s.Start()
})
}