See the details here: https://github.com/AdguardTeam/dnsproxy/issues/18
(t *testing.T)
| 50 | |
| 51 | // See the details here: https://github.com/AdguardTeam/dnsproxy/issues/18 |
| 52 | func TestResolveDialContext(t *testing.T) { |
| 53 | sig := make(chan net.Addr, 1) |
| 54 | |
| 55 | ipp := newListener(t, "tcp", sig) |
| 56 | port := ipp.Port() |
| 57 | |
| 58 | l := slogutil.NewDiscardLogger() |
| 59 | |
| 60 | testCases := []struct { |
| 61 | name string |
| 62 | addresses []netip.Addr |
| 63 | preferIPv6 bool |
| 64 | }{{ |
| 65 | name: "v4", |
| 66 | addresses: []netip.Addr{netutil.IPv4Localhost()}, |
| 67 | preferIPv6: false, |
| 68 | }, { |
| 69 | name: "both_prefer_v6", |
| 70 | addresses: []netip.Addr{netutil.IPv4Localhost(), netutil.IPv6Localhost()}, |
| 71 | preferIPv6: true, |
| 72 | }, { |
| 73 | name: "both_prefer_v4", |
| 74 | addresses: []netip.Addr{netutil.IPv6Localhost(), netutil.IPv4Localhost()}, |
| 75 | preferIPv6: false, |
| 76 | }, { |
| 77 | name: "strip_invalid", |
| 78 | addresses: []netip.Addr{{}, netutil.IPv4Localhost(), {}, netutil.IPv6Localhost(), {}}, |
| 79 | preferIPv6: true, |
| 80 | }} |
| 81 | |
| 82 | const hostname = "host.name" |
| 83 | |
| 84 | pt := testutil.PanicT{} |
| 85 | |
| 86 | for _, tc := range testCases { |
| 87 | r := &testResolver{ |
| 88 | onLookupNetIP: func( |
| 89 | _ context.Context, |
| 90 | network string, |
| 91 | host string, |
| 92 | ) (addrs []netip.Addr, err error) { |
| 93 | require.Equal(pt, bootstrap.NetworkIP, network) |
| 94 | require.Equal(pt, hostname, host) |
| 95 | |
| 96 | return tc.addresses, nil |
| 97 | }, |
| 98 | } |
| 99 | |
| 100 | t.Run(tc.name, func(t *testing.T) { |
| 101 | dialContext, err := bootstrap.ResolveDialContext( |
| 102 | &url.URL{Host: netutil.JoinHostPort(hostname, port)}, |
| 103 | testTimeout, |
| 104 | bootstrap.ParallelResolver{r}, |
| 105 | tc.preferIPv6, |
| 106 | l, |
| 107 | ) |
| 108 | require.NoError(t, err) |
| 109 |
nothing calls this directly
no test coverage detected
searching dependent graphs…