durationinterceptor_test.go 711 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package clientinterceptors
  2. import (
  3. "context"
  4. "errors"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "google.golang.org/grpc"
  8. )
  9. func TestDurationInterceptor(t *testing.T) {
  10. tests := []struct {
  11. name string
  12. err error
  13. }{
  14. {
  15. name: "nil",
  16. err: nil,
  17. },
  18. {
  19. name: "with error",
  20. err: errors.New("mock"),
  21. },
  22. }
  23. for _, test := range tests {
  24. t.Run(test.name, func(t *testing.T) {
  25. cc := new(grpc.ClientConn)
  26. err := DurationInterceptor(context.Background(), "/foo", nil, nil, cc,
  27. func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
  28. opts ...grpc.CallOption) error {
  29. return test.err
  30. })
  31. assert.Equal(t, test.err, err)
  32. })
  33. }
  34. }