@@ -14,32 +14,68 @@ func Test_githubClient_withEnterpriseURL(t *testing.T) {
1414 tests := []struct {
1515 name string
1616 baseURL string
17- expectedBaseURL interface {}
17+ wantErr bool
18+ expectedBaseURL string
1819 }{
1920 {
20- name : "valid URL with subdomain" ,
21+ name : "valid URL with first subdomain" ,
2122 baseURL : "https://api.github.example.com" ,
23+ wantErr : false ,
2224 expectedBaseURL : "https://api.github.example.com/" ,
2325 },
26+ {
27+ name : "valid URL with first subdomain and trailing slash" ,
28+ baseURL : "https://api.github.example.com/" ,
29+ wantErr : false ,
30+ expectedBaseURL : "https://api.github.example.com/" ,
31+ },
32+ {
33+ name : "valid URL with second subdomain" ,
34+ baseURL : "https://ghes.api.example.com" ,
35+ wantErr : false ,
36+ expectedBaseURL : "https://ghes.api.example.com/" ,
37+ },
38+ {
39+ name : "valid URL with second subdomain and trailing slash" ,
40+ baseURL : "https://ghes.api.example.com/" ,
41+ wantErr : false ,
42+ expectedBaseURL : "https://ghes.api.example.com/" ,
43+ },
2444 {
2545 name : "valid URL with path" ,
2646 baseURL : "https://github.example.com/api/v3" ,
47+ wantErr : false ,
48+ expectedBaseURL : "https://github.example.com/api/v3/" ,
49+ },
50+ {
51+ name : "valid URL with path and trailing slash" ,
52+ baseURL : "https://github.example.com/api/v3/" ,
53+ wantErr : false ,
2754 expectedBaseURL : "https://github.example.com/api/v3/" ,
2855 },
2956 {
3057 name : "valid URL without path" ,
3158 baseURL : "https://github.example.com" ,
59+ wantErr : false ,
60+ expectedBaseURL : "https://github.example.com/api/v3/" ,
61+ },
62+ {
63+ name : "valid URL without path but with trailing slash" ,
64+ baseURL : "https://github.example.com/" ,
65+ wantErr : false ,
3266 expectedBaseURL : "https://github.example.com/api/v3/" ,
3367 },
3468 {
3569 name : "invalid URL with control characters" ,
3670 baseURL : "ht\n tp://invalid" ,
37- expectedBaseURL : nil ,
71+ wantErr : true ,
72+ expectedBaseURL : "" ,
3873 },
3974 {
4075 name : "URL with spaces" ,
4176 baseURL : "http://invalid url with spaces" ,
42- expectedBaseURL : nil ,
77+ wantErr : true ,
78+ expectedBaseURL : "" ,
4379 },
4480 }
4581
@@ -48,11 +84,11 @@ func Test_githubClient_withEnterpriseURL(t *testing.T) {
4884 client := newGitHubClient (& http.Client {})
4985 githubClient , err := client .withEnterpriseURL (tt .baseURL )
5086
51- if err != nil {
52- if tt . expectedBaseURL != nil {
53- t . Errorf ( "withEnterpriseURL(%v) error = %v" , tt . baseURL , err )
54- }
55- } else if githubClient .baseURL .String () != tt .expectedBaseURL {
87+ if ( err != nil ) != tt . wantErr {
88+ t . Errorf ( "withEnterpriseURL(%v) error = %v" , tt . baseURL , err )
89+ }
90+
91+ if err == nil && githubClient .baseURL .String () != tt .expectedBaseURL {
5692 t .Errorf ("withEnterpriseURL(%v) expected = %v, received = %v" , tt .baseURL , tt .expectedBaseURL , githubClient .baseURL )
5793 }
5894 })
0 commit comments