MCPcopy Create free account
hub / github.com/devfile/api / TestValidateProjects

Function TestValidateProjects

pkg/validation/projects_test.go:139–219  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

137}
138
139func TestValidateProjects(t *testing.T) {
140
141 wrongCheckoutErr := "unable to find the checkout remote .* in the remotes for project.*"
142 atleastOneRemoteErr := "project .* should have at least one remote"
143 missingCheckOutFromRemoteErr := "project .* has more than one remote defined, but has no checkoutfrom remote defined"
144
145 parentOverridesFromMainDevfile := attributes.Attributes{}.PutString(ImportSourceAttribute,
146 "uri: http://127.0.0.1:8080").PutString(ParentOverrideAttribute, "main devfile")
147 wrongCheckoutErrWithImportAttributes := "unable to find the checkout remote .* in the remotes for project.*, imported from uri: http://127.0.0.1:8080, in parent overrides from main devfile"
148
149 tests := []struct {
150 name string
151 projects []v1alpha2.Project
152 wantErr []string
153 }{
154 {
155 name: "Valid Project",
156 projects: []v1alpha2.Project{
157 generateDummyGitProject("project1", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{"origin": "originremote"}, attributes.Attributes{}),
158 generateDummyGitProject("project2", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{"origin": "originremote"}, attributes.Attributes{}),
159 },
160 },
161 {
162 name: "Invalid Project with multiple remotes but no checkoutfrom",
163 projects: []v1alpha2.Project{
164 generateDummyGitProject("project2", nil, map[string]string{"origin": "originremote", "test": "testremote"}, attributes.Attributes{}),
165 },
166 wantErr: []string{missingCheckOutFromRemoteErr},
167 },
168 {
169 name: "Invalid Project with multiple remote and empty checkout remote",
170 projects: []v1alpha2.Project{
171 generateDummyGitProject("project2", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{"origin": "originremote"}, attributes.Attributes{}),
172 generateDummyGitProject("project1", &v1alpha2.CheckoutFrom{Remote: ""}, map[string]string{"origin": "originremote", "test": "testremote"}, attributes.Attributes{}),
173 },
174 wantErr: []string{missingCheckOutFromRemoteErr},
175 },
176 {
177 name: "Invalid Project with wrong checkout",
178 projects: []v1alpha2.Project{
179 generateDummyGitProject("project1", &v1alpha2.CheckoutFrom{Remote: "origin1"}, map[string]string{"origin": "originremote", "test": "testremote"}, attributes.Attributes{}),
180 },
181 wantErr: []string{wrongCheckoutErr},
182 },
183 {
184 name: "Valid Project with empty checkout remote",
185 projects: []v1alpha2.Project{
186 generateDummyGitProject("project1", &v1alpha2.CheckoutFrom{Remote: ""}, map[string]string{"origin": "originremote"}, attributes.Attributes{}),
187 },
188 },
189 {
190 name: "Multiple errors: invalid Project with empty remotes, invalid Project with wrong checkout",
191 projects: []v1alpha2.Project{
192 generateDummyGitProject("project1", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{}, attributes.Attributes{}),
193 generateDummyGitProject("project2", &v1alpha2.CheckoutFrom{Remote: "origins"}, map[string]string{"origin": "originremote", "test": "testremote"}, attributes.Attributes{}),
194 },
195 wantErr: []string{atleastOneRemoteErr, wrongCheckoutErr},
196 },

Callers

nothing calls this directly

Calls 4

generateDummyGitProjectFunction · 0.85
ValidateProjectsFunction · 0.85
PutStringMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected