@@ -20,9 +20,10 @@ import (
2020 "testing"
2121
2222 "github.com/fluxcd/go-git-providers/gitprovider"
23+ gogitlab "github.com/xanzy/go-gitlab"
2324)
2425
25- func Test_DomainVariations (t * testing.T ) {
26+ func TestSupportedDomain (t * testing.T ) {
2627 tests := []struct {
2728 name string
2829 opts gitprovider.ClientOption
@@ -39,16 +40,31 @@ func Test_DomainVariations(t *testing.T) {
3940 opts : gitprovider .WithDomain ("my-gitlab.dev.com" ),
4041 want : "https://my-gitlab.dev.com" ,
4142 },
43+ {
44+ name : "custom domain without protocol with port" ,
45+ opts : gitprovider .WithDomain ("my-gitlab.dev.com:1234" ),
46+ want : "https://my-gitlab.dev.com:1234" ,
47+ },
4248 {
4349 name : "custom domain with https protocol" ,
4450 opts : gitprovider .WithDomain ("https://my-gitlab.dev.com" ),
4551 want : "https://my-gitlab.dev.com" ,
4652 },
53+ {
54+ name : "custom domain with https protocol with port" ,
55+ opts : gitprovider .WithDomain ("https://my-gitlab.dev.com:1234" ),
56+ want : "https://my-gitlab.dev.com:1234" ,
57+ },
4758 {
4859 name : "custom domain with http protocol" ,
4960 opts : gitprovider .WithDomain ("http://my-gitlab.dev.com" ),
5061 want : "http://my-gitlab.dev.com" ,
5162 },
63+ {
64+ name : "custom domain with http protocol with port" ,
65+ opts : gitprovider .WithDomain ("http://my-gitlab.dev.com:1234" ),
66+ want : "http://my-gitlab.dev.com:1234" ,
67+ },
5268 }
5369 for _ , tt := range tests {
5470 t .Run (tt .name , func (t * testing.T ) {
@@ -61,6 +77,61 @@ func Test_DomainVariations(t *testing.T) {
6177 }
6278}
6379
80+ func TestBaseURL (t * testing.T ) {
81+ tests := []struct {
82+ name string
83+ opts gitprovider.ClientOption
84+ expected string
85+ }{
86+ {
87+ name : "gitlab.com domain" ,
88+ opts : gitprovider .WithDomain ("gitlab.com" ),
89+ expected : "https://gitlab.com/api/v4/" ,
90+ },
91+ {
92+ name : "custom domain without protocol" ,
93+ opts : gitprovider .WithDomain ("my-gitlab.dev.com" ),
94+ expected : "https://my-gitlab.dev.com/api/v4/" ,
95+ },
96+ {
97+ name : "custom domain without protocol with port" ,
98+ opts : gitprovider .WithDomain ("my-gitlab.dev.com:1234" ),
99+ expected : "https://my-gitlab.dev.com:1234/api/v4/" ,
100+ },
101+ {
102+ name : "custom domain with https protocol" ,
103+ opts : gitprovider .WithDomain ("https://my-gitlab.dev.com" ),
104+ expected : "https://my-gitlab.dev.com/api/v4/" ,
105+ },
106+ {
107+ name : "custom domain with https protocol with port" ,
108+ opts : gitprovider .WithDomain ("https://my-gitlab.dev.com:1234" ),
109+ expected : "https://my-gitlab.dev.com:1234/api/v4/" ,
110+ },
111+ {
112+ name : "custom domain with http protocol" ,
113+ opts : gitprovider .WithDomain ("http://my-gitlab.dev.com" ),
114+ expected : "http://my-gitlab.dev.com/api/v4/" ,
115+ },
116+ {
117+ name : "custom domain with http protocol with port" ,
118+ opts : gitprovider .WithDomain ("http://my-gitlab.dev.com:1234" ),
119+ expected : "http://my-gitlab.dev.com:1234/api/v4/" ,
120+ },
121+ }
122+ for _ , tt := range tests {
123+ t .Run (tt .name , func (t * testing.T ) {
124+ c1 , _ := NewClient ("token" , "oauth2" , tt .opts )
125+ gc1 := c1 .Raw ().(* gogitlab.Client )
126+ assertEqual (t , tt .expected , gc1 .BaseURL ().String ())
127+
128+ c2 , _ := NewClient ("token" , "pat" , tt .opts )
129+ gc2 := c2 .Raw ().(* gogitlab.Client )
130+ assertEqual (t , tt .expected , gc2 .BaseURL ().String ())
131+ })
132+ }
133+ }
134+
64135func assertEqual (t * testing.T , a interface {}, b interface {}) {
65136 if a != b {
66137 t .Fatalf ("%s != %s" , a , b )
0 commit comments