فهرست منبع

add more tests

kevin 4 سال پیش
والد
کامیت
5989444227

+ 3 - 2
.codecov.yml

@@ -1,3 +1,4 @@
 ignore:
-  - "example/*"
-  - "tools/*"
+  - "doc"
+  - "example"
+  - "tools"

+ 30 - 0
rpcx/internal/clientinterceptors/breakerinterceptor_test.go

@@ -1,12 +1,15 @@
 package clientinterceptors
 
 import (
+	"context"
+	"errors"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
 	"github.com/tal-tech/go-zero/core/breaker"
 	"github.com/tal-tech/go-zero/core/stat"
 	rcodes "github.com/tal-tech/go-zero/rpcx/internal/codes"
+	"google.golang.org/grpc"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
 )
@@ -49,3 +52,30 @@ func TestBreakerInterceptorDeadlineExceeded(t *testing.T) {
 	assert.True(t, errs[err] > 0)
 	assert.True(t, errs[breaker.ErrServiceUnavailable] > 0)
 }
+
+func TestBreakerInterceptor(t *testing.T) {
+	tests := []struct {
+		name string
+		err  error
+	}{
+		{
+			name: "nil",
+			err:  nil,
+		},
+		{
+			name: "with error",
+			err:  errors.New("mock"),
+		},
+	}
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			cc := new(grpc.ClientConn)
+			err := BreakerInterceptor(context.Background(), "/foo", nil, nil, cc,
+				func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
+					opts ...grpc.CallOption) error {
+					return test.err
+				})
+			assert.Equal(t, test.err, err)
+		})
+	}
+}

+ 37 - 0
rpcx/internal/clientinterceptors/durationinterceptor_test.go

@@ -0,0 +1,37 @@
+package clientinterceptors
+
+import (
+	"context"
+	"errors"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"google.golang.org/grpc"
+)
+
+func TestDurationInterceptor(t *testing.T) {
+	tests := []struct {
+		name string
+		err  error
+	}{
+		{
+			name: "nil",
+			err:  nil,
+		},
+		{
+			name: "with error",
+			err:  errors.New("mock"),
+		},
+	}
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			cc := new(grpc.ClientConn)
+			err := DurationInterceptor(context.Background(), "/foo", nil, nil, cc,
+				func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
+					opts ...grpc.CallOption) error {
+					return test.err
+				})
+			assert.Equal(t, test.err, err)
+		})
+	}
+}

+ 37 - 0
rpcx/internal/clientinterceptors/prommetricinterceptor_test.go

@@ -0,0 +1,37 @@
+package clientinterceptors
+
+import (
+	"context"
+	"errors"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"google.golang.org/grpc"
+)
+
+func TestPromMetricInterceptor(t *testing.T) {
+	tests := []struct {
+		name string
+		err  error
+	}{
+		{
+			name: "nil",
+			err:  nil,
+		},
+		{
+			name: "with error",
+			err:  errors.New("mock"),
+		},
+	}
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			cc := new(grpc.ClientConn)
+			err := PromMetricInterceptor(context.Background(), "/foo", nil, nil, cc,
+				func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
+					opts ...grpc.CallOption) error {
+					return test.err
+				})
+			assert.Equal(t, test.err, err)
+		})
+	}
+}