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

Function TestValidateStarterProjects

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

Source from the content-addressed store, hash-verified

57}
58
59func TestValidateStarterProjects(t *testing.T) {
60
61 oneRemoteErr := "starterProject .* should have one remote only"
62 wrongCheckoutErr := "unable to find the checkout remote .* in the remotes for starterProject.*"
63 atleastOneRemoteErr := "starterProject .* should have at least one remote"
64
65 parentOverridesFromMainDevfile := attributes.Attributes{}.PutString(ImportSourceAttribute,
66 "uri: http://127.0.0.1:8080").PutString(ParentOverrideAttribute, "main devfile")
67 wrongCheckoutErrWithImportAttributes := "unable to find the checkout remote .* in the remotes for starterProject.*, imported from uri: http://127.0.0.1:8080, in parent overrides from main devfile"
68
69 tests := []struct {
70 name string
71 starterProjects []v1alpha2.StarterProject
72 wantErr []string
73 }{
74 {
75 name: "Valid Starter Project",
76 starterProjects: []v1alpha2.StarterProject{
77 generateDummyGitStarterProject("project1", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{"origin": "originremote"}, attributes.Attributes{}),
78 generateDummyGitStarterProject("project2", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{"origin": "originremote2"}, attributes.Attributes{}),
79 },
80 },
81 {
82 name: "Invalid Starter Project",
83 starterProjects: []v1alpha2.StarterProject{
84 generateDummyGitStarterProject("project1", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{"origin": "originremote", "test": "testremote"}, attributes.Attributes{}),
85 },
86 wantErr: []string{oneRemoteErr},
87 },
88 {
89 name: "Invalid Starter Project with wrong checkout",
90 starterProjects: []v1alpha2.StarterProject{
91 generateDummyGitStarterProject("project1", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{"test": "testremote"}, attributes.Attributes{}),
92 },
93 wantErr: []string{wrongCheckoutErr},
94 },
95 {
96 name: "Valid Starter Project with empty checkout remote",
97 starterProjects: []v1alpha2.StarterProject{
98 generateDummyGitStarterProject("project1", &v1alpha2.CheckoutFrom{Remote: ""}, map[string]string{"origin": "originremote"}, attributes.Attributes{}),
99 },
100 },
101 {
102 name: "Valid Starter Project with no checkout remote",
103 starterProjects: []v1alpha2.StarterProject{
104 generateDummyGitStarterProject("project1", nil, map[string]string{"origin": "originremote"}, attributes.Attributes{}),
105 },
106 },
107 {
108 name: "Multiple errors: Starter Project with empty remotes, Starter Project with multiple remotes",
109 starterProjects: []v1alpha2.StarterProject{
110 generateDummyGitStarterProject("project1", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{}, attributes.Attributes{}),
111 generateDummyGitStarterProject("project3", &v1alpha2.CheckoutFrom{Remote: "origin"}, map[string]string{"origin": "originremote", "test": "testremote"}, attributes.Attributes{}),
112 },
113 wantErr: []string{atleastOneRemoteErr, oneRemoteErr},
114 },
115 {
116 name: "Invalid Starter Project due to wrong checkout with import source attributes",

Callers

nothing calls this directly

Calls 4

ValidateStarterProjectsFunction · 0.85
PutStringMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected