chore: add more tests (#2812)

* chore: add more tests

* chore: add more tests
master
Kevin Wan 2 years ago committed by GitHub
parent f3369f8e81
commit 4bd8025c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,10 +10,35 @@ import (
) )
func TestRpcClientConf(t *testing.T) { func TestRpcClientConf(t *testing.T) {
conf := NewDirectClientConf([]string{"localhost:1234"}, "foo", "bar") t.Run("direct", func(t *testing.T) {
assert.True(t, conf.HasCredential()) conf := NewDirectClientConf([]string{"localhost:1234"}, "foo", "bar")
conf = NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"}, "key", "foo", "bar") assert.True(t, conf.HasCredential())
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) { func TestRpcServerConf(t *testing.T) {

@ -48,5 +48,6 @@ func ParseTarget(target resolver.Target) (Service, error) {
} else { } else {
service.Name = endpoints service.Name = endpoints
} }
return service, nil return service, nil
} }

@ -18,6 +18,15 @@ func TestKubeBuilder_Build(t *testing.T) {
var b kubeBuilder var b kubeBuilder
u, err := url.Parse(fmt.Sprintf("%s://%s", KubernetesScheme, "a,b")) u, err := url.Parse(fmt.Sprintf("%s://%s", KubernetesScheme, "a,b"))
assert.NoError(t, err) 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{ _, err = b.Build(resolver.Target{
URL: *u, URL: *u,
}, nil, resolver.BuildOptions{}) }, nil, resolver.BuildOptions{})

@ -3,15 +3,19 @@ package internal
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/resolver" "google.golang.org/grpc/resolver"
"google.golang.org/grpc/serviceconfig" "google.golang.org/grpc/serviceconfig"
) )
func TestNopResolver(t *testing.T) { func TestNopResolver(t *testing.T) {
// make sure ResolveNow & Close don't panic assert.NotPanics(t, func() {
var r nopResolver RegisterResolver()
r.ResolveNow(resolver.ResolveNowOptions{}) // make sure ResolveNow & Close don't panic
r.Close() var r nopResolver
r.ResolveNow(resolver.ResolveNowOptions{})
r.Close()
})
} }
type mockedClientConn struct { type mockedClientConn struct {

Loading…
Cancel
Save