Skip to content

fix: go 1.22 test breakage #3459

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

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ go-github will require the N-1 major release of Go by default.

## Development

Go version 1.22 introduced significant changes to the pattern syntax and matching
behavior of `http.ServerMux` which causes a large number of legacy unit tests to break.
(See https://pkg.go.dev/net/http#hdr-Compatibility-ServeMux for more information.)
As a result, testing of this repo is currently performed by setting this env variable:

```bash
export GODEBUG=httpmuxgo121=1
```

An issue has been created (#3409) requesting assistance in updating all breaking legacy unit
tests when this `GODEBUG` environment variable is not set and Go 1.23.4 or later is
used to perform unit tests.

If you're interested in using the [GraphQL API v4][], the recommended library is
[shurcooL/githubv4][].

Expand Down
14 changes: 7 additions & 7 deletions github/orgs_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestOrganizationsService_GetPackage(t *testing.T) {
client, mux, _ := setup(t)

// don't url escape the package name here since mux will convert it to a slash automatically
mux.HandleFunc("/orgs/o/packages/container/hello/hello_docker", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/orgs/o/packages/container/hello%2fhello_docker", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
_, err := io.WriteString(w, `{
"id": 197,
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestOrganizationsService_DeletePackage(t *testing.T) {
client, mux, _ := setup(t)

// don't url escape the package name here since mux will convert it to a slash automatically
mux.HandleFunc("/orgs/o/packages/container/hello/hello_docker", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/orgs/o/packages/container/hello%2fhello_docker", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})

Expand Down Expand Up @@ -207,7 +207,7 @@ func TestOrganizationsService_RestorePackage(t *testing.T) {
client, mux, _ := setup(t)

// don't url escape the package name here since mux will convert it to a slash automatically
mux.HandleFunc("/orgs/o/packages/container/hello/hello_docker/restore", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/orgs/o/packages/container/hello%2Fhello_docker/restore", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
})

Expand All @@ -233,7 +233,7 @@ func TestOrganizationsService_ListPackagesVersions(t *testing.T) {
client, mux, _ := setup(t)

// don't url escape the package name here since mux will convert it to a slash automatically
mux.HandleFunc("/orgs/o/packages/container/hello/hello_docker/versions", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/orgs/o/packages/container/hello%2Fhello_docker/versions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"per_page": "2", "page": "1", "state": "deleted", "visibility": "internal", "package_type": "container"})
_, err := io.WriteString(w, `[
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestOrganizationsService_PackageGetVersion(t *testing.T) {
client, mux, _ := setup(t)

// don't url escape the package name here since mux will convert it to a slash automatically
mux.HandleFunc("/orgs/o/packages/container/hello/hello_docker/versions/45763", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/orgs/o/packages/container/hello%2Fhello_docker/versions/45763", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
_, err := io.WriteString(w, `
{
Expand Down Expand Up @@ -377,7 +377,7 @@ func TestOrganizationsService_PackageDeleteVersion(t *testing.T) {
client, mux, _ := setup(t)

// don't url escape the package name here since mux will convert it to a slash automatically
mux.HandleFunc("/orgs/o/packages/container/hello/hello_docker/versions/45763", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/orgs/o/packages/container/hello%2Fhello_docker/versions/45763", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})

Expand All @@ -403,7 +403,7 @@ func TestOrganizationsService_PackageRestoreVersion(t *testing.T) {
client, mux, _ := setup(t)

// don't url escape the package name here since mux will convert it to a slash automatically
mux.HandleFunc("/orgs/o/packages/container/hello/hello_docker/versions/45763/restore", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/orgs/o/packages/container/hello%2Fhello_docker/versions/45763/restore", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
})

Expand Down
20 changes: 16 additions & 4 deletions github/repos_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func TestRepositoriesService_NonAlphabetCharacter_GetCommitSHA1(t *testing.T) {

const sha1 = "01234abcde"

mux.HandleFunc("/repos/o/r/commits/master%20hash", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/repos/o/r/commits/master%2520hash", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeV3SHA)

Expand Down Expand Up @@ -391,10 +391,14 @@ func TestRepositoriesService_CompareCommits(t *testing.T) {

base := sample.base
head := sample.head

encodedBase := url.PathEscape(base)
encodedHead := url.PathEscape(head)

escapedBase := url.QueryEscape(base)
escapedHead := url.QueryEscape(head)

pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", base, head)
pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", encodedBase, encodedHead)

mux.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
Expand Down Expand Up @@ -529,7 +533,11 @@ func TestRepositoriesService_CompareCommitsRaw_diff(t *testing.T) {

base := sample.base
head := sample.head
pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", base, head)

encodedBase := url.PathEscape(base)
encodedHead := url.PathEscape(head)

pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", encodedBase, encodedHead)
const rawStr = "@@diff content"

mux.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -584,7 +592,11 @@ func TestRepositoriesService_CompareCommitsRaw_patch(t *testing.T) {

base := sample.base
head := sample.head
pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", base, head)

encodedBase := url.PathEscape(base)
encodedHead := url.PathEscape(head)

pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", encodedBase, encodedHead)
const rawStr = "@@patch content"

mux.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions github/repos_contents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func TestRepositoriesService_GetContents_DirectoryWithSpaces(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/repos/o/r/contents/some directory/file.go", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/repos/o/r/contents/some%20directory/file.go", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{}`)
})
Expand Down Expand Up @@ -502,7 +502,7 @@ func TestRepositoriesService_GetContents_DirectoryWithPlusChars(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/repos/o/r/contents/some directory+name/file.go", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/repos/o/r/contents/some%20directory%2Bname/file.go", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{}`)
})
Expand Down
Loading
Loading