-
Notifications
You must be signed in to change notification settings - Fork 35
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the toLower
should be removed, as Id is restricted to be lower case
@@ -9,21 +9,36 @@ import ( | |||
|
|||
// GetCommands returns the slice of Command objects parsed from the Devfile | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commandGroup
is a pointer acc to the schema struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, I check length before looping thru and return when there is a length mismatch.
@@ -41,3 +41,20 @@ func GetDefaultSource(ps v1.GitLikeProjectSource) (remoteName string, remoteURL | |||
return remoteName, remoteURL, revision, err | |||
|
|||
} | |||
|
|||
// GetProjectSourceType returns the source type of a given project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// GetProjectSourceType returns the source type of a given project | |
// GetProjectSourceType returns the source type of a given project source |
} | ||
|
||
return components, nil | ||
} | ||
|
||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
@@ -41,7 +48,7 @@ func (d *DevfileV2) GetDevfileContainerComponents(options common.DevfileOptions) | |||
return components, nil | |||
} | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Needs 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)
allowsDevfileOptions
to 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