yarpc / yarpc-go

A message passing platform for Go
MIT License
401 stars 101 forks source link

Fake clients and directly calling handlers #683

Closed abhinav closed 6 years ago

abhinav commented 7 years ago

Now that we put headers, etc. on context, we need to provide a way for users to build fake versions of these. That is, if I have a handler,

func getValue(ctx context.Context, req *GetValueRequest) (*GetValueResponse, error) {
    call := yarpc.CallFromContext(ctx)
    fmt.Println(call.Header("key"))
    if err := call.WriteResponseHeader("foo", "bar"); ... {
        ..
    }
    return ...
}

There needs to be a way to inject a context with fake request information so that this function is callable directly from a test. Similarly, we need to expose the response headers written to the context to the caller.

This is currently possible in a convoluted way with the use of encoding.NewInboundCall but we can do better.

Similarly, if I have a mock client (generated with mockgen), there needs to be a way to tell the mock client to expect specific request headers or return specific response headers. This too is possible with some convoluted use of encoding.NewOutboundCall but we can do better.

prashantv commented 7 years ago

+1, This makes it pretty hard to test any method that:

bufdev commented 6 years ago

Closing in favor of #1350