Mock transport with pc frames#2008
Conversation
|
I've added the code generation to all methods now. Let me know your thoughts @gmlewis 👍 . |
Codecov Report
@@ Coverage Diff @@
## master #2008 +/- ##
==========================================
- Coverage 97.84% 97.44% -0.40%
==========================================
Files 105 108 +3
Lines 6809 6968 +159
==========================================
+ Hits 6662 6790 +128
- Misses 80 110 +30
- Partials 67 68 +1
Continue to review full report at Codecov.
|
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @migueleliasweb . I'm liking this approach.
You will also want to add a new generator to this PR here:
https://github.com/google/go-github/blob/master/github/github.go#L6-L7
|
|
||
| func MustMarshal(v interface{}) []byte { | ||
| b, err := json.Marshal(v) | ||
|
|
There was a problem hiding this comment.
Please remove this blank line.
| } | ||
| } | ||
|
|
||
| func NewMockHttpClient(options ...MockHttpClientOption) *http.Client { |
There was a problem hiding this comment.
Please add godoc comment.
| func NewMockHttpClient(options ...MockHttpClientOption) *http.Client { | |
| func NewMockHTTPClient(options ...MockHTTPClientOption) *http.Client { |
|
|
||
| type MockHttpClientOption func(*MockRoundTripper) | ||
|
|
||
| func WithRequestMatch( |
There was a problem hiding this comment.
Please add godoc comment.
|
|
||
| var _ http.RoundTripper = &MockRoundTripper{} | ||
|
|
||
| type MockHttpClientOption func(*MockRoundTripper) |
There was a problem hiding this comment.
Please add godoc comment.
| type MockHttpClientOption func(*MockRoundTripper) | |
| type MockHTTPClientOption func(*MockRoundTripper) |
| RequestMocks map[RequestMatch][][]byte | ||
| } | ||
|
|
||
| // RoundTrip implements http.RoundTripper interface |
There was a problem hiding this comment.
| // RoundTrip implements http.RoundTripper interface | |
| // RoundTrip implements http.RoundTripper interface. |
|
|
||
| if receiverType, ok := fn.Recv.List[0].Type.(*ast.StarExpr); ok { | ||
| if receiverTypeIndent, ok := receiverType.X.(*ast.Ident); ok { | ||
| if receiverTypeIndent.Name != "" { |
There was a problem hiding this comment.
This line can then be deleted if you take my suggestions above.
| if receiverTypeIndent.Name != "" { | ||
| varName := fmt.Sprintf( | ||
| "RequestMatch%s%s", | ||
| strings.Replace( |
There was a problem hiding this comment.
After the reduction in indentation above, this strings.Replace could all fit nicely on a single line.
| return requestMatches[i].Value < requestMatches[j].Value | ||
| }) | ||
|
|
||
| // fmt.Println("requestMatches:", requestMatches) |
There was a problem hiding this comment.
Please remove this debugging line.
|
|
||
| // fmt.Println("requestMatches:", requestMatches) | ||
|
|
||
| buf := bytes.NewBufferString("") |
There was a problem hiding this comment.
| buf := bytes.NewBufferString("") | |
| var buf bytes.Buffer |
| buf := bytes.NewBufferString("") | ||
|
|
||
| template.Must(template.New("source").Parse(source)).Execute( | ||
| buf, |
There was a problem hiding this comment.
| buf, | |
| &buf, |
|
After further consideration, I think that @willnorris is correct in his comment that this would be a great utility to place in an external helper repo. So my recommendation is that we close this PR and also close #1800 and point to a new helper repo in this repo's README.md once it has been implemented. |
An attempt to address #1800
runtime.Framesto get a the caller method in the SDK and use it to mock a response