mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 00:50:20 +08:00
chore: add more tests (#2812)
* chore: add more tests * chore: add more tests
This commit is contained in:
parent
f3369f8e81
commit
4bd8025c5b
@ -10,10 +10,35 @@ import (
|
||||
)
|
||||
|
||||
func TestRpcClientConf(t *testing.T) {
|
||||
conf := NewDirectClientConf([]string{"localhost:1234"}, "foo", "bar")
|
||||
assert.True(t, conf.HasCredential())
|
||||
conf = NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"}, "key", "foo", "bar")
|
||||
assert.True(t, conf.HasCredential())
|
||||
t.Run("direct", func(t *testing.T) {
|
||||
conf := NewDirectClientConf([]string{"localhost:1234"}, "foo", "bar")
|
||||
assert.True(t, conf.HasCredential())
|
||||
})
|
||||
|
||||
t.Run("etcd", func(t *testing.T) {
|
||||
conf := NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"},
|
||||
"key", "foo", "bar")
|
||||
assert.True(t, conf.HasCredential())
|
||||
})
|
||||
|
||||
t.Run("etcd with account", func(t *testing.T) {
|
||||
conf := NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"},
|
||||
"key", "foo", "bar")
|
||||
conf.Etcd.User = "user"
|
||||
conf.Etcd.Pass = "pass"
|
||||
_, err := conf.BuildTarget()
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("etcd with tls", func(t *testing.T) {
|
||||
conf := NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"},
|
||||
"key", "foo", "bar")
|
||||
conf.Etcd.CertFile = "cert"
|
||||
conf.Etcd.CertKeyFile = "key"
|
||||
conf.Etcd.CACertFile = "ca"
|
||||
_, err := conf.BuildTarget()
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRpcServerConf(t *testing.T) {
|
||||
|
@ -48,5 +48,6 @@ func ParseTarget(target resolver.Target) (Service, error) {
|
||||
} else {
|
||||
service.Name = endpoints
|
||||
}
|
||||
|
||||
return service, nil
|
||||
}
|
||||
|
@ -18,6 +18,15 @@ func TestKubeBuilder_Build(t *testing.T) {
|
||||
var b kubeBuilder
|
||||
u, err := url.Parse(fmt.Sprintf("%s://%s", KubernetesScheme, "a,b"))
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = b.Build(resolver.Target{
|
||||
URL: *u,
|
||||
}, nil, resolver.BuildOptions{})
|
||||
assert.Error(t, err)
|
||||
|
||||
u, err = url.Parse(fmt.Sprintf("%s://%s:9100/a:b:c", KubernetesScheme, "a,b,c,d"))
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = b.Build(resolver.Target{
|
||||
URL: *u,
|
||||
}, nil, resolver.BuildOptions{})
|
||||
|
@ -3,15 +3,19 @@ package internal
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/grpc/resolver"
|
||||
"google.golang.org/grpc/serviceconfig"
|
||||
)
|
||||
|
||||
func TestNopResolver(t *testing.T) {
|
||||
// make sure ResolveNow & Close don't panic
|
||||
var r nopResolver
|
||||
r.ResolveNow(resolver.ResolveNowOptions{})
|
||||
r.Close()
|
||||
assert.NotPanics(t, func() {
|
||||
RegisterResolver()
|
||||
// make sure ResolveNow & Close don't panic
|
||||
var r nopResolver
|
||||
r.ResolveNow(resolver.ResolveNowOptions{})
|
||||
r.Close()
|
||||
})
|
||||
}
|
||||
|
||||
type mockedClientConn struct {
|
||||
|
Loading…
Reference in New Issue
Block a user