Skip to content

Commit 4879efb

Browse files
committed
Updated get func test check
Signed-off-by: Maysun J Faisal <[email protected]>
1 parent 9b136b9 commit 4879efb

File tree

3 files changed

+21
-53
lines changed

3 files changed

+21
-53
lines changed

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

+5-13
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,12 @@ func TestDevfile200_GetCommands(t *testing.T) {
185185
t.Errorf("TestDevfile200_GetCommands() error = %v, wantErr %v", err, tt.wantErr)
186186
return
187187
} else if err == nil {
188-
assert.Equal(t, len(tt.wantCommands), len(commands), "expected length not the same as returned length")
189-
190-
for _, devfileCommand := range commands {
191-
matched := false
192-
for _, wantCommand := range tt.wantCommands {
193-
if wantCommand == devfileCommand.Id {
194-
matched = true
195-
}
196-
}
197-
198-
if !matched {
199-
t.Errorf("TestDevfile200_GetCommands() error - command %s not found in the expected list", devfileCommand.Id)
200-
}
188+
var gotCommands []string
189+
for _, command := range commands {
190+
gotCommands = append(gotCommands, command.Id)
201191
}
192+
193+
assert.Equal(t, tt.wantCommands, gotCommands, "expected commands not the same as returned commands")
202194
}
203195
})
204196
}

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

+5-13
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,12 @@ func TestGetDevfileComponents(t *testing.T) {
310310
t.Errorf("TestGetDevfileComponents() error = %v, wantErr %v", err, tt.wantErr)
311311
return
312312
} else if err == nil {
313-
assert.Equal(t, len(tt.wantComponents), len(components), "expected length not the same as returned length")
314-
315-
for _, devfileComponent := range components {
316-
matched := false
317-
for _, wantComponent := range tt.wantComponents {
318-
if wantComponent == devfileComponent.Name {
319-
matched = true
320-
}
321-
}
322-
323-
if !matched {
324-
t.Errorf("TestGetDevfileComponents() error - component %s not found in the expected list", devfileComponent.Name)
325-
}
313+
var gotComponents []string
314+
for _, component := range components {
315+
gotComponents = append(gotComponents, component.Name)
326316
}
317+
318+
assert.Equal(t, tt.wantComponents, gotComponents, "expected components not the same as returned components")
327319
}
328320
})
329321
}

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

+11-27
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,12 @@ func TestDevfile200_GetProjects(t *testing.T) {
146146
t.Errorf("TestDevfile200_GetProjects() error = %v, wantErr %v", err, tt.wantErr)
147147
return
148148
} else if err == nil {
149-
assert.Equal(t, len(tt.wantProjects), len(projects), "expected length not the same as returned length")
150-
151-
for _, devfileProject := range projects {
152-
matched := false
153-
for _, wantProject := range tt.wantProjects {
154-
if wantProject == devfileProject.Name {
155-
matched = true
156-
}
157-
}
158-
159-
if !matched {
160-
t.Errorf("TestDevfile200_GetProjects() error - project %s not found in the expected list", devfileProject.Name)
161-
}
149+
var gotProjects []string
150+
for _, project := range projects {
151+
gotProjects = append(gotProjects, project.Name)
162152
}
153+
154+
assert.Equal(t, tt.wantProjects, gotProjects, "expected projects not the same as returned projects")
163155
}
164156
})
165157
}
@@ -531,25 +523,17 @@ func TestDevfile200_GetStarterProjects(t *testing.T) {
531523
},
532524
}
533525

534-
projects, err := d.GetStarterProjects(tt.filterOptions)
526+
starterProjects, err := d.GetStarterProjects(tt.filterOptions)
535527
if (err != nil) != tt.wantErr {
536528
t.Errorf("TestDevfile200_GetStarterProjects() error = %v, wantErr %v", err, tt.wantErr)
537529
return
538530
} else if err == nil {
539-
assert.Equal(t, len(tt.wantStarterProjects), len(projects), "expected length not the same as returned length")
540-
541-
for _, devfileProject := range projects {
542-
matched := false
543-
for _, wantProject := range tt.wantStarterProjects {
544-
if wantProject == devfileProject.Name {
545-
matched = true
546-
}
547-
}
548-
549-
if !matched {
550-
t.Errorf("TestDevfile200_GetStarterProjects() error - project %s not found in the expected list", devfileProject.Name)
551-
}
531+
var gotStarterProjects []string
532+
for _, starterProject := range starterProjects {
533+
gotStarterProjects = append(gotStarterProjects, starterProject.Name)
552534
}
535+
536+
assert.Equal(t, tt.wantStarterProjects, gotStarterProjects, "expected starter projects not the same as returned starter projects")
553537
}
554538
})
555539
}

0 commit comments

Comments
 (0)