@@ -7,64 +7,56 @@ import (
77 "github.com/stretchr/testify/assert"
88)
99
10- func generateDummyGitStarterProject (name , checkoutRemote string , remotes map [string ]string ) v1alpha2.StarterProject {
10+ func generateDummyGitStarterProject (name string , checkoutRemote * v1alpha2. CheckoutFrom , remotes map [string ]string ) v1alpha2.StarterProject {
1111 return v1alpha2.StarterProject {
1212 Name : name ,
1313 ProjectSource : v1alpha2.ProjectSource {
1414 Git : & v1alpha2.GitProjectSource {
1515 GitLikeProjectSource : v1alpha2.GitLikeProjectSource {
16- Remotes : remotes ,
17- CheckoutFrom : & v1alpha2.CheckoutFrom {
18- Remote : checkoutRemote ,
19- },
16+ Remotes : remotes ,
17+ CheckoutFrom : checkoutRemote ,
2018 },
2119 },
2220 },
2321 }
2422}
2523
26- func generateDummyGithubStarterProject (name , checkoutRemote string , remotes map [string ]string ) v1alpha2.StarterProject {
24+ func generateDummyGithubStarterProject (name string , checkoutRemote * v1alpha2. CheckoutFrom , remotes map [string ]string ) v1alpha2.StarterProject {
2725 return v1alpha2.StarterProject {
2826 Name : name ,
2927 ProjectSource : v1alpha2.ProjectSource {
3028 Github : & v1alpha2.GithubProjectSource {
3129 GitLikeProjectSource : v1alpha2.GitLikeProjectSource {
32- Remotes : remotes ,
33- CheckoutFrom : & v1alpha2.CheckoutFrom {
34- Remote : checkoutRemote ,
35- },
30+ Remotes : remotes ,
31+ CheckoutFrom : checkoutRemote ,
3632 },
3733 },
3834 },
3935 }
4036}
4137
42- func generateDummyGitProject (name , checkoutRemote string , remotes map [string ]string ) v1alpha2.Project {
38+ func generateDummyGitProject (name string , checkoutRemote * v1alpha2. CheckoutFrom , remotes map [string ]string ) v1alpha2.Project {
4339 return v1alpha2.Project {
4440 Name : name ,
4541 ProjectSource : v1alpha2.ProjectSource {
4642 Git : & v1alpha2.GitProjectSource {
4743 GitLikeProjectSource : v1alpha2.GitLikeProjectSource {
48- Remotes : remotes ,
49- CheckoutFrom : & v1alpha2.CheckoutFrom {
50- Remote : checkoutRemote ,
51- },
44+ Remotes : remotes ,
45+ CheckoutFrom : checkoutRemote ,
5246 },
5347 },
5448 },
5549 }
5650}
5751
58- func generateDummyGithubProject (name , checkoutRemote string , remotes map [string ]string ) v1alpha2.Project {
52+ func generateDummyGithubProject (name string , checkoutRemote * v1alpha2. CheckoutFrom , remotes map [string ]string ) v1alpha2.Project {
5953 return v1alpha2.Project {
6054 Name : name ,
6155 ProjectSource : v1alpha2.ProjectSource {
6256 Github : & v1alpha2.GithubProjectSource {
6357 GitLikeProjectSource : v1alpha2.GitLikeProjectSource {
64- Remotes : remotes ,
65- CheckoutFrom : & v1alpha2.CheckoutFrom {
66- Remote : checkoutRemote ,
67- },
58+ Remotes : remotes ,
59+ CheckoutFrom : checkoutRemote ,
6860 },
6961 },
7062 },
@@ -85,35 +77,41 @@ func TestValidateStarterProjects(t *testing.T) {
8577 {
8678 name : "Valid Starter Project" ,
8779 starterProjects : []v1alpha2.StarterProject {
88- generateDummyGitStarterProject ("project1" , "origin" , map [string ]string {"origin" : "originremote" }),
89- generateDummyGitStarterProject ("project2" , "origin" , map [string ]string {"origin" : "originremote2" }),
80+ generateDummyGitStarterProject ("project1" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {"origin" : "originremote" }),
81+ generateDummyGitStarterProject ("project2" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {"origin" : "originremote2" }),
9082 },
9183 },
9284 {
9385 name : "Invalid Starter Project" ,
9486 starterProjects : []v1alpha2.StarterProject {
95- generateDummyGithubStarterProject ("project1" , "origin" , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
87+ generateDummyGithubStarterProject ("project1" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
9688 },
9789 wantErr : & oneRemoteErr ,
9890 },
9991 {
10092 name : "Invalid Starter Project with wrong checkout" ,
10193 starterProjects : []v1alpha2.StarterProject {
102- generateDummyGithubStarterProject ("project1" , "origin" , map [string ]string {"test" : "testremote" }),
94+ generateDummyGithubStarterProject ("project1" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {"test" : "testremote" }),
10395 },
10496 wantErr : & wrongCheckoutErr ,
10597 },
10698 {
10799 name : "Valid Starter Project with empty checkout remote" ,
108100 starterProjects : []v1alpha2.StarterProject {
109- generateDummyGitStarterProject ("project1" , "" , map [string ]string {"origin" : "originremote" }),
101+ generateDummyGitStarterProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "" }, map [string ]string {"origin" : "originremote" }),
102+ },
103+ },
104+ {
105+ name : "Valid Starter Project with no checkout remote" ,
106+ starterProjects : []v1alpha2.StarterProject {
107+ generateDummyGitStarterProject ("project1" , nil , map [string ]string {"origin" : "originremote" }),
110108 },
111109 },
112110 {
113111 name : "Invalid Starter Project with empty remotes" ,
114112 starterProjects : []v1alpha2.StarterProject {
115- generateDummyGithubStarterProject ("project1" , "origin" , map [string ]string {}),
116- generateDummyGithubStarterProject ("project3" , "origin" , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
113+ generateDummyGithubStarterProject ("project1" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {}),
114+ generateDummyGithubStarterProject ("project3" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
117115 },
118116 wantErr : & atleastOneRemoteErr ,
119117 },
@@ -135,6 +133,7 @@ func TestValidateProjects(t *testing.T) {
135133
136134 wrongCheckoutErr := "unable to find the checkout remote .* in the remotes for project.*"
137135 atleastOneRemoteErr := "projects .* should have at least one remote"
136+ missingCheckOutFromRemoteErr := "project .* has more than one remote defined, but has no checkoutfrom remote defined"
138137
139138 tests := []struct {
140139 name string
@@ -144,37 +143,44 @@ func TestValidateProjects(t *testing.T) {
144143 {
145144 name : "Valid Project" ,
146145 projects : []v1alpha2.Project {
147- generateDummyGitProject ("project1" , "origin" , map [string ]string {"origin" : "originremote" }),
148- generateDummyGithubProject ("project2" , "origin" , map [string ]string {"origin" : "originremote" }),
146+ generateDummyGitProject ("project1" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {"origin" : "originremote" }),
147+ generateDummyGithubProject ("project2" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {"origin" : "originremote" }),
149148 },
150149 },
150+ {
151+ name : "Invalid Project with multiple remotes but no checkoutfrom" ,
152+ projects : []v1alpha2.Project {
153+ generateDummyGithubProject ("project2" , nil , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
154+ },
155+ wantErr : & missingCheckOutFromRemoteErr ,
156+ },
151157 {
152158 name : "Invalid Project with multiple remote and empty checkout remote" ,
153159 projects : []v1alpha2.Project {
154- generateDummyGitProject ("project2" , "origin" , map [string ]string {"origin" : "originremote" }),
155- generateDummyGithubProject ("project1" , "" , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
160+ generateDummyGitProject ("project2" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {"origin" : "originremote" }),
161+ generateDummyGithubProject ("project1" , & v1alpha2. CheckoutFrom { Remote : "" } , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
156162 },
157- wantErr : & wrongCheckoutErr ,
163+ wantErr : & missingCheckOutFromRemoteErr ,
158164 },
159165 {
160166 name : "Invalid Project with wrong checkout" ,
161167 projects : []v1alpha2.Project {
162- generateDummyGithubProject ("project1" , "origin" , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
163- generateDummyGitProject ("project2" , "origin1" , map [string ]string {"origin2" : "originremote2" }),
168+ generateDummyGithubProject ("project1" , & v1alpha2. CheckoutFrom { Remote : "origin1" } , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
169+ generateDummyGitProject ("project2" , & v1alpha2. CheckoutFrom { Remote : "origin1" } , map [string ]string {"origin2" : "originremote2" }),
164170 },
165171 wantErr : & wrongCheckoutErr ,
166172 },
167173 {
168174 name : "Valid Project with empty checkout remote" ,
169175 projects : []v1alpha2.Project {
170- generateDummyGitProject ("project1" , "" , map [string ]string {"origin" : "originremote" }),
176+ generateDummyGitProject ("project1" , & v1alpha2. CheckoutFrom { Remote : "" } , map [string ]string {"origin" : "originremote" }),
171177 },
172178 },
173179 {
174180 name : "Invalid Project with empty remotes" ,
175181 projects : []v1alpha2.Project {
176- generateDummyGitProject ("project1" , "origin" , map [string ]string {}),
177- generateDummyGithubProject ("project2" , "origins" , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
182+ generateDummyGitProject ("project1" , & v1alpha2. CheckoutFrom { Remote : "origin" } , map [string ]string {}),
183+ generateDummyGithubProject ("project2" , & v1alpha2. CheckoutFrom { Remote : "origins" } , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
178184 },
179185 wantErr : & atleastOneRemoteErr ,
180186 },
0 commit comments