rename method to endpoint
This commit is contained in:
		| @@ -16,7 +16,7 @@ var ( | ||||
| ) | ||||
|  | ||||
| type MockResponse struct { | ||||
| 	Method   string | ||||
| 	Endpoint string | ||||
| 	Response interface{} | ||||
| 	Error    error | ||||
| } | ||||
| @@ -54,8 +54,8 @@ func (m *MockClient) NewMessage(topic string, msg interface{}, opts ...client.Me | ||||
| 	return m.Client.NewMessage(topic, msg, opts...) | ||||
| } | ||||
|  | ||||
| func (m *MockClient) NewRequest(service, method string, req interface{}, reqOpts ...client.RequestOption) client.Request { | ||||
| 	return m.Client.NewRequest(service, method, req, reqOpts...) | ||||
| func (m *MockClient) NewRequest(service, endpoint string, req interface{}, reqOpts ...client.RequestOption) client.Request { | ||||
| 	return m.Client.NewRequest(service, endpoint, req, reqOpts...) | ||||
| } | ||||
|  | ||||
| func (m *MockClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { | ||||
| @@ -68,7 +68,7 @@ func (m *MockClient) Call(ctx context.Context, req client.Request, rsp interface | ||||
| 	} | ||||
|  | ||||
| 	for _, r := range response { | ||||
| 		if r.Method != req.Method() { | ||||
| 		if r.Endpoint != req.Endpoint() { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| @@ -91,7 +91,7 @@ func (m *MockClient) Call(ctx context.Context, req client.Request, rsp interface | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	return fmt.Errorf("rpc: can't find service %s", req.Method()) | ||||
| 	return fmt.Errorf("rpc: can't find service %s", req.Endpoint()) | ||||
| } | ||||
|  | ||||
| func (m *MockClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) { | ||||
|   | ||||
| @@ -13,17 +13,17 @@ func TestClient(t *testing.T) { | ||||
| 	} | ||||
|  | ||||
| 	response := []MockResponse{ | ||||
| 		{Method: "Foo.Bar", Response: map[string]interface{}{"foo": "bar"}}, | ||||
| 		{Method: "Foo.Struct", Response: &TestResponse{Param: "aparam"}}, | ||||
| 		{Method: "Foo.Fail", Error: errors.InternalServerError("go.mock", "failed")}, | ||||
| 		{Method: "Foo.Func", Response: func() string { return "string" }}, | ||||
| 		{Method: "Foo.FuncStruct", Response: func() *TestResponse { return &TestResponse{Param: "aparam"} }}, | ||||
| 		{Endpoint: "Foo.Bar", Response: map[string]interface{}{"foo": "bar"}}, | ||||
| 		{Endpoint: "Foo.Struct", Response: &TestResponse{Param: "aparam"}}, | ||||
| 		{Endpoint: "Foo.Fail", Error: errors.InternalServerError("go.mock", "failed")}, | ||||
| 		{Endpoint: "Foo.Func", Response: func() string { return "string" }}, | ||||
| 		{Endpoint: "Foo.FuncStruct", Response: func() *TestResponse { return &TestResponse{Param: "aparam"} }}, | ||||
| 	} | ||||
|  | ||||
| 	c := NewClient(Response("go.mock", response)) | ||||
|  | ||||
| 	for _, r := range response { | ||||
| 		req := c.NewRequest("go.mock", r.Method, map[string]interface{}{"foo": "bar"}) | ||||
| 		req := c.NewRequest("go.mock", r.Endpoint, map[string]interface{}{"foo": "bar"}) | ||||
| 		var rsp interface{} | ||||
|  | ||||
| 		err := c.Call(context.TODO(), req, &rsp) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user