client_test.go 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package internal
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. "google.golang.org/grpc"
  8. )
  9. func TestWithDialOption(t *testing.T) {
  10. var options ClientOptions
  11. agent := grpc.WithUserAgent("chrome")
  12. opt := WithDialOption(agent)
  13. opt(&options)
  14. assert.Contains(t, options.DialOptions, agent)
  15. }
  16. func TestWithTimeout(t *testing.T) {
  17. var options ClientOptions
  18. opt := WithTimeout(time.Second)
  19. opt(&options)
  20. assert.Equal(t, time.Second, options.Timeout)
  21. }
  22. func TestWithUnaryClientInterceptor(t *testing.T) {
  23. var options ClientOptions
  24. opt := WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{},
  25. cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
  26. return nil
  27. })
  28. opt(&options)
  29. assert.Equal(t, 1, len(options.DialOptions))
  30. }
  31. func TestBuildDialOptions(t *testing.T) {
  32. var c client
  33. agent := grpc.WithUserAgent("chrome")
  34. opts := c.buildDialOptions(WithDialOption(agent))
  35. assert.Contains(t, opts, agent)
  36. }