MCPcopy
hub / github.com/micro/go-micro / TestCallWrapper

Function TestCallWrapper

client/rpc_client_test.go:114–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestCallWrapper(t *testing.T) {
115 var called bool
116 id := "test.1"
117 service := "test.service"
118 endpoint := "Test.Endpoint"
119 address := "10.1.10.1:8080"
120
121 wrap := func(cf CallFunc) CallFunc {
122 return func(_ context.Context, node *registry.Node, req Request, _ interface{}, _ CallOptions) error {
123 called = true
124
125 if req.Service() != service {
126 return fmt.Errorf("expected service: %s got %s", service, req.Service())
127 }
128
129 if req.Endpoint() != endpoint {
130 return fmt.Errorf("expected service: %s got %s", endpoint, req.Endpoint())
131 }
132
133 if node.Address != address {
134 return fmt.Errorf("expected address: %s got %s", address, node.Address)
135 }
136
137 // don't do the call
138 return nil
139 }
140 }
141
142 r := newTestRegistry()
143 c := NewClient(
144 Registry(r),
145 WrapCall(wrap),
146 )
147
148 if err := c.Options().Selector.Init(selector.Registry(r)); err != nil {
149 t.Fatal("failed to initialize selector", err)
150 }
151
152 err := r.Register(&registry.Service{
153 Name: service,
154 Version: "latest",
155 Nodes: []*registry.Node{
156 {
157 Id: id,
158 Address: address,
159 Metadata: map[string]string{
160 "protocol": "mucp",
161 },
162 },
163 },
164 })
165 if err != nil {
166 t.Fatal("failed to register service", err)
167 }
168
169 req := c.NewRequest(service, endpoint, nil)
170 if err := c.Call(context.Background(), req, nil); err != nil {
171 t.Fatal("call wrapper error", err)

Callers

nothing calls this directly

Calls 14

ServiceMethod · 0.95
EndpointMethod · 0.95
OptionsMethod · 0.95
NewRequestMethod · 0.95
CallMethod · 0.95
RegistryFunction · 0.92
FatalMethod · 0.80
newTestRegistryFunction · 0.70
RegistryFunction · 0.70
WrapCallFunction · 0.70
InitMethod · 0.65
RegisterMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…