11package validation
22
33import (
4- "github.com/devfile/api/v2/pkg/attributes"
54 "testing"
65
6+ "github.com/devfile/api/v2/pkg/attributes"
7+
78 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
89 "github.com/stretchr/testify/assert"
910)
@@ -23,20 +24,6 @@ func generateDummyGitStarterProject(name string, checkoutRemote *v1alpha2.Checko
2324 }
2425}
2526
26- func generateDummyGithubStarterProject (name string , checkoutRemote * v1alpha2.CheckoutFrom , remotes map [string ]string ) v1alpha2.StarterProject {
27- return v1alpha2.StarterProject {
28- Name : name ,
29- ProjectSource : v1alpha2.ProjectSource {
30- Github : & v1alpha2.GithubProjectSource {
31- GitLikeProjectSource : v1alpha2.GitLikeProjectSource {
32- Remotes : remotes ,
33- CheckoutFrom : checkoutRemote ,
34- },
35- },
36- },
37- }
38- }
39-
4027func generateDummyGitProject (name string , checkoutRemote * v1alpha2.CheckoutFrom , remotes map [string ]string , projectAttribute attributes.Attributes ) v1alpha2.Project {
4128 return v1alpha2.Project {
4229 Attributes : projectAttribute ,
@@ -52,20 +39,6 @@ func generateDummyGitProject(name string, checkoutRemote *v1alpha2.CheckoutFrom,
5239 }
5340}
5441
55- func generateDummyGithubProject (name string , checkoutRemote * v1alpha2.CheckoutFrom , remotes map [string ]string ) v1alpha2.Project {
56- return v1alpha2.Project {
57- Name : name ,
58- ProjectSource : v1alpha2.ProjectSource {
59- Github : & v1alpha2.GithubProjectSource {
60- GitLikeProjectSource : v1alpha2.GitLikeProjectSource {
61- Remotes : remotes ,
62- CheckoutFrom : checkoutRemote ,
63- },
64- },
65- },
66- }
67- }
68-
6942func TestValidateStarterProjects (t * testing.T ) {
7043
7144 oneRemoteErr := "starterProject .* should have one remote only"
@@ -91,14 +64,14 @@ func TestValidateStarterProjects(t *testing.T) {
9164 {
9265 name : "Invalid Starter Project" ,
9366 starterProjects : []v1alpha2.StarterProject {
94- generateDummyGithubStarterProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
67+ generateDummyGitStarterProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }, attributes. Attributes { }),
9568 },
9669 wantErr : & oneRemoteErr ,
9770 },
9871 {
9972 name : "Invalid Starter Project with wrong checkout" ,
10073 starterProjects : []v1alpha2.StarterProject {
101- generateDummyGithubStarterProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"test" : "testremote" }),
74+ generateDummyGitStarterProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"test" : "testremote" }, attributes. Attributes { }),
10275 },
10376 wantErr : & wrongCheckoutErr ,
10477 },
@@ -117,8 +90,8 @@ func TestValidateStarterProjects(t *testing.T) {
11790 {
11891 name : "Invalid Starter Project with empty remotes" ,
11992 starterProjects : []v1alpha2.StarterProject {
120- generateDummyGithubStarterProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {}),
121- generateDummyGithubStarterProject ("project3" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
93+ generateDummyGitStarterProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {}, attributes. Attributes {}),
94+ generateDummyGitStarterProject ("project3" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }, attributes. Attributes { }),
12295 },
12396 wantErr : & atleastOneRemoteErr ,
12497 },
@@ -162,28 +135,28 @@ func TestValidateProjects(t *testing.T) {
162135 name : "Valid Project" ,
163136 projects : []v1alpha2.Project {
164137 generateDummyGitProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"origin" : "originremote" }, attributes.Attributes {}),
165- generateDummyGithubProject ("project2" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"origin" : "originremote" }),
138+ generateDummyGitProject ("project2" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"origin" : "originremote" }, attributes. Attributes { }),
166139 },
167140 },
168141 {
169142 name : "Invalid Project with multiple remotes but no checkoutfrom" ,
170143 projects : []v1alpha2.Project {
171- generateDummyGithubProject ("project2" , nil , map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
144+ generateDummyGitProject ("project2" , nil , map [string ]string {"origin" : "originremote" , "test" : "testremote" }, attributes. Attributes { }),
172145 },
173146 wantErr : & missingCheckOutFromRemoteErr ,
174147 },
175148 {
176149 name : "Invalid Project with multiple remote and empty checkout remote" ,
177150 projects : []v1alpha2.Project {
178151 generateDummyGitProject ("project2" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {"origin" : "originremote" }, attributes.Attributes {}),
179- generateDummyGithubProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
152+ generateDummyGitProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }, attributes. Attributes { }),
180153 },
181154 wantErr : & missingCheckOutFromRemoteErr ,
182155 },
183156 {
184157 name : "Invalid Project with wrong checkout" ,
185158 projects : []v1alpha2.Project {
186- generateDummyGithubProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin1" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
159+ generateDummyGitProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin1" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }, attributes. Attributes { }),
187160 generateDummyGitProject ("project2" , & v1alpha2.CheckoutFrom {Remote : "origin1" }, map [string ]string {"origin2" : "originremote2" }, attributes.Attributes {}),
188161 },
189162 wantErr : & wrongCheckoutErr ,
@@ -198,7 +171,7 @@ func TestValidateProjects(t *testing.T) {
198171 name : "Invalid Project with empty remotes" ,
199172 projects : []v1alpha2.Project {
200173 generateDummyGitProject ("project1" , & v1alpha2.CheckoutFrom {Remote : "origin" }, map [string ]string {}, attributes.Attributes {}),
201- generateDummyGithubProject ("project2" , & v1alpha2.CheckoutFrom {Remote : "origins" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }),
174+ generateDummyGitProject ("project2" , & v1alpha2.CheckoutFrom {Remote : "origins" }, map [string ]string {"origin" : "originremote" , "test" : "testremote" }, attributes. Attributes { }),
202175 },
203176 wantErr : & atleastOneRemoteErr ,
204177 },
0 commit comments