diff --git a/zrpc/config_test.go b/zrpc/config_test.go index 02a3a10d..0f7a637e 100644 --- a/zrpc/config_test.go +++ b/zrpc/config_test.go @@ -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) { diff --git a/zrpc/resolver/internal/kube/targetparser.go b/zrpc/resolver/internal/kube/targetparser.go index d74cfba3..811cae2e 100644 --- a/zrpc/resolver/internal/kube/targetparser.go +++ b/zrpc/resolver/internal/kube/targetparser.go @@ -48,5 +48,6 @@ func ParseTarget(target resolver.Target) (Service, error) { } else { service.Name = endpoints } + return service, nil } diff --git a/zrpc/resolver/internal/kubebuilder_test.go b/zrpc/resolver/internal/kubebuilder_test.go index 38a663d9..bc9750dd 100644 --- a/zrpc/resolver/internal/kubebuilder_test.go +++ b/zrpc/resolver/internal/kubebuilder_test.go @@ -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{}) diff --git a/zrpc/resolver/internal/resolver_test.go b/zrpc/resolver/internal/resolver_test.go index 2f4a4690..62c82387 100644 --- a/zrpc/resolver/internal/resolver_test.go +++ b/zrpc/resolver/internal/resolver_test.go @@ -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 {