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

Function setupDNS

internal/xds/balancer/cdsbalancer/cdsbalancer_test.go:175–186  ·  view source on GitHub ↗

setupDNS unregisters the DNS resolver and registers a manual resolver for the same scheme. This allows the test to fake the DNS resolution by supplying the addresses of the test backends. Returns the following: - a channel onto which the DNS target being resolved is written to by the fake DNS resol

(t *testing.T)

Source from the content-addressed store, hash-verified

173// fake DNS resolver
174// - a manual resolver which is used to fake the actual DNS resolution
175func setupDNS(t *testing.T) (chan resolver.Target, *manual.Resolver) {
176 targetCh := make(chan resolver.Target, 1)
177
178 mr := manual.NewBuilderWithScheme("dns")
179 mr.BuildCallback = func(target resolver.Target, _ resolver.ClientConn, _ resolver.BuildOptions) { targetCh <- target }
180
181 dnsResolverBuilder := resolver.Get("dns")
182 resolver.Register(mr)
183
184 t.Cleanup(func() { resolver.Register(dnsResolverBuilder) })
185 return targetCh, mr
186}
187
188// Performs the following setup required for tests:
189// - Spins up an xDS management server and the provided onStreamRequest

Calls 2

NewBuilderWithSchemeFunction · 0.92
GetMethod · 0.65

Tested by

no test coverage detected