Skip to content

Commit 0ccbfaf

Browse files
authored
fix: go 1.22 test breakage (#3459)
1 parent 24b0795 commit 0ccbfaf

File tree

6 files changed

+67
-70
lines changed

6 files changed

+67
-70
lines changed

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ go-github will require the N-1 major release of Go by default.
2222

2323
## Development
2424

25-
Go version 1.22 introduced significant changes to the pattern syntax and matching
26-
behavior of `http.ServerMux` which causes a large number of legacy unit tests to break.
27-
(See https://pkg.go.dev/net/http#hdr-Compatibility-ServeMux for more information.)
28-
As a result, testing of this repo is currently performed by setting this env variable:
29-
30-
```bash
31-
export GODEBUG=httpmuxgo121=1
32-
```
33-
34-
An issue has been created (#3409) requesting assistance in updating all breaking legacy unit
35-
tests when this `GODEBUG` environment variable is not set and Go 1.23.4 or later is
36-
used to perform unit tests.
37-
3825
If you're interested in using the [GraphQL API v4][], the recommended library is
3926
[shurcooL/githubv4][].
4027

github/orgs_packages_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestOrganizationsService_GetPackage(t *testing.T) {
118118
client, mux, _ := setup(t)
119119

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

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

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

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

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

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

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

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

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

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

github/repos_commits_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func TestRepositoriesService_NonAlphabetCharacter_GetCommitSHA1(t *testing.T) {
296296

297297
const sha1 = "01234abcde"
298298

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

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

392392
base := sample.base
393393
head := sample.head
394+
395+
encodedBase := url.PathEscape(base)
396+
encodedHead := url.PathEscape(head)
397+
394398
escapedBase := url.QueryEscape(base)
395399
escapedHead := url.QueryEscape(head)
396400

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

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

530534
base := sample.base
531535
head := sample.head
532-
pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", base, head)
536+
537+
encodedBase := url.PathEscape(base)
538+
encodedHead := url.PathEscape(head)
539+
540+
pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", encodedBase, encodedHead)
533541
const rawStr = "@@diff content"
534542

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

585593
base := sample.base
586594
head := sample.head
587-
pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", base, head)
595+
596+
encodedBase := url.PathEscape(base)
597+
encodedHead := url.PathEscape(head)
598+
599+
pattern := fmt.Sprintf("/repos/o/r/compare/%v...%v", encodedBase, encodedHead)
588600
const rawStr = "@@patch content"
589601

590602
mux.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {

github/repos_contents_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ func TestRepositoriesService_GetContents_DirectoryWithSpaces(t *testing.T) {
472472
t.Parallel()
473473
client, mux, _ := setup(t)
474474

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

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

0 commit comments

Comments
 (0)