1
1
package validation
2
2
3
3
import (
4
- "github.com/devfile/api/v2/pkg/attributes"
5
4
"testing"
6
5
6
+ "github.com/devfile/api/v2/pkg/attributes"
7
+
7
8
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
8
9
"github.com/stretchr/testify/assert"
9
10
)
@@ -23,20 +24,6 @@ func generateDummyGitStarterProject(name string, checkoutRemote *v1alpha2.Checko
23
24
}
24
25
}
25
26
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
-
40
27
func generateDummyGitProject (name string , checkoutRemote * v1alpha2.CheckoutFrom , remotes map [string ]string , projectAttribute attributes.Attributes ) v1alpha2.Project {
41
28
return v1alpha2.Project {
42
29
Attributes : projectAttribute ,
@@ -52,20 +39,6 @@ func generateDummyGitProject(name string, checkoutRemote *v1alpha2.CheckoutFrom,
52
39
}
53
40
}
54
41
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
-
69
42
func TestValidateStarterProjects (t * testing.T ) {
70
43
71
44
oneRemoteErr := "starterProject .* should have one remote only"
@@ -91,14 +64,14 @@ func TestValidateStarterProjects(t *testing.T) {
91
64
{
92
65
name : "Invalid Starter Project" ,
93
66
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 { }),
95
68
},
96
69
wantErr : & oneRemoteErr ,
97
70
},
98
71
{
99
72
name : "Invalid Starter Project with wrong checkout" ,
100
73
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 { }),
102
75
},
103
76
wantErr : & wrongCheckoutErr ,
104
77
},
@@ -117,8 +90,8 @@ func TestValidateStarterProjects(t *testing.T) {
117
90
{
118
91
name : "Invalid Starter Project with empty remotes" ,
119
92
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 { }),
122
95
},
123
96
wantErr : & atleastOneRemoteErr ,
124
97
},
@@ -162,28 +135,28 @@ func TestValidateProjects(t *testing.T) {
162
135
name : "Valid Project" ,
163
136
projects : []v1alpha2.Project {
164
137
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 { }),
166
139
},
167
140
},
168
141
{
169
142
name : "Invalid Project with multiple remotes but no checkoutfrom" ,
170
143
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 { }),
172
145
},
173
146
wantErr : & missingCheckOutFromRemoteErr ,
174
147
},
175
148
{
176
149
name : "Invalid Project with multiple remote and empty checkout remote" ,
177
150
projects : []v1alpha2.Project {
178
151
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 { }),
180
153
},
181
154
wantErr : & missingCheckOutFromRemoteErr ,
182
155
},
183
156
{
184
157
name : "Invalid Project with wrong checkout" ,
185
158
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 { }),
187
160
generateDummyGitProject ("project2" , & v1alpha2.CheckoutFrom {Remote : "origin1" }, map [string ]string {"origin2" : "originremote2" }, attributes.Attributes {}),
188
161
},
189
162
wantErr : & wrongCheckoutErr ,
@@ -198,7 +171,7 @@ func TestValidateProjects(t *testing.T) {
198
171
name : "Invalid Project with empty remotes" ,
199
172
projects : []v1alpha2.Project {
200
173
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 { }),
202
175
},
203
176
wantErr : & atleastOneRemoteErr ,
204
177
},
0 commit comments