-
Notifications
You must be signed in to change notification settings - Fork 472
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
added redirect tests for core redirect features #1556
added redirect tests for core redirect features #1556
Conversation
Welcome @LiorLieberman! |
Hi @LiorLieberman. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This is a draft working implementation to check core features for redirect. As per #1496 I think that we should add a roundTripper under Perhaps we should continue with this lean implementation and amend accordingly once #1496 is finished? a few more nits; |
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.
Thanks @LiorLieberman, this LGTM, just a few minor nits.
@@ -153,3 +179,14 @@ func formatDump(data []byte, prefix string) string { | |||
data = startLineRegex.ReplaceAllLiteral(data, []byte(prefix)) | |||
return string(data) | |||
} | |||
|
|||
func IsRedirect(statusCode int) bool { | |||
// Gateway allows only 301, and 302 |
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.
Even though we only allow 301 and 302, I'd make this logic more future-proof to include the full set of redirect codes. There's a chance we'll add more in the future, but even if not, it will be more helpful to show a more useful error message than if we didn't capture the redirect info.
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 you elaborate? my thought was to put it in a function so we will have a one central place for adding more codes in the future. I think now we want to fail conformance if someone returns something other than 301/302 because we do not support it, correct?
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.
Let's say an implementation is actually returning a 307 or 308. With the current code, we wouldn't actually populate the rest of the redirect info for the rest of the test logic, so it would just look like everything failed instead of just having the wrong status code set.
I think the IsRedirect
function is primarily a check on if we should populate the new redirect struct. The roundtripper itself should not care about what is conformant or not, just in making sure it populates as much information as possible so the tests can determine if the response was conformant.
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.
Thats a good point, however we do check for wrong status code
gateway-api/conformance/utils/http/http.go
Lines 194 to 196 in c1c4952
if expected.Response.StatusCode != cRes.StatusCode { | |
return fmt.Errorf("expected status code to be %d, got %d", expected.Response.StatusCode, cRes.StatusCode) | |
} |
I agree the roundtripper should not care about conformance, would you prefer to construct the redirect struct always? Whats the value you think it'll give us? it wont change the behavior of the above lines - we will have a failure with a wrong status code still.
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 think we should always construct the redirect struct for any 3xx status code. Although the test will still fail, it will likely provide more useful information to the person debugging the test. Instead of simply knowing the code is wrong, they'll also be able to see if the location they are redirecting to has any issues.
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.
Makes sense, I have added all the codes but if you prefer I will do something like this instead let me know
func IsRedirect(statusCode int) bool {
switch {
case statusCode >= 300 && statusCode < 400:
return true
}
return false
}
/ok-to-test |
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.
+1 to Rob's comments but they appear to be resolved already.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: LiorLieberman, shaneutt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
🤔 looks like @k8s-ci-robot got stuck on the LGTM, adding another. /lgtm |
What type of PR is this?
/kind feature
/area conformance
What this PR does / why we need it:
Add tests for core redirect features
Which issue(s) this PR fixes:
Issue #1103
Does this PR introduce a user-facing change?:
NONE