Update Devfile Library Get Options#71
Conversation
Signed-off-by: Maysun J Faisal <[email protected]>
Signed-off-by: Maysun J Faisal <[email protected]>
Signed-off-by: Maysun J Faisal <[email protected]>
| continue | ||
| } | ||
|
|
||
| command.Id = strings.ToLower(command.Id) |
There was a problem hiding this comment.
the toLower should be removed, as Id is restricted to be lower case
| func (d *DevfileV2) GetCommands(options common.DevfileOptions) ([]v1.Command, error) { | ||
| if len(options.Filter) == 0 { | ||
| return d.Commands, nil | ||
| } |
There was a problem hiding this comment.
why remove this block?
can be reflect.DeepEqual(options, common.DevfileOptions{})
same for the other Get functions
|
|
||
| // Filter Command Group Kind - Run, Build, etc. | ||
| commandGroup := common.GetGroup(command) | ||
| if commandGroup != nil && options.CommandOptions.CommandGroupKind != "" && options.CommandOptions.CommandGroupKind != commandGroup.Kind { |
There was a problem hiding this comment.
| if commandGroup != nil && options.CommandOptions.CommandGroupKind != "" && options.CommandOptions.CommandGroupKind != commandGroup.Kind { | |
| if options.CommandOptions.CommandGroupKind != "" && options.CommandOptions.CommandGroupKind != commandGroup.Kind { | |
| continue | |
| } |
There was a problem hiding this comment.
commandGroup is a pointer acc to the schema struct
There was a problem hiding this comment.
commandGroup != nil or commandGroup == nil doesn't matter in this case
this if&else block can be combined in the one I suggested
There was a problem hiding this comment.
Command Group can be nil which is when no command group is mentioned in the devfile. So, we definitely need to check commandGroup != nil because the condition checks commandGroup.Kind, otherwise it will panic:
I've updated the if-else condition to one if condition and added comment for the exclusion cases:
| matched = true | ||
| matched := false | ||
| for _, wantCommand := range tt.wantCommands { | ||
| if wantCommand == devfileCommand.Id { |
There was a problem hiding this comment.
this check only works when len(commands) > len(wantCommands), and commands contains wantCommands
won't work if len(wantCommands) > len(commands) and wantCommands contains all elements in commands
do we have a better way to check??
same for getComponents & getProjects unit tests
There was a problem hiding this comment.
wantCommands is always a subset of commands. commands is all the devfile commands & wantCommands is whatever we want from that list (commands/devfile commands), so wantCommands can be everything or a subset depending on DevfileOptions.
it works fine when wantCommands == commands which means there is no filter or filter returned everything and this is test case number 1 by default for all the Get functions
{
name: "Get the necessary commands",
currentCommands: []v1.Command{
{
Id: "command1",
CommandUnion: v1.CommandUnion{
Exec: &v1.ExecCommand{},
},
},
{
Id: "command2",
CommandUnion: v1.CommandUnion{
Composite: &v1.CompositeCommand{},
},
},
},
filterOptions: common.DevfileOptions{},
wantCommands: []string{"command1", "command2"},
wantErr: false,
},
There was a problem hiding this comment.
I think the other way of doing it would be:
var gotCommands []string
for _, command := range commands {
gotCommands = append(gotCommands, command.Id)
}
assert.Equal(t, tt.wantCommands, gotCommands, "expected cmds not the same as returned cmds")
I made this change in the latest commit which is cleaner
There was a problem hiding this comment.
I did't get it. commands is not all the devfile commands, it is filtered commands as it was defined by
commands, err := d.GetCommands(tt.filterOptions)
If the filter does not function as expected, there is case that the filtered commands contains more element than wantCommands
And I don't think you can do assert.Equal to compare wantCommands and gotCommands, since slice in golang is a struct with order. I did not try, but I would expect different element order will be considered as NotEqual in golang.
There was a problem hiding this comment.
updated, I check length before looping thru and return when there is a length mismatch.
|
|
||
| } | ||
|
|
||
| // GetProjectSourceType returns the source type of a given project |
There was a problem hiding this comment.
| // GetProjectSourceType returns the source type of a given project | |
| // GetProjectSourceType returns the source type of a given project source |
| } | ||
|
|
||
| // GetDevfileContainerComponents iterates through the components in the devfile and returns a list of devfile container components | ||
| // GetDevfileContainerComponents iterates through the components in the devfile and returns a list of devfile container components. Deprecated, use GetComponents() with the DevfileOptions. |
There was a problem hiding this comment.
switch a new line?
| // GetDevfileContainerComponents iterates through the components in the devfile and returns a list of devfile container components. Deprecated, use GetComponents() with the DevfileOptions. | |
| // GetDevfileContainerComponents iterates through the components in the devfile and returns a list of devfile container components. | |
| // Deprecated, use GetComponents() with the DevfileOptions. |
| } | ||
|
|
||
| // GetDevfileVolumeComponents iterates through the components in the devfile and returns a list of devfile volume components | ||
| // GetDevfileVolumeComponents iterates through the components in the devfile and returns a list of devfile volume components. Deprecated, use GetComponents() with the DevfileOptions. |
There was a problem hiding this comment.
switch a new line?
| // GetDevfileVolumeComponents iterates through the components in the devfile and returns a list of devfile volume components. Deprecated, use GetComponents() with the DevfileOptions. | |
| // GetDevfileVolumeComponents iterates through the components in the devfile and returns a list of devfile volume components. | |
| // Deprecated, use GetComponents() with the DevfileOptions. |
Signed-off-by: Maysun J Faisal <[email protected]>
Signed-off-by: Maysun J Faisal <[email protected]>
yangcao77
left a comment
There was a problem hiding this comment.
changes look good to me
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: maysunfaisal, yangcao77 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |


What does this PR do?
Rather than having individual get funcs for different devfile objects like -
GetDevfileContainerComponents(),GetDevfileVolumeComponents(), etc.;GetComponents(common.DevfileOptions)allowsDevfileOptionsto specify various options to filter:What issues does this PR fix or reference?
Fixes devfile/api#373
Is your PR tested? Consider putting some instruction how to test your changes
yes, new tests