Skip to content

Commit

Permalink
Cleanup of interface funcs
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 Mar 1, 2021
1 parent b17b135 commit 6518216
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/devfile/parser/data/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type DevfileData interface {

// command related methods
GetCommands(common.DevfileOptions) ([]v1.Command, error)
AddCommands(commands ...v1.Command) error
AddCommands(commands []v1.Command) error
UpdateCommand(command v1.Command)
DeleteCommand(id string) error

Expand Down
8 changes: 2 additions & 6 deletions pkg/devfile/parser/data/v2/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ func (d *DevfileV2) GetCommands(options common.DevfileOptions) ([]v1.Command, er

// AddCommands adds the slice of Command objects to the Devfile's commands
// if a command is already defined, error out
func (d *DevfileV2) AddCommands(commands ...v1.Command) error {
devfileCommands, err := d.GetCommands(common.DevfileOptions{})
if err != nil {
return err
}
func (d *DevfileV2) AddCommands(commands []v1.Command) error {

for _, command := range commands {
for _, devfileCommand := range devfileCommands {
for _, devfileCommand := range d.Commands {
if command.Id == devfileCommand.Id {
return &common.FieldAlreadyExistError{Name: command.Id, Field: "command"}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/parser/data/v2/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestDevfile200_AddCommands(t *testing.T) {
},
}

got := d.AddCommands(tt.newCommands...)
got := d.AddCommands(tt.newCommands)
if !tt.wantErr && got != nil {
t.Errorf("TestDevfile200_AddCommands() unexpected error - %v", got)
} else if tt.wantErr && got == nil {
Expand Down
14 changes: 5 additions & 9 deletions pkg/devfile/parser/data/v2/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,13 @@ func (d *DevfileV2) GetDevfileVolumeComponents(options common.DevfileOptions) ([
// if a component is already defined, error out
func (d *DevfileV2) AddComponents(components []v1.Component) error {

componentMap := make(map[string]bool)

for _, component := range d.Components {
componentMap[component.Name] = true
}
for _, component := range components {
if _, ok := componentMap[component.Name]; !ok {
d.Components = append(d.Components, component)
} else {
return &common.FieldAlreadyExistError{Name: component.Name, Field: "component"}
for _, devfileComponent := range d.Components {
if component.Name == devfileComponent.Name {
return &common.FieldAlreadyExistError{Name: component.Name, Field: "component"}
}
}
d.Components = append(d.Components, component)
}
return nil
}
Expand Down

0 comments on commit 6518216

Please sign in to comment.