Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add name filter #130

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/devfile/parser/data/v2/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func (d *DevfileV2) GetCommands(options common.DevfileOptions) ([]v1.Command, er
continue
}

commands = append(commands, command)
if options.FilterByName == "" || command.Id == options.FilterByName {
commands = append(commands, command)
}
}

return commands, nil
Expand Down
48 changes: 48 additions & 0 deletions pkg/devfile/parser/data/v2/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,54 @@ func TestDevfile200_GetCommands(t *testing.T) {
},
wantCommands: []string{"command3"},
},
{
name: "Get command with the specified name",
currentCommands: []v1.Command{
{
Id: "command1",
CommandUnion: v1.CommandUnion{
Exec: &v1.ExecCommand{},
},
},
{
Id: "command2",
CommandUnion: v1.CommandUnion{
Composite: &v1.CompositeCommand{},
},
},
{
Id: "command3",
CommandUnion: v1.CommandUnion{
Composite: &v1.CompositeCommand{},
},
},
},
filterOptions: common.DevfileOptions{
FilterByName: "command3",
},
wantCommands: []string{"command3"},
},
{
name: "command name not found",
currentCommands: []v1.Command{
{
Id: "command1",
CommandUnion: v1.CommandUnion{
Exec: &v1.ExecCommand{},
},
},
{
Id: "command2",
CommandUnion: v1.CommandUnion{
Composite: &v1.CompositeCommand{},
},
},
},
filterOptions: common.DevfileOptions{
FilterByName: "command3",
},
wantCommands: []string{},
},
{
name: "Wrong filter for commands",
currentCommands: []v1.Command{
Expand Down
3 changes: 3 additions & 0 deletions pkg/devfile/parser/data/v2/common/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type DevfileOptions struct {

// ProjectOptions specifies the various options available to filter projects/starterProjects
ProjectOptions ProjectOptions

// FilterByName specifies the name for the particular devfile object that's been looking for
FilterByName string
}

// CommandOptions specifies the various options available to filter commands
Expand Down
4 changes: 3 additions & 1 deletion pkg/devfile/parser/data/v2/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func (d *DevfileV2) GetComponents(options common.DevfileOptions) ([]v1.Component
continue
}

components = append(components, component)
if options.FilterByName == "" || component.Name == options.FilterByName {
components = append(components, component)
}
}

return components, nil
Expand Down
48 changes: 48 additions & 0 deletions pkg/devfile/parser/data/v2/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,54 @@ func TestGetDevfileComponents(t *testing.T) {
},
wantComponents: []string{"comp3"},
},
{
name: "Get component with the specified name",
component: []v1.Component{
{
Name: "comp1",
ComponentUnion: v1.ComponentUnion{
Container: &v1.ContainerComponent{},
},
},
{
Name: "comp2",
ComponentUnion: v1.ComponentUnion{
Container: &v1.ContainerComponent{},
},
},
{
Name: "comp3",
ComponentUnion: v1.ComponentUnion{
Volume: &v1.VolumeComponent{},
},
},
},
filterOptions: common.DevfileOptions{
FilterByName: "comp3",
},
wantComponents: []string{"comp3"},
},
{
name: "component name not found",
component: []v1.Component{
{
Name: "comp1",
ComponentUnion: v1.ComponentUnion{
Container: &v1.ContainerComponent{},
},
},
{
Name: "comp2",
ComponentUnion: v1.ComponentUnion{
Container: &v1.ContainerComponent{},
},
},
},
filterOptions: common.DevfileOptions{
FilterByName: "comp3",
},
wantComponents: []string{},
},
{
name: "Wrong filter for component",
component: []v1.Component{
Expand Down
9 changes: 6 additions & 3 deletions pkg/devfile/parser/data/v2/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func (d *DevfileV2) GetProjects(options common.DevfileOptions) ([]v1.Project, er
if options.ProjectOptions.ProjectSourceType != "" && projectSourceType != options.ProjectOptions.ProjectSourceType {
continue
}

projects = append(projects, project)
if options.FilterByName == "" || project.Name == options.FilterByName {
projects = append(projects, project)
}
}

return projects, nil
Expand Down Expand Up @@ -118,7 +119,9 @@ func (d *DevfileV2) GetStarterProjects(options common.DevfileOptions) ([]v1.Star
continue
}

starterProjects = append(starterProjects, starterProject)
if options.FilterByName == "" || starterProject.Name == options.FilterByName {
starterProjects = append(starterProjects, starterProject)
}
}

return starterProjects, nil
Expand Down
84 changes: 84 additions & 0 deletions pkg/devfile/parser/data/v2/projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,48 @@ func TestDevfile200_GetProjects(t *testing.T) {
},
wantProjects: []string{"project1"},
},
{
name: "Get project with the specified name",
currentProjects: []v1.Project{
{
Name: "project1",
ProjectSource: v1.ProjectSource{
Git: &v1.GitProjectSource{},
},
},
{
Name: "project2",
ProjectSource: v1.ProjectSource{
Zip: &v1.ZipProjectSource{},
},
},
},
filterOptions: common.DevfileOptions{
FilterByName: "project2",
},
wantProjects: []string{"project2"},
},
{
name: "project name not found",
currentProjects: []v1.Project{
{
Name: "project1",
ProjectSource: v1.ProjectSource{
Git: &v1.GitProjectSource{},
},
},
{
Name: "project2",
ProjectSource: v1.ProjectSource{
Zip: &v1.ZipProjectSource{},
},
},
},
filterOptions: common.DevfileOptions{
FilterByName: "project3",
},
wantProjects: []string{},
},
{
name: "Wrong filter for projects",
currentProjects: []v1.Project{
Expand Down Expand Up @@ -493,6 +535,48 @@ func TestDevfile200_GetStarterProjects(t *testing.T) {
},
wantStarterProjects: []string{"project1", "project3"},
},
{
name: "Get starter project with specified name",
currentStarterProjects: []v1.StarterProject{
{
Name: "project1",
ProjectSource: v1.ProjectSource{
Git: &v1.GitProjectSource{},
},
},
{
Name: "project2",
ProjectSource: v1.ProjectSource{
Zip: &v1.ZipProjectSource{},
},
},
},
filterOptions: common.DevfileOptions{
FilterByName: "project2",
},
wantStarterProjects: []string{"project2"},
},
{
name: "starter project name not found",
currentStarterProjects: []v1.StarterProject{
{
Name: "project1",
ProjectSource: v1.ProjectSource{
Git: &v1.GitProjectSource{},
},
},
{
Name: "project2",
ProjectSource: v1.ProjectSource{
Zip: &v1.ZipProjectSource{},
},
},
},
filterOptions: common.DevfileOptions{
FilterByName: "project3",
},
wantStarterProjects: []string{},
},
{
name: "Wrong filter for starter projects",
currentStarterProjects: []v1.StarterProject{
Expand Down