(t *testing.T)
| 48 | } |
| 49 | |
| 50 | func (s) TestResolverCaseSensitivity(t *testing.T) { |
| 51 | // This should find the "casetest" resolver instead of the "caseTest" |
| 52 | // resolver, even though the latter was registered later. "casetest" is |
| 53 | // "passthrough" and "caseTest" is "dns". With "passthrough" the dialer |
| 54 | // should see the target's address directly, but "dns" would be converted |
| 55 | // into a loopback IP (v4 or v6) address. |
| 56 | target := "caseTest:///localhost:1234" |
| 57 | addrCh := make(chan string, 1) |
| 58 | customDialer := func(_ context.Context, addr string) (net.Conn, error) { |
| 59 | select { |
| 60 | case addrCh <- addr: |
| 61 | default: |
| 62 | } |
| 63 | return nil, fmt.Errorf("not dialing with custom dialer") |
| 64 | } |
| 65 | |
| 66 | cc, err := NewClient(target, WithContextDialer(customDialer), WithTransportCredentials(insecure.NewCredentials())) |
| 67 | if err != nil { |
| 68 | t.Fatalf("Unexpected NewClient(%q) error: %v", target, err) |
| 69 | } |
| 70 | cc.Connect() |
| 71 | if got, want := <-addrCh, "localhost:1234"; got != want { |
| 72 | cc.Close() |
| 73 | t.Fatalf("Dialer got address %q; wanted %q", got, want) |
| 74 | } |
| 75 | cc.Close() |
| 76 | |
| 77 | // Clear addrCh for future use. |
| 78 | select { |
| 79 | case <-addrCh: |
| 80 | default: |
| 81 | } |
| 82 | |
| 83 | res := &wrapResolverBuilder{Builder: resolver.Get("dns"), scheme: "caseTest2"} |
| 84 | // This should not find the injected resolver due to the case not matching. |
| 85 | // This results in "passthrough" being used with the address as the whole |
| 86 | // target. |
| 87 | target = "caseTest2:///localhost:1234" |
| 88 | cc, err = NewClient(target, WithContextDialer(customDialer), withDefaultScheme("passthrough"), WithResolvers(res), WithTransportCredentials(insecure.NewCredentials())) |
| 89 | if err != nil { |
| 90 | t.Fatalf("Unexpected NewClient(%q) error: %v", target, err) |
| 91 | } |
| 92 | cc.Connect() |
| 93 | if got, want := <-addrCh, target; got != want { |
| 94 | cc.Close() |
| 95 | t.Fatalf("Dialer got address %q; wanted %q", got, want) |
| 96 | } |
| 97 | cc.Close() |
| 98 | } |
| 99 | |
| 100 | // TestResolverAddressesToEndpoints ensures one Endpoint is created for each |
| 101 | // entry in resolver.State.Addresses automatically. |
nothing calls this directly
no test coverage detected