Skip to content

Commit 55a1b83

Browse files
committed
Update Feedback for test 2
Signed-off-by: Maysun J Faisal <[email protected]>
1 parent 9b136b9 commit 55a1b83

File tree

4 files changed

+103
-42
lines changed

4 files changed

+103
-42
lines changed

pkg/devfile/parser/data/v2/commands.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ func (d *DevfileV2) GetCommands(options common.DevfileOptions) ([]v1.Command, er
3636

3737
// Filter Command Group Kind - Run, Build, etc.
3838
commandGroup := common.GetGroup(command)
39-
if commandGroup != nil && options.CommandOptions.CommandGroupKind != "" && options.CommandOptions.CommandGroupKind != commandGroup.Kind {
40-
continue
41-
} else if commandGroup == nil && options.CommandOptions.CommandGroupKind != "" {
39+
// exclude conditions:
40+
// 1. options group is present and command group is present but does not match
41+
// 2. options group is present and command group is not present
42+
if options.CommandOptions.CommandGroupKind != "" && ((commandGroup != nil && options.CommandOptions.CommandGroupKind != commandGroup.Kind) || commandGroup == nil) {
4243
continue
4344
}
4445

pkg/devfile/parser/data/v2/commands_test.go

+33-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestDevfile200_GetCommands(t *testing.T) {
2020
wantErr bool
2121
}{
2222
{
23-
name: "Get the necessary commands",
23+
name: "Get all the commands",
2424
currentCommands: []v1.Command{
2525
{
2626
Id: "command1",
@@ -35,9 +35,8 @@ func TestDevfile200_GetCommands(t *testing.T) {
3535
},
3636
},
3737
},
38-
filterOptions: common.DevfileOptions{},
39-
wantCommands: []string{"command1", "command2"},
40-
wantErr: false,
38+
wantCommands: []string{"command1", "command2"},
39+
wantErr: false,
4140
},
4241
{
4342
name: "Get the filtered commands",
@@ -105,6 +104,24 @@ func TestDevfile200_GetCommands(t *testing.T) {
105104
},
106105
},
107106
},
107+
{
108+
Id: "command5",
109+
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
110+
"firstString": "firstStringValue",
111+
"thirdString": "thirdStringValue",
112+
}),
113+
CommandUnion: v1.CommandUnion{
114+
Composite: &v1.CompositeCommand{
115+
LabeledCommand: v1.LabeledCommand{
116+
BaseCommand: v1.BaseCommand{
117+
Group: &v1.CommandGroup{
118+
Kind: v1.RunCommandGroupKind,
119+
},
120+
},
121+
},
122+
},
123+
},
124+
},
108125
},
109126
filterOptions: common.DevfileOptions{
110127
Filter: map[string]interface{}{
@@ -119,7 +136,7 @@ func TestDevfile200_GetCommands(t *testing.T) {
119136
wantErr: false,
120137
},
121138
{
122-
name: "Get the wrong filtered commands",
139+
name: "Wrong filter for commands",
123140
currentCommands: []v1.Command{
124141
{
125142
Id: "command1",
@@ -150,7 +167,7 @@ func TestDevfile200_GetCommands(t *testing.T) {
150167
wantErr: false,
151168
},
152169
{
153-
name: "Wrong command type",
170+
name: "Invalid command type",
154171
currentCommands: []v1.Command{
155172
{
156173
Id: "command1",
@@ -183,20 +200,24 @@ func TestDevfile200_GetCommands(t *testing.T) {
183200
commands, err := d.GetCommands(tt.filterOptions)
184201
if (err != nil) != tt.wantErr {
185202
t.Errorf("TestDevfile200_GetCommands() error = %v, wantErr %v", err, tt.wantErr)
186-
return
187203
} else if err == nil {
188-
assert.Equal(t, len(tt.wantCommands), len(commands), "expected length not the same as returned length")
204+
// confirm the length of actual vs expected
205+
if len(commands) != len(tt.wantCommands) {
206+
t.Errorf("TestDevfile200_GetCommands() error - length of expected commands is not the same as the length of actual commands")
207+
return
208+
}
189209

190-
for _, devfileCommand := range commands {
210+
// compare the command slices for content
211+
for _, wantCommand := range tt.wantCommands {
191212
matched := false
192-
for _, wantCommand := range tt.wantCommands {
193-
if wantCommand == devfileCommand.Id {
213+
for _, command := range commands {
214+
if wantCommand == command.Id {
194215
matched = true
195216
}
196217
}
197218

198219
if !matched {
199-
t.Errorf("TestDevfile200_GetCommands() error - command %s not found in the expected list", devfileCommand.Id)
220+
t.Errorf("TestDevfile200_GetCommands() error - command %s not found in the devfile", wantCommand)
200221
}
201222
}
202223
}

pkg/devfile/parser/data/v2/components_test.go

+38-8
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,32 @@ func TestGetDevfileComponents(t *testing.T) {
183183
name: "Invalid devfile",
184184
component: []v1.Component{},
185185
},
186+
{
187+
name: "Get all the components",
188+
component: []v1.Component{
189+
{
190+
Name: "comp1",
191+
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
192+
"firstString": "firstStringValue",
193+
"secondString": "secondStringValue",
194+
}),
195+
ComponentUnion: v1.ComponentUnion{
196+
Container: &v1.ContainerComponent{},
197+
},
198+
},
199+
{
200+
Name: "comp2",
201+
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
202+
"firstString": "firstStringValue",
203+
"fourthString": "fourthStringValue",
204+
}),
205+
ComponentUnion: v1.ComponentUnion{
206+
Volume: &v1.VolumeComponent{},
207+
},
208+
},
209+
},
210+
wantComponents: []string{"comp1", "comp2"},
211+
},
186212
{
187213
name: "Get component with the specified filter",
188214
component: []v1.Component{
@@ -241,7 +267,7 @@ func TestGetDevfileComponents(t *testing.T) {
241267
wantComponents: []string{"comp3"},
242268
},
243269
{
244-
name: "Get component with the wrong specified filter",
270+
name: "Wrong filter for component",
245271
component: []v1.Component{
246272
{
247273
Name: "comp1",
@@ -275,7 +301,7 @@ func TestGetDevfileComponents(t *testing.T) {
275301
wantErr: false,
276302
},
277303
{
278-
name: "Wrong component type",
304+
name: "Invalid component type",
279305
component: []v1.Component{
280306
{
281307
Name: "comp1",
@@ -308,20 +334,24 @@ func TestGetDevfileComponents(t *testing.T) {
308334
components, err := d.GetComponents(tt.filterOptions)
309335
if (err != nil) != tt.wantErr {
310336
t.Errorf("TestGetDevfileComponents() error = %v, wantErr %v", err, tt.wantErr)
311-
return
312337
} else if err == nil {
313-
assert.Equal(t, len(tt.wantComponents), len(components), "expected length not the same as returned length")
338+
// confirm the length of actual vs expected
339+
if len(components) != len(tt.wantComponents) {
340+
t.Errorf("TestGetDevfileComponents() error - length of expected components is not the same as the length of actual components")
341+
return
342+
}
314343

315-
for _, devfileComponent := range components {
344+
// compare the component slices for content
345+
for _, wantComponent := range tt.wantComponents {
316346
matched := false
317-
for _, wantComponent := range tt.wantComponents {
318-
if wantComponent == devfileComponent.Name {
347+
for _, component := range components {
348+
if wantComponent == component.Name {
319349
matched = true
320350
}
321351
}
322352

323353
if !matched {
324-
t.Errorf("TestGetDevfileComponents() error - component %s not found in the expected list", devfileComponent.Name)
354+
t.Errorf("TestGetDevfileComponents() error - component %s not found in the devfile", wantComponent)
325355
}
326356
}
327357
}

pkg/devfile/parser/data/v2/projects_test.go

+28-19
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestDevfile200_GetProjects(t *testing.T) {
2121
wantErr bool
2222
}{
2323
{
24-
name: "Get the necessary projects",
24+
name: "Get all the projects",
2525
currentProjects: []v1.Project{
2626
{
2727
Name: "project1",
@@ -78,7 +78,7 @@ func TestDevfile200_GetProjects(t *testing.T) {
7878
wantErr: false,
7979
},
8080
{
81-
name: "Get the wrong filtered projects",
81+
name: "Wrong filter for projects",
8282
currentProjects: []v1.Project{
8383
{
8484
Name: "project1",
@@ -111,7 +111,7 @@ func TestDevfile200_GetProjects(t *testing.T) {
111111
wantErr: false,
112112
},
113113
{
114-
name: "Wrong project src type",
114+
name: "Invalid project src type",
115115
currentProjects: []v1.Project{
116116
{
117117
Name: "project1",
@@ -144,20 +144,24 @@ func TestDevfile200_GetProjects(t *testing.T) {
144144
projects, err := d.GetProjects(tt.filterOptions)
145145
if (err != nil) != tt.wantErr {
146146
t.Errorf("TestDevfile200_GetProjects() error = %v, wantErr %v", err, tt.wantErr)
147-
return
148147
} else if err == nil {
149-
assert.Equal(t, len(tt.wantProjects), len(projects), "expected length not the same as returned length")
148+
// confirm the length of actual vs expected
149+
if len(projects) != len(tt.wantProjects) {
150+
t.Errorf("TestDevfile200_GetProjects() error - length of expected projects is not the same as the length of actual projects")
151+
return
152+
}
150153

151-
for _, devfileProject := range projects {
154+
// compare the project slices for content
155+
for _, wantProject := range tt.wantProjects {
152156
matched := false
153-
for _, wantProject := range tt.wantProjects {
154-
if wantProject == devfileProject.Name {
157+
for _, project := range projects {
158+
if wantProject == project.Name {
155159
matched = true
156160
}
157161
}
158162

159163
if !matched {
160-
t.Errorf("TestDevfile200_GetProjects() error - project %s not found in the expected list", devfileProject.Name)
164+
t.Errorf("TestDevfile200_GetProjects() error - project %s not found in the devfile", wantProject)
161165
}
162166
}
163167
}
@@ -412,7 +416,7 @@ func TestDevfile200_GetStarterProjects(t *testing.T) {
412416
wantErr bool
413417
}{
414418
{
415-
name: "Get the necessary projects",
419+
name: "Get all the starter projects",
416420
currentStarterProjects: []v1.StarterProject{
417421
{
418422
Name: "project1",
@@ -470,7 +474,7 @@ func TestDevfile200_GetStarterProjects(t *testing.T) {
470474
wantErr: false,
471475
},
472476
{
473-
name: "Get the wrong filtered starter projects",
477+
name: "Wrong filter for starter projects",
474478
currentStarterProjects: []v1.StarterProject{
475479
{
476480
Name: "project1",
@@ -501,7 +505,7 @@ func TestDevfile200_GetStarterProjects(t *testing.T) {
501505
wantErr: false,
502506
},
503507
{
504-
name: "Wrong starter project src type",
508+
name: "Invalid starter project src type",
505509
currentStarterProjects: []v1.StarterProject{
506510
{
507511
Name: "project1",
@@ -531,23 +535,28 @@ func TestDevfile200_GetStarterProjects(t *testing.T) {
531535
},
532536
}
533537

534-
projects, err := d.GetStarterProjects(tt.filterOptions)
538+
starterProjects, err := d.GetStarterProjects(tt.filterOptions)
535539
if (err != nil) != tt.wantErr {
536540
t.Errorf("TestDevfile200_GetStarterProjects() error = %v, wantErr %v", err, tt.wantErr)
537-
return
538541
} else if err == nil {
539-
assert.Equal(t, len(tt.wantStarterProjects), len(projects), "expected length not the same as returned length")
542+
// confirm the length of actual vs expected
543+
if len(starterProjects) != len(tt.wantStarterProjects) {
544+
t.Errorf("TestDevfile200_GetStarterProjects() error - length of expected starter projects is not the same as the length of actual starter projects")
545+
return
546+
}
540547

541-
for _, devfileProject := range projects {
548+
// compare the starter project slices for content
549+
for _, wantProject := range tt.wantStarterProjects {
542550
matched := false
543-
for _, wantProject := range tt.wantStarterProjects {
544-
if wantProject == devfileProject.Name {
551+
552+
for _, starterProject := range starterProjects {
553+
if wantProject == starterProject.Name {
545554
matched = true
546555
}
547556
}
548557

549558
if !matched {
550-
t.Errorf("TestDevfile200_GetStarterProjects() error - project %s not found in the expected list", devfileProject.Name)
559+
t.Errorf("TestDevfile200_GetStarterProjects() error - starter project %s not found in the devfile", wantProject)
551560
}
552561
}
553562
}

0 commit comments

Comments
 (0)