MCPcopy
hub / github.com/grpc/grpc-go / TestAddGlobalDialOptions

Method TestAddGlobalDialOptions

default_dial_option_server_option_test.go:31–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func (s) TestAddGlobalDialOptions(t *testing.T) {
32 // Ensure the NewClient fails without credentials
33 if _, err := NewClient("fake"); err == nil {
34 t.Fatalf("NewClient without a credential did not fail")
35 } else {
36 if !strings.Contains(err.Error(), "no transport security set") {
37 t.Fatalf("NewClient failed with unexpected error: %v", err)
38 }
39 }
40
41 // Set and check the DialOptions
42 opts := []DialOption{WithTransportCredentials(insecure.NewCredentials()), WithTransportCredentials(insecure.NewCredentials()), WithTransportCredentials(insecure.NewCredentials())}
43 internal.AddGlobalDialOptions.(func(opt ...DialOption))(opts...)
44 defer internal.ClearGlobalDialOptions()
45 for i, opt := range opts {
46 if globalDialOptions[i] != opt {
47 t.Fatalf("Unexpected global dial option at index %d: %v != %v", i, globalDialOptions[i], opt)
48 }
49 }
50
51 // Ensure the NewClient passes with the extra dial options
52 if cc, err := NewClient("fake"); err != nil {
53 t.Fatalf("NewClient with insecure credential failed: %v", err)
54 } else {
55 cc.Close()
56 }
57
58 internal.ClearGlobalDialOptions()
59 if len(globalDialOptions) != 0 {
60 t.Fatalf("Unexpected len of globalDialOptions: %d != 0", len(globalDialOptions))
61 }
62}
63
64// TestDisableGlobalOptions tests dialing with the disableGlobalDialOptions dial
65// option. Dialing with this set should not pick up global options.

Callers

nothing calls this directly

Calls 6

NewCredentialsFunction · 0.92
WithTransportCredentialsFunction · 0.85
NewClientFunction · 0.70
FatalfMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected