-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contrib/gin-gonic: add option to ignore request #1061
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just a few nits.
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
r := httptest.NewRequest("GET", "http://localhost"+test.url, nil) | ||
w := httptest.NewRecorder() | ||
|
||
router.ServeHTTP(w, r) | ||
|
||
spans := mt.FinishedSpans() | ||
assert.Equal(t, test.spanCount, len(spans)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mt := mocktracer.Start() | |
defer mt.Stop() | |
r := httptest.NewRequest("GET", "http://localhost"+test.url, nil) | |
w := httptest.NewRecorder() | |
router.ServeHTTP(w, r) | |
spans := mt.FinishedSpans() | |
assert.Equal(t, test.spanCount, len(spans)) | |
mt := mocktracer.Start() | |
defer mt.Reset() | |
r := httptest.NewRequest("GET", "http://localhost"+test.url, nil) | |
router.ServeHTTP(httptest.NewRecorder(), r) | |
assert.Equal(t, test.spanCount, len(mt.FinishedSpans())) |
No need to create variables that are not used. Also, we can use Reset
instead of Stop
, on the mocktracer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, addressed in latest commit.
c.Writer.Write([]byte("Skip")) | ||
}) | ||
|
||
for _, test := range tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer it if we didn't create the tests
variable. There is no need for it, it's not used in more than one place. You can just inline all the tests. If you like (up to you), it could also be a map:
for _, test := range tests { | |
for path, count := range map[string]int{ | |
"/OK": 1, | |
// ... | |
} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can add a field called expectedToSkip bool
(to represent a table driven tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you can meet both the suggested requirements by doing something like this:
for path, shouldSkip := range map[string]bool{
"/OK": false,
// ...
} {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, made the change 👍
Co-authored-by: Gabriel Aszalos <gabriel.aszalos@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful! Thank you!
This PR add's an option to ignore requests for contrib/gin-gonic.
Fixes: #1060