Skip to content

Commit

Permalink
Update filtered test
Browse files Browse the repository at this point in the history
Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
  • Loading branch information
maysunfaisal committed Jun 7, 2021
1 parent 5a2ea56 commit 0caeed9
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion pkg/devfile/generator/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestGetContainers(t *testing.T) {
tests := []struct {
name string
containerComponents []v1.Component
filteredComponents []v1.Component
filterOptions common.DevfileOptions
wantContainerName string
wantContainerImage string
Expand Down Expand Up @@ -149,6 +150,17 @@ func TestGetContainers(t *testing.T) {
{
name: "Filter containers",
containerComponents: []v1.Component{
{
Name: containerNames[0],
ComponentUnion: v1.ComponentUnion{
Container: &v1.ContainerComponent{
Container: v1.Container{
Image: containerImages[0],
MountSources: &falseMountSources,
},
},
},
},
{
Name: containerNames[1],
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
Expand All @@ -167,6 +179,23 @@ func TestGetContainers(t *testing.T) {
},
wantContainerName: containerNames[1],
wantContainerImage: containerImages[0],
filteredComponents: []v1.Component{
{
Name: containerNames[1],
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
"firstString": "firstStringValue",
"thirdString": "thirdStringValue",
}),
ComponentUnion: v1.ComponentUnion{
Container: &v1.ContainerComponent{
Container: v1.Container{
Image: containerImages[0],
MountSources: &falseMountSources,
},
},
},
},
},
filterOptions: common.DevfileOptions{
Filter: map[string]interface{}{
"firstString": "firstStringValue",
Expand All @@ -182,7 +211,11 @@ func TestGetContainers(t *testing.T) {
mockDevfileData := data.NewMockDevfileData(ctrl)

// set up the mock data
mockDevfileData.EXPECT().GetDevfileContainerComponents(tt.filterOptions).Return(tt.containerComponents, nil).AnyTimes()
if len(tt.filterOptions.Filter) == 0 {
mockDevfileData.EXPECT().GetDevfileContainerComponents(tt.filterOptions).Return(tt.containerComponents, nil).AnyTimes()
} else {
mockDevfileData.EXPECT().GetDevfileContainerComponents(tt.filterOptions).Return(tt.filteredComponents, nil).AnyTimes()
}
mockDevfileData.EXPECT().GetProjects(common.DevfileOptions{}).Return(projects, nil).AnyTimes()

devObj := parser.DevfileObj{
Expand Down

0 comments on commit 0caeed9

Please sign in to comment.