-
-
Notifications
You must be signed in to change notification settings - Fork 5
Fix regression in github enterprise url handling #40 #41
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,33 +12,48 @@ import ( | |
|
|
||
| func Test_githubClient_withEnterpriseURL(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| baseURL string | ||
| wantErr bool | ||
| name string | ||
| baseURL string | ||
| expectedBaseURL interface{} | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer keeping the original wantErr bool + a separate expectedURL string field instead of using interface{} to represent both. This is more idiomatic Go and gives type safety at compile time. |
||
| }{ | ||
| { | ||
| name: "valid URL", | ||
| baseURL: "https://github.example.com", | ||
| wantErr: false, | ||
| name: "valid URL with subdomain", | ||
| baseURL: "https://api.github.example.com", | ||
| expectedBaseURL: "https://api.github.example.com/", | ||
| }, | ||
| { | ||
| name: "valid URL with path", | ||
| baseURL: "https://github.example.com/api/v3", | ||
| expectedBaseURL: "https://github.example.com/api/v3/", | ||
| }, | ||
| { | ||
| name: "valid URL without path", | ||
| baseURL: "https://github.example.com", | ||
| expectedBaseURL: "https://github.example.com/api/v3/", | ||
| }, | ||
| { | ||
| name: "invalid URL with control characters", | ||
| baseURL: "ht\ntp://invalid", | ||
| wantErr: true, | ||
| name: "invalid URL with control characters", | ||
| baseURL: "ht\ntp://invalid", | ||
| expectedBaseURL: nil, | ||
| }, | ||
| { | ||
| name: "URL with spaces", | ||
| baseURL: "http://invalid url with spaces", | ||
| wantErr: true, | ||
| name: "URL with spaces", | ||
| baseURL: "http://invalid url with spaces", | ||
| expectedBaseURL: nil, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| client := newGitHubClient(&http.Client{}) | ||
| _, err := client.withEnterpriseURL(tt.baseURL) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("withEnterpriseURL() error = %v, wantErr %v", err, tt.wantErr) | ||
| githubClient, err := client.withEnterpriseURL(tt.baseURL) | ||
|
|
||
| if err != nil { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This silently passes when an error occurs and expectedBaseURL is nil, but doesn't assert that an error was expected. The original if (err != nil) != tt.wantErr pattern is stricter — it catches both unexpected errors and missing expected errors. |
||
| if tt.expectedBaseURL != nil { | ||
| t.Errorf("withEnterpriseURL(%v) error = %v", tt.baseURL, err) | ||
| } | ||
| } else if githubClient.baseURL.String() != tt.expectedBaseURL { | ||
| t.Errorf("withEnterpriseURL(%v) expected = %v, received = %v", tt.baseURL, tt.expectedBaseURL, githubClient.baseURL) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
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.
Could you add test cases for the remaining branches?
https://github.example.com/api/v3/ — already fully suffixed, should stay as-is
https://ghes.api.example.com — .api. in host, should skip /api/v3/ append
https://github.example.com/ — trailing slash already present, should not double it