(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func (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. |
nothing calls this directly
no test coverage detected