Skip to content
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

Fix issue with RequestURI that arises in tests #121

Conversation

giovannibonetti-work
Copy link

Describe the PR
Although RequestURI and the URL field are supposed to be the same, sometimes they are inconsistent:
"RequestURI is the unmodified request-target of the Request-Line (RFC 7230, Section 3.1.1) as sent by the client to a server. Usually the URL field should be used instead."

When running automated tests with http.NewRequest from net/http, the RequestURI field is unfortunately not set. Hence, by replacing RequestURI by the path field we fix those issues.

Relation issue
#99, golang/go#12613

Additional context
The way it is, when running tests with http.NewRequest, the following panic occurs:

--- FAIL: TestSwaggerRouter (0.00s)
    --- FAIL: TestSwaggerRouter/Allows_access_with_correct_Basic_Auth (0.00s)
panic: runtime error: index out of range [2] with length 0 [recovered]
	panic: runtime error: index out of range [2] with length 0

goroutine 56 [running]:
testing.tRunner.func1.2({0x1042e03c0, 0x14000056c60})
	.../go/src/testing/testing.go:1632 +0x1bc
testing.tRunner.func1()
	.../go/src/testing/testing.go:1635 +0x334
panic({0x1042e03c0?, 0x14000056c60?})
	.../go/src/runtime/panic.go:785 +0x124
github.com/swaggo/http-swagger/v2.Handler.func1({0x1043e6ae8, 0x1400090e5c0}, 0x14000926500)
	.../go/pkg/mod/github.com/swaggo/http-swagger/[email protected]/swagger.go:186 +0x798
net/http.HandlerFunc.ServeHTTP(0x14000891560?, {0x1043e6ae8?, 0x1400090e5c0?}, 0x10357fcef?)

@ubogdan
Copy link
Contributor

ubogdan commented Oct 21, 2024

Not sure why is crashing on your end but we are using http.NewRequest also to test the code.

I can't approve a change that doesn't pass the unit tests.
I want to see an additional test that proves you fixed that panic.

@WhatsApp-Platform WhatsApp-Platform closed this by deleting the head repository Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants