@@ -7,9 +7,11 @@ import (
7
7
v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
8
8
"github.com/devfile/api/v2/pkg/attributes"
9
9
"github.com/devfile/library/pkg/devfile/parser"
10
+ "github.com/devfile/library/pkg/devfile/parser/data"
10
11
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
11
12
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
12
13
"github.com/devfile/library/pkg/testingutil"
14
+ "github.com/golang/mock/gomock"
13
15
14
16
corev1 "k8s.io/api/core/v1"
15
17
)
@@ -27,14 +29,16 @@ func TestGetContainers(t *testing.T) {
27
29
trueMountSources := true
28
30
falseMountSources := false
29
31
30
- project := v1.Project {
31
- ClonePath : "test-project/" ,
32
- Name : "project0" ,
33
- ProjectSource : v1.ProjectSource {
34
- Git : & v1.GitProjectSource {
35
- GitLikeProjectSource : v1.GitLikeProjectSource {
36
- Remotes : map [string ]string {
37
- "origin" : "repo" ,
32
+ projects := []v1.Project {
33
+ {
34
+ ClonePath : "test-project/" ,
35
+ Name : "project0" ,
36
+ ProjectSource : v1.ProjectSource {
37
+ Git : & v1.GitProjectSource {
38
+ GitLikeProjectSource : v1.GitLikeProjectSource {
39
+ Remotes : map [string ]string {
40
+ "origin" : "repo" ,
41
+ },
38
42
},
39
43
},
40
44
},
@@ -143,17 +147,6 @@ func TestGetContainers(t *testing.T) {
143
147
{
144
148
name : "Filter containers" ,
145
149
containerComponents : []v1.Component {
146
- {
147
- Name : containerNames [0 ],
148
- ComponentUnion : v1.ComponentUnion {
149
- Container : & v1.ContainerComponent {
150
- Container : v1.Container {
151
- Image : containerImages [0 ],
152
- MountSources : & falseMountSources ,
153
- },
154
- },
155
- },
156
- },
157
150
{
158
151
Name : containerNames [1 ],
159
152
Attributes : attributes.Attributes {}.FromStringMap (map [string ]string {
@@ -182,19 +175,16 @@ func TestGetContainers(t *testing.T) {
182
175
for _ , tt := range tests {
183
176
t .Run (tt .name , func (t * testing.T ) {
184
177
178
+ ctrl := gomock .NewController (t )
179
+ defer ctrl .Finish ()
180
+ mockDevfileData := data .NewMockDevfileData (ctrl )
181
+
182
+ // set up the mock data
183
+ mockDevfileData .EXPECT ().GetDevfileContainerComponents (tt .filterOptions ).Return (tt .containerComponents , nil ).AnyTimes ()
184
+ mockDevfileData .EXPECT ().GetProjects (common.DevfileOptions {}).Return (projects , nil ).AnyTimes ()
185
+
185
186
devObj := parser.DevfileObj {
186
- Data : & v2.DevfileV2 {
187
- Devfile : v1.Devfile {
188
- DevWorkspaceTemplateSpec : v1.DevWorkspaceTemplateSpec {
189
- DevWorkspaceTemplateSpecContent : v1.DevWorkspaceTemplateSpecContent {
190
- Components : tt .containerComponents ,
191
- Projects : []v1.Project {
192
- project ,
193
- },
194
- },
195
- },
196
- },
197
- },
187
+ Data : mockDevfileData ,
198
188
}
199
189
200
190
containers , err := GetContainers (devObj , tt .filterOptions )
0 commit comments