Check that FromEnvironmentUsing uses our dialer.
(t *testing.T)
| 125 | |
| 126 | // Check that FromEnvironmentUsing uses our dialer. |
| 127 | func TestFromEnvironmentUsing(t *testing.T) { |
| 128 | ResetProxyEnv() |
| 129 | errFoo := errors.New("some error to check our dialer was used)") |
| 130 | type key string |
| 131 | ctx := context.WithValue(context.Background(), key("foo"), "bar") |
| 132 | dialer := FromEnvironmentUsing(funcFailDialer(func(ctx context.Context) error { |
| 133 | if got := ctx.Value(key("foo")); got != "bar" { |
| 134 | t.Errorf("Resolver context = %T %v, want %q", got, got, "bar") |
| 135 | } |
| 136 | return errFoo |
| 137 | })) |
| 138 | _, err := dialer.(ContextDialer).DialContext(ctx, "tcp", "foo.tld:123") |
| 139 | if err == nil { |
| 140 | t.Fatalf("unexpected success") |
| 141 | } |
| 142 | if !strings.Contains(err.Error(), errFoo.Error()) { |
| 143 | t.Errorf("got unexpected error %q; want substr %q", err, errFoo) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | func ResetProxyEnv() { |
| 148 | for _, env := range []*envOnce{allProxyEnv, noProxyEnv} { |
nothing calls this directly
no test coverage detected
searching dependent graphs…