Skip to content

Commit 9d476bc

Browse files
committed
Fix validation tests to not include GitHub projects
Signed-off-by: Angel Misevski <[email protected]>
1 parent 06d8128 commit 9d476bc

File tree

3 files changed

+13
-49
lines changed

3 files changed

+13
-49
lines changed

Diff for: pkg/validation/projects.go

-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ func ValidateStarterProjects(starterProjects []v1alpha2.StarterProject) error {
1616
var gitSource v1alpha2.GitLikeProjectSource
1717
if starterProject.Git != nil {
1818
gitSource = starterProject.Git.GitLikeProjectSource
19-
} else if starterProject.Github != nil {
20-
gitSource = starterProject.Github.GitLikeProjectSource
2119
} else {
2220
continue
2321
}
@@ -60,8 +58,6 @@ func ValidateProjects(projects []v1alpha2.Project) error {
6058
var gitSource v1alpha2.GitLikeProjectSource
6159
if project.Git != nil {
6260
gitSource = project.Git.GitLikeProjectSource
63-
} else if project.Github != nil {
64-
gitSource = project.Github.GitLikeProjectSource
6561
} else {
6662
continue
6763
}

Diff for: pkg/validation/projects_test.go

+11-38
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package validation
22

33
import (
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-
4027
func 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-
6942
func 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
},

Diff for: pkg/validation/variables/variables_project.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,8 @@ func validateandReplaceForProjectSource(variables map[string]string, projectSour
8989
if projectSource.Zip.Location, err = validateAndReplaceDataWithVariable(projectSource.Zip.Location, variables); err != nil {
9090
checkForInvalidError(invalidKeys, err)
9191
}
92-
case projectSource.Git != nil || projectSource.Github != nil:
93-
var gitProject *v1alpha2.GitLikeProjectSource
94-
if projectSource.Git != nil {
95-
gitProject = &projectSource.Git.GitLikeProjectSource
96-
} else if projectSource.Github != nil {
97-
gitProject = &projectSource.Github.GitLikeProjectSource
98-
}
92+
case projectSource.Git != nil:
93+
gitProject := &projectSource.Git.GitLikeProjectSource
9994

10095
if gitProject.CheckoutFrom != nil {
10196
// validate git checkout revision

0 commit comments

Comments
 (0)