@@ -12,33 +12,48 @@ import (
1212
1313func Test_githubClient_withEnterpriseURL (t * testing.T ) {
1414 tests := []struct {
15- name string
16- baseURL string
17- wantErr bool
15+ name string
16+ baseURL string
17+ expectedBaseURL interface {}
1818 }{
1919 {
20- name : "valid URL" ,
21- baseURL : "https://github.example.com" ,
22- wantErr : false ,
20+ name : "valid URL with subdomain" ,
21+ baseURL : "https://api.github.example.com" ,
22+ expectedBaseURL : "https://api.github.example.com/" ,
23+ },
24+ {
25+ name : "valid URL with path" ,
26+ baseURL : "https://github.example.com/api/v3" ,
27+ expectedBaseURL : "https://github.example.com/api/v3/" ,
28+ },
29+ {
30+ name : "valid URL without path" ,
31+ baseURL : "https://github.example.com" ,
32+ expectedBaseURL : "https://github.example.com/api/v3/" ,
2333 },
2434 {
25- name : "invalid URL with control characters" ,
26- baseURL : "ht\n tp://invalid" ,
27- wantErr : true ,
35+ name : "invalid URL with control characters" ,
36+ baseURL : "ht\n tp://invalid" ,
37+ expectedBaseURL : nil ,
2838 },
2939 {
30- name : "URL with spaces" ,
31- baseURL : "http://invalid url with spaces" ,
32- wantErr : true ,
40+ name : "URL with spaces" ,
41+ baseURL : "http://invalid url with spaces" ,
42+ expectedBaseURL : nil ,
3343 },
3444 }
3545
3646 for _ , tt := range tests {
3747 t .Run (tt .name , func (t * testing.T ) {
3848 client := newGitHubClient (& http.Client {})
39- _ , err := client .withEnterpriseURL (tt .baseURL )
40- if (err != nil ) != tt .wantErr {
41- t .Errorf ("withEnterpriseURL() error = %v, wantErr %v" , err , tt .wantErr )
49+ githubClient , err := client .withEnterpriseURL (tt .baseURL )
50+
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 {
56+ t .Errorf ("withEnterpriseURL(%v) expected = %v, received = %v" , tt .baseURL , tt .expectedBaseURL , githubClient .baseURL )
4257 }
4358 })
4459 }
0 commit comments