Skip to content

Commit 329c600

Browse files
committed
Cleanup of interface funcs
Signed-off-by: Maysun J Faisal <[email protected]>
1 parent b17b135 commit 329c600

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed

pkg/devfile/parser/data/interface.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type DevfileData interface {
4242

4343
// command related methods
4444
GetCommands(common.DevfileOptions) ([]v1.Command, error)
45-
AddCommands(commands ...v1.Command) error
45+
AddCommands(commands []v1.Command) error
4646
UpdateCommand(command v1.Command)
4747
DeleteCommand(id string) error
4848

pkg/devfile/parser/data/v2/commands.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@ func (d *DevfileV2) GetCommands(options common.DevfileOptions) ([]v1.Command, er
3131

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

4036
for _, command := range commands {
41-
for _, devfileCommand := range devfileCommands {
37+
for _, devfileCommand := range d.Commands {
4238
if command.Id == devfileCommand.Id {
4339
return &common.FieldAlreadyExistError{Name: command.Id, Field: "command"}
4440
}

pkg/devfile/parser/data/v2/commands_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func TestDevfile200_AddCommands(t *testing.T) {
217217
},
218218
}
219219

220-
got := d.AddCommands(tt.newCommands...)
220+
got := d.AddCommands(tt.newCommands)
221221
if !tt.wantErr && got != nil {
222222
t.Errorf("TestDevfile200_AddCommands() unexpected error - %v", got)
223223
} else if tt.wantErr && got == nil {

pkg/devfile/parser/data/v2/components.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,13 @@ func (d *DevfileV2) GetDevfileVolumeComponents(options common.DevfileOptions) ([
6060
// if a component is already defined, error out
6161
func (d *DevfileV2) AddComponents(components []v1.Component) error {
6262

63-
componentMap := make(map[string]bool)
64-
65-
for _, component := range d.Components {
66-
componentMap[component.Name] = true
67-
}
6863
for _, component := range components {
69-
if _, ok := componentMap[component.Name]; !ok {
70-
d.Components = append(d.Components, component)
71-
} else {
72-
return &common.FieldAlreadyExistError{Name: component.Name, Field: "component"}
64+
for _, devfileComponent := range d.Components {
65+
if component.Name == devfileComponent.Name {
66+
return &common.FieldAlreadyExistError{Name: component.Name, Field: "component"}
67+
}
7368
}
69+
d.Components = append(d.Components, component)
7470
}
7571
return nil
7672
}

tests/v2/utils/command_test_utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func (devfile *TestDevfile) commandAdded(command schema.Command) {
1616
LogInfoMessage(fmt.Sprintf("command added Id: %s", command.Id))
1717
devfile.SchemaDevFile.Commands = append(devfile.SchemaDevFile.Commands, command)
18-
devfile.ParserData.AddCommands(command)
18+
devfile.ParserData.AddCommands([]schema.Command{command})
1919
}
2020

2121
// commandUpdated updates a command in the parser data

0 commit comments

Comments
 (0)