Skip to content

containerinfra: Fix wrong HTTP method and path in certificate create test - #3946

Merged
mandre merged 1 commit into
gophercloud:mainfrom
shiftstack:fix-containerinfra-test
Aug 17, 2026
Merged

mandre merged 1 commit into
gophercloud:mainfrom
shiftstack:fix-containerinfra-test

Conversation

@stephenfin

@stephenfin stephenfin commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

The HandleCreateCertificateSuccessfully fixture registered its handler at /v1/certificates/ (with trailing slash) and asserted the request method was GET, but certificates.Create issues a POST to /v1/certificates (without trailing slash).

This worked by accident prior to Go 1.26: the ServeMux redirected requests from /v1/certificates to /v1/certificates/ via 301, and Go's HTTP client changed POST to GET when following a 301 redirect. Go 1.26 changed these trailing-slash redirects to use 307 instead, which preserves the original method, so POST now arrives at the handler unchanged and the incorrect assertion fails.

Fix by matching the actual URL (/v1/certificates, no trailing slash) and asserting the correct method (POST).

Fixes #3898

@github-actions github-actions Bot added edit:containerinfra This PR updates containerinfra code semver:patch No API change backport-v2 This PR will be backported to v2 labels Aug 14, 2026
@coveralls

coveralls commented Aug 14, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 63.544%. remained the same — shiftstack:fix-containerinfra-test into gophercloud:main

@stephenfin

stephenfin commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

This worked by accident prior to Go 1.22: the old http.ServeMux redirected requests from /v1/certificates to /v1/certificates/ via 301, and Go's HTTP client changed POST to GET when following the redirect. The Go 1.22 enhanced ServeMux routes the request directly to the subtree handler without a redirect, so POST arrives unchanged and the assertion fails.

I think this analysis is wrong. go 1.22 is pretty old at this point. The test is clearly broken though, and it fails reliably in my environment. It might be more likely that this test is simply not running in CI?

Later: Hmm, no, the test is running here alright 😕 From the latest run:

PASS openstack/containerinfra/v1/certificates/testing.TestCreateCertificates (0.00s)

(That test is the sole caller of HandleCreateCertificateSuccessfully)

Later again: okay, it's a change in the redirect behavior in go 1.26. Updating the commit message now.

…test

The HandleCreateCertificateSuccessfully fixture registered its handler
at "/v1/certificates/" (with trailing slash) and asserted the request
method was GET, but certificates.Create issues a POST to
"/v1/certificates" (without trailing slash).

This worked by accident prior to Go 1.26: the ServeMux redirected
requests from "/v1/certificates" to "/v1/certificates/" via 301, and
Go's HTTP client changed POST to GET when following a 301 redirect. Go
1.26 changed these trailing-slash redirects to use 307 instead [1],
which preserves the original method, so POST now arrives at the handler
unchanged and the incorrect assertion fails.

Fix by matching the actual URL ("/v1/certificates", no trailing slash)
and asserting the correct method (POST).

[1] https://go.dev/doc/go1.26

Signed-off-by: Stephen Finucane <[email protected]>
Assisted-By: Claude Opus 4.6 <[email protected]>
@stephenfin
stephenfin force-pushed the fix-containerinfra-test branch from 91714b2 to 47354d2 Compare August 14, 2026 11:00
@winiciusallan

Copy link
Copy Markdown
Contributor

This worked by accident prior to Go 1.26: the ServeMux redirected requests from /v1/certificates to /v1/certificates/ via 301, and Go's HTTP client changed POST to GET when following a 301 redirect. Go 1.26 changed these trailing-slash redirects to use 307 instead, which preserves the original method, so POST now arrives at the handler unchanged and the incorrect assertion fails.

Ok, this explains everything now.

after @kayrus pushed a PR for this, I did some tests locally and wasn't getting why this was working with go 1.25 without the trailing slash but with 1.26 it was failing either way. good catch 👌

@mandre mandre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mandre
mandre added this pull request to the merge queue Aug 17, 2026
Merged via the queue into gophercloud:main with commit 41ffec8 Aug 17, 2026
70 checks passed
@mandre
mandre deleted the fix-containerinfra-test branch August 17, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v2 This PR will be backported to v2 edit:containerinfra This PR updates containerinfra code semver:patch No API change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: containerinfra unit tests are broken

4 participants