add more tests
This commit is contained in:
47
rpcx/internal/chainclientinterceptors_test.go
Normal file
47
rpcx/internal/chainclientinterceptors_test.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync/atomic"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWithStreamClientInterceptors(t *testing.T) {
|
||||||
|
opts := WithStreamClientInterceptors()
|
||||||
|
assert.NotNil(t, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWithUnaryClientInterceptors(t *testing.T) {
|
||||||
|
opts := WithUnaryClientInterceptors()
|
||||||
|
assert.NotNil(t, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChainStreamClientInterceptors_zero(t *testing.T) {
|
||||||
|
interceptors := chainStreamClientInterceptors()
|
||||||
|
_, err := interceptors(context.Background(), nil, new(grpc.ClientConn), "/foo",
|
||||||
|
func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string,
|
||||||
|
opts ...grpc.CallOption) (grpc.ClientStream, error) {
|
||||||
|
return nil, nil
|
||||||
|
})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChainStreamClientInterceptors_one(t *testing.T) {
|
||||||
|
var called int32
|
||||||
|
interceptors := chainStreamClientInterceptors(func(ctx context.Context, desc *grpc.StreamDesc,
|
||||||
|
cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (
|
||||||
|
grpc.ClientStream, error) {
|
||||||
|
atomic.AddInt32(&called, 1)
|
||||||
|
return nil, nil
|
||||||
|
})
|
||||||
|
_, err := interceptors(context.Background(), nil, new(grpc.ClientConn), "/foo",
|
||||||
|
func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string,
|
||||||
|
opts ...grpc.CallOption) (grpc.ClientStream, error) {
|
||||||
|
return nil, nil
|
||||||
|
})
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, int32(1), atomic.LoadInt32(&called))
|
||||||
|
}
|
||||||
@@ -9,10 +9,10 @@ import (
|
|||||||
|
|
||||||
func BuildDirectTarget(endpoints []string) string {
|
func BuildDirectTarget(endpoints []string) string {
|
||||||
return fmt.Sprintf("%s:///%s", resolver.DirectScheme, strings.Join(
|
return fmt.Sprintf("%s:///%s", resolver.DirectScheme, strings.Join(
|
||||||
endpoints, fmt.Sprint(resolver.EndpointSep)))
|
endpoints, fmt.Sprintf("%c", resolver.EndpointSep)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildDiscovTarget(endpoints []string, key string) string {
|
func BuildDiscovTarget(endpoints []string, key string) string {
|
||||||
return fmt.Sprintf("%s://%s/%s", resolver.DiscovScheme, strings.Join(
|
return fmt.Sprintf("%s://%s/%s", resolver.DiscovScheme, strings.Join(
|
||||||
endpoints, fmt.Sprint(resolver.EndpointSep)), key)
|
endpoints, fmt.Sprintf("%c", resolver.EndpointSep)), key)
|
||||||
}
|
}
|
||||||
|
|||||||
17
rpcx/internal/target_test.go
Normal file
17
rpcx/internal/target_test.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBuildDirectTarget(t *testing.T) {
|
||||||
|
target := BuildDirectTarget([]string{"localhost:123", "localhost:456"})
|
||||||
|
assert.Equal(t, "direct:///localhost:123,localhost:456", target)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildDiscovTarget(t *testing.T) {
|
||||||
|
target := BuildDiscovTarget([]string{"localhost:123", "localhost:456"}, "foo")
|
||||||
|
assert.Equal(t, "discov://localhost:123,localhost:456/foo", target)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user