@@ -20,13 +20,15 @@ import (
2020 "github.com/google/go-cmp/cmp"
2121)
2222
23+ // nolint:paralleltest
24+ // because we are using t.Setenv.
2325func TestRepoURL_IsValid (t * testing.T ) {
24- t .Parallel ()
2526 tests := []struct {
2627 name string
2728 inputURL string
2829 expected repoURL
2930 wantErr bool
31+ ghHost bool
3032 }{
3133 {
3234 name : "Valid http address" ,
@@ -59,7 +61,7 @@ func TestRepoURL_IsValid(t *testing.T) {
5961 wantErr : true ,
6062 },
6163 {
62- name : "github repository" ,
64+ name : "Github repository" ,
6365 expected : repoURL {
6466 host : "github.com" ,
6567 owner : "foo" ,
@@ -69,7 +71,7 @@ func TestRepoURL_IsValid(t *testing.T) {
6971 wantErr : false ,
7072 },
7173 {
72- name : "github repository" ,
74+ name : "Github repository with host " ,
7375 expected : repoURL {
7476 host : "github.com" ,
7577 owner : "foo" ,
@@ -78,11 +80,36 @@ func TestRepoURL_IsValid(t *testing.T) {
7880 inputURL : "https://github.com/foo/kubeflow" ,
7981 wantErr : false ,
8082 },
83+ {
84+ name : "Enterprise github repository with host" ,
85+ expected : repoURL {
86+ host : "github.corp.com" ,
87+ owner : "corpfoo" ,
88+ repo : "kubeflow" ,
89+ },
90+ inputURL : "https://github.corp.com/corpfoo/kubeflow" ,
91+ wantErr : false ,
92+ ghHost : true ,
93+ },
94+ {
95+ name : "Enterprise github repository" ,
96+ expected : repoURL {
97+ host : "github.corp.com" ,
98+ owner : "corpfoo" ,
99+ repo : "kubeflow" ,
100+ },
101+ inputURL : "corpfoo/kubeflow" ,
102+ wantErr : false ,
103+ ghHost : true ,
104+ },
81105 }
82106 for _ , tt := range tests {
83107 tt := tt // Re-initializing variable so it is not changed while executing the closure below
84108 t .Run (tt .name , func (t * testing.T ) {
85- t .Parallel ()
109+ if tt .ghHost {
110+ t .Setenv ("GH_HOST" , "github.corp.com" )
111+ }
112+
86113 r := repoURL {
87114 host : tt .expected .host ,
88115 owner : tt .expected .owner ,
@@ -97,7 +124,6 @@ func TestRepoURL_IsValid(t *testing.T) {
97124 if ! tt .wantErr && ! cmp .Equal (tt .expected , r , cmp .AllowUnexported (repoURL {})) {
98125 t .Errorf ("Got diff: %s" , cmp .Diff (tt .expected , r ))
99126 }
100-
101127 if ! cmp .Equal (r .Host (), tt .expected .host ) {
102128 t .Errorf ("%s expected host: %s got host %s" , tt .inputURL , tt .expected .host , r .Host ())
103129 }
0 commit comments