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

Function TestResolver

resolver/manual/manual_test.go:31–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestResolver(t *testing.T) {
32 r := manual.NewBuilderWithScheme("whatever")
33 r.InitialState(resolver.State{
34 Addresses: []resolver.Address{
35 {Addr: "address"},
36 },
37 })
38
39 t.Run("cc_panics", func(t *testing.T) {
40 defer func() {
41 want := "Manual resolver instance has not yet been built."
42 if r := recover(); r != want {
43 t.Errorf("expected panic %q, got %q", want, r)
44 }
45 }()
46 r.CC()
47 })
48
49 t.Run("happy_path", func(t *testing.T) {
50 cc, err := grpc.NewClient("whatever://localhost",
51 grpc.WithTransportCredentials(insecure.NewCredentials()),
52 grpc.WithResolvers(r))
53 if err != nil {
54 t.Errorf("grpc.NewClient() failed: %v", err)
55 }
56 defer cc.Close()
57 cc.Connect()
58 r.UpdateState(resolver.State{Addresses: []resolver.Address{
59 {Addr: "ok"},
60 }})
61 r.CC().ReportError(errors.New("example"))
62 })
63}

Callers

nothing calls this directly

Calls 12

NewBuilderWithSchemeFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92
InitialStateMethod · 0.80
CCMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.65
ConnectMethod · 0.65
UpdateStateMethod · 0.65
ReportErrorMethod · 0.65

Tested by

no test coverage detected