diff --git a/pkg/devfile/parser/data/interface.go b/pkg/devfile/parser/data/interface.go index eb0f72a8..250d8ecc 100644 --- a/pkg/devfile/parser/data/interface.go +++ b/pkg/devfile/parser/data/interface.go @@ -46,10 +46,10 @@ type DevfileData interface { UpdateCommand(command v1.Command) DeleteCommand(id string) error - // volume related methods - AddVolume(volume v1.Component, path string) error - DeleteVolume(name string) error - GetVolumeMountPath(name string) (string, error) + // volume mount related methods + AddVolumeMount(componentName, name, path string) error + DeleteVolumeMount(name string) error + GetVolumeMountPath(mountName, componentName string) (string, error) // workspace related methods GetDevfileWorkspace() *v1.DevWorkspaceTemplateSpecContent diff --git a/pkg/devfile/parser/data/v2/commands.go b/pkg/devfile/parser/data/v2/commands.go index b430ef34..8db7630d 100644 --- a/pkg/devfile/parser/data/v2/commands.go +++ b/pkg/devfile/parser/data/v2/commands.go @@ -59,15 +59,7 @@ func (d *DevfileV2) DeleteCommand(id string) error { found := false for i := len(d.Commands) - 1; i >= 0; i-- { - if d.Commands[i].Composite != nil && d.Commands[i].Id != id { - var subCmd []string - for _, command := range d.Commands[i].Composite.Commands { - if command != id { - subCmd = append(subCmd, command) - } - } - d.Commands[i].Composite.Commands = subCmd - } else if d.Commands[i].Id == id { + if d.Commands[i].Id == id { found = true d.Commands = append(d.Commands[:i], d.Commands[i+1:]...) } diff --git a/pkg/devfile/parser/data/v2/commands_test.go b/pkg/devfile/parser/data/v2/commands_test.go index 476a787f..bc23be27 100644 --- a/pkg/devfile/parser/data/v2/commands_test.go +++ b/pkg/devfile/parser/data/v2/commands_test.go @@ -347,52 +347,7 @@ func TestDeleteCommands(t *testing.T) { Id: "command3", CommandUnion: v1.CommandUnion{ Composite: &v1.CompositeCommand{ - Commands: []string{"command2"}, - }, - }, - }, - }, - wantErr: false, - }, - { - name: "Commands that do not belong to Composite Command", - commandToDelete: "command3", - commands: []v1.Command{ - { - Id: "command1", - CommandUnion: v1.CommandUnion{ - Exec: &v1.ExecCommand{}, - }, - }, - { - Id: "command2", - CommandUnion: v1.CommandUnion{ - Composite: &v1.CompositeCommand{ - Commands: []string{"command1"}, - }, - }, - }, - { - Id: "command3", - CommandUnion: v1.CommandUnion{ - Composite: &v1.CompositeCommand{ - Commands: []string{"command1"}, - }, - }, - }, - }, - wantCommands: []v1.Command{ - { - Id: "command1", - CommandUnion: v1.CommandUnion{ - Exec: &v1.ExecCommand{}, - }, - }, - { - Id: "command2", - CommandUnion: v1.CommandUnion{ - Composite: &v1.CompositeCommand{ - Commands: []string{"command1"}, + Commands: []string{"command1", "command2", "command1"}, }, }, }, diff --git a/pkg/devfile/parser/data/v2/components.go b/pkg/devfile/parser/data/v2/components.go index 7d9526e9..75c20d72 100644 --- a/pkg/devfile/parser/data/v2/components.go +++ b/pkg/devfile/parser/data/v2/components.go @@ -90,15 +90,7 @@ func (d *DevfileV2) DeleteComponent(name string) error { found := false for i := len(d.Components) - 1; i >= 0; i-- { - if d.Components[i].Container != nil && d.Components[i].Name != name { - var tmp []v1.VolumeMount - for _, volumeMount := range d.Components[i].Container.VolumeMounts { - if volumeMount.Name != name { - tmp = append(tmp, volumeMount) - } - } - d.Components[i].Container.VolumeMounts = tmp - } else if d.Components[i].Name == name { + if d.Components[i].Name == name { found = true d.Components = append(d.Components[:i], d.Components[i+1:]...) } diff --git a/pkg/devfile/parser/data/v2/components_test.go b/pkg/devfile/parser/data/v2/components_test.go index d30e24e6..f69f1390 100644 --- a/pkg/devfile/parser/data/v2/components_test.go +++ b/pkg/devfile/parser/data/v2/components_test.go @@ -454,6 +454,7 @@ func TestDeleteComponents(t *testing.T) { VolumeMounts: []v1.VolumeMount{ testingutil.GetFakeVolumeMount("comp2", "/path"), testingutil.GetFakeVolumeMount("comp2", "/path2"), + testingutil.GetFakeVolumeMount("comp3", "/path"), }, }, }, @@ -468,51 +469,6 @@ func TestDeleteComponents(t *testing.T) { }, wantErr: false, }, - { - name: "Non Volume Component", - componentToDelete: "comp1", - components: []v1.Component{ - { - Name: "comp1", - ComponentUnion: v1.ComponentUnion{ - Container: &v1.ContainerComponent{ - Container: v1.Container{ - VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount("comp2", "/path"), - }, - }, - }, - }, - }, - { - Name: "comp2", - ComponentUnion: v1.ComponentUnion{ - Volume: &v1.VolumeComponent{}, - }, - }, - { - Name: "comp3", - ComponentUnion: v1.ComponentUnion{ - Kubernetes: &v1.KubernetesComponent{}, - }, - }, - }, - wantComponents: []v1.Component{ - { - Name: "comp2", - ComponentUnion: v1.ComponentUnion{ - Volume: &v1.VolumeComponent{}, - }, - }, - { - Name: "comp3", - ComponentUnion: v1.ComponentUnion{ - Kubernetes: &v1.KubernetesComponent{}, - }, - }, - }, - wantErr: false, - }, { name: "Missing Component", componentToDelete: "comp12", diff --git a/pkg/devfile/parser/data/v2/volumes.go b/pkg/devfile/parser/data/v2/volumes.go index cb864f16..53a93232 100644 --- a/pkg/devfile/parser/data/v2/volumes.go +++ b/pkg/devfile/parser/data/v2/volumes.go @@ -8,75 +8,90 @@ import ( "github.com/devfile/library/pkg/devfile/parser/data/v2/common" ) -// AddVolume adds the volume to the devFile and mounts it to all the container components -func (d *DevfileV2) AddVolume(volumeComponent v1.Component, path string) error { - volumeExists := false +// AddVolumeMount adds the volume mount to the specified container component +func (d *DevfileV2) AddVolumeMount(componentName, name, path string) error { var pathErrorContainers []string + found := false for _, component := range d.Components { - if component.Container != nil { + if component.Container != nil && component.Name == componentName { + found = true for _, volumeMount := range component.Container.VolumeMounts { if volumeMount.Path == path { - var err = fmt.Errorf("another volume, %s, is mounted to the same path: %s, on the container: %s", volumeMount.Name, path, component.Name) + var err = fmt.Errorf("another volume, %s, is mounted to the same path: %s, in the container: %s", volumeMount.Name, path, component.Name) pathErrorContainers = append(pathErrorContainers, err.Error()) } } component.Container.VolumeMounts = append(component.Container.VolumeMounts, v1.VolumeMount{ - Name: volumeComponent.Name, + Name: name, Path: path, }) - } else if component.Volume != nil && component.Name == volumeComponent.Name { - volumeExists = true - break } } - if volumeExists { - return &common.FieldAlreadyExistError{ - Field: "volume", - Name: volumeComponent.Name, + if !found { + return &common.FieldNotFoundError{ + Field: "container component", + Name: componentName, } } if len(pathErrorContainers) > 0 { - return fmt.Errorf("errors while creating volume:\n%s", strings.Join(pathErrorContainers, "\n")) + return fmt.Errorf("errors while adding volume mounts:\n%s", strings.Join(pathErrorContainers, "\n")) } - d.Components = append(d.Components, volumeComponent) - return nil } -// DeleteVolume removes the volume from the devFile and removes all the related volume mounts -func (d *DevfileV2) DeleteVolume(name string) error { +// DeleteVolumeMount deletes the volume mount from container components +func (d *DevfileV2) DeleteVolumeMount(name string) error { + found := false + for i := range d.Components { + if d.Components[i].Container != nil && d.Components[i].Name != name { + for j := len(d.Components[i].Container.VolumeMounts) - 1; j >= 0; j-- { + if d.Components[i].Container.VolumeMounts[j].Name == name { + found = true + d.Components[i].Container.VolumeMounts = append(d.Components[i].Container.VolumeMounts[:j], d.Components[i].Container.VolumeMounts[j+1:]...) + } + } + } + } - return d.DeleteComponent(name) + if !found { + return &common.FieldNotFoundError{ + Field: "volume mount", + Name: name, + } + } + + return nil } -// GetVolumeMountPath gets the mount path of the required volume -func (d *DevfileV2) GetVolumeMountPath(name string) (string, error) { - volumeFound := false +// GetVolumeMountPath gets the mount path of the specified volume mount from the specified container component +func (d *DevfileV2) GetVolumeMountPath(mountName, componentName string) (string, error) { mountFound := false - path := "" + componentFound := false + var path string for _, component := range d.Components { - if component.Container != nil { + if component.Container != nil && component.Name == componentName { + componentFound = true for _, volumeMount := range component.Container.VolumeMounts { - if volumeMount.Name == name { + if volumeMount.Name == mountName { mountFound = true path = volumeMount.Path } } - } else if component.Volume != nil { - volumeFound = true } } - if volumeFound && mountFound { - return path, nil - } else if !mountFound && volumeFound { - return "", fmt.Errorf("volume not mounted to any component") - } - return "", &common.FieldNotFoundError{ - Field: "volume", - Name: "name", + + if !componentFound { + return "", &common.FieldNotFoundError{ + Field: "container component", + Name: componentName, + } + } else if !mountFound { + return "", fmt.Errorf("volume %s not mounted to component %s", mountName, componentName) } + + return path, nil } diff --git a/pkg/devfile/parser/data/v2/volumes_test.go b/pkg/devfile/parser/data/v2/volumes_test.go index e3105f65..22e5c3d1 100644 --- a/pkg/devfile/parser/data/v2/volumes_test.go +++ b/pkg/devfile/parser/data/v2/volumes_test.go @@ -1,27 +1,26 @@ package v2 import ( - "reflect" "testing" v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" "github.com/devfile/library/pkg/testingutil" - "github.com/kylelemons/godebug/pretty" + "github.com/stretchr/testify/assert" ) -func TestDevfile200_AddVolume(t *testing.T) { +func TestDevfile200_AddVolumeMount(t *testing.T) { image0 := "some-image-0" - container0 := "container0" - image1 := "some-image-1" + container0 := "container0" container1 := "container1" volume0 := "volume0" volume1 := "volume1" type args struct { - volumeComponent v1.Component - path string + componentName string + name string + path string } tests := []struct { name string @@ -31,7 +30,7 @@ func TestDevfile200_AddVolume(t *testing.T) { wantErr bool }{ { - name: "case 1: it should add the volume to all the containers", + name: "add the volume mount when other mounts are present", currentComponents: []v1.Component{ { Name: container0, @@ -39,6 +38,9 @@ func TestDevfile200_AddVolume(t *testing.T) { Container: &v1.ContainerComponent{ Container: v1.Container{ Image: image0, + VolumeMounts: []v1.VolumeMount{ + testingutil.GetFakeVolumeMount(volume1, "/data"), + }, }, }, }, @@ -48,15 +50,19 @@ func TestDevfile200_AddVolume(t *testing.T) { ComponentUnion: v1.ComponentUnion{ Container: &v1.ContainerComponent{ Container: v1.Container{ - Image: image1, + Image: image0, + VolumeMounts: []v1.VolumeMount{ + testingutil.GetFakeVolumeMount(volume1, "/data"), + }, }, }, }, }, }, args: args{ - volumeComponent: testingutil.GetFakeVolumeComponent(volume0, "5Gi"), - path: "/path", + name: volume0, + path: "/path0", + componentName: container0, }, wantComponents: []v1.Component{ { @@ -66,7 +72,8 @@ func TestDevfile200_AddVolume(t *testing.T) { Container: v1.Container{ Image: image0, VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume0, "/path"), + testingutil.GetFakeVolumeMount(volume1, "/data"), + testingutil.GetFakeVolumeMount(volume0, "/path0"), }, }, }, @@ -77,19 +84,18 @@ func TestDevfile200_AddVolume(t *testing.T) { ComponentUnion: v1.ComponentUnion{ Container: &v1.ContainerComponent{ Container: v1.Container{ - Image: image1, + Image: image0, VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume0, "/path"), + testingutil.GetFakeVolumeMount(volume1, "/data"), }, }, }, }, }, - testingutil.GetFakeVolumeComponent(volume0, "5Gi"), }, }, { - name: "case 2: it should add the volume when other volumes are present", + name: "error out when same path is present in the container", currentComponents: []v1.Component{ { Name: container0, @@ -106,40 +112,14 @@ func TestDevfile200_AddVolume(t *testing.T) { }, }, args: args{ - volumeComponent: testingutil.GetFakeVolumeComponent(volume0, "5Gi"), - path: "/path", - }, - wantComponents: []v1.Component{ - { - Name: container0, - ComponentUnion: v1.ComponentUnion{ - Container: &v1.ContainerComponent{ - Container: v1.Container{ - Image: image0, - VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume1, "/data"), - testingutil.GetFakeVolumeMount(volume0, "/path"), - }, - }, - }, - }, - }, - testingutil.GetFakeVolumeComponent(volume0, "5Gi"), - }, - }, - { - name: "case 3: error out when same volume is present", - currentComponents: []v1.Component{ - testingutil.GetFakeVolumeComponent(volume0, "1Gi"), - }, - args: args{ - volumeComponent: testingutil.GetFakeVolumeComponent(volume0, "5Gi"), - path: "/path", + name: volume0, + path: "/data", + componentName: container0, }, wantErr: true, }, { - name: "case 4: it should error out when another volume is mounted to the same path", + name: "error out when the specified container is not found", currentComponents: []v1.Component{ { Name: container0, @@ -148,17 +128,17 @@ func TestDevfile200_AddVolume(t *testing.T) { Container: v1.Container{ Image: image0, VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume1, "/path"), + testingutil.GetFakeVolumeMount(volume1, "/data"), }, }, }, }, }, - testingutil.GetFakeVolumeComponent(volume1, "5Gi"), }, args: args{ - volumeComponent: testingutil.GetFakeVolumeComponent(volume0, "5Gi"), - path: "/path", + name: volume0, + path: "/data", + componentName: container1, }, wantErr: true, }, @@ -175,193 +155,116 @@ func TestDevfile200_AddVolume(t *testing.T) { }, } - err := d.AddVolume(tt.args.volumeComponent, tt.args.path) - if (err != nil) != tt.wantErr { - t.Errorf("AddVolume() error = %v, wantErr %v", err, tt.wantErr) - } - - if err != nil && tt.wantErr { - return - } - - if !reflect.DeepEqual(d.Components, tt.wantComponents) { - t.Errorf("wanted: %v, got: %v, difference at %v", tt.wantComponents, d.Components, pretty.Compare(tt.wantComponents, d.Components)) + err := d.AddVolumeMount(tt.args.componentName, tt.args.name, tt.args.path) + if tt.wantErr && err == nil { + t.Errorf("Expected error from test but got nil") + } else if !tt.wantErr && err != nil { + t.Errorf("Got unexpected error: %s", err) + } else if err == nil { + assert.Equal(t, tt.wantComponents, d.Components, "The two values should be the same.") } }) } } -func TestDevfile200_DeleteVolume(t *testing.T) { - image0 := "some-image-0" - container0 := "container0" - - image1 := "some-image-1" - container1 := "container1" - - volume0 := "volume0" - volume1 := "volume1" +func TestDevfile200_DeleteVolumeMounts(t *testing.T) { tests := []struct { - name string - currentComponents []v1.Component - wantComponents []v1.Component - cmpName string - wantErr bool + name string + volMountToDelete string + components []v1.Component + wantComponents []v1.Component + wantErr bool }{ { - name: "case 1: volume is present and mounted to multiple components", - currentComponents: []v1.Component{ + name: "Volume Component with mounts", + volMountToDelete: "comp2", + components: []v1.Component{ { - Name: container0, + Name: "comp1", ComponentUnion: v1.ComponentUnion{ Container: &v1.ContainerComponent{ Container: v1.Container{ - Image: image0, VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume0, "/path"), + testingutil.GetFakeVolumeMount("comp2", "/path"), + testingutil.GetFakeVolumeMount("comp2", "/path2"), + testingutil.GetFakeVolumeMount("comp3", "/path"), }, }, }, }, }, { - Name: container1, + Name: "comp4", ComponentUnion: v1.ComponentUnion{ Container: &v1.ContainerComponent{ Container: v1.Container{ - Image: image1, VolumeMounts: []v1.VolumeMount{ - { - Name: volume0, - Path: "/path", - }, + testingutil.GetFakeVolumeMount("comp2", "/path"), }, }, }, }, }, - testingutil.GetFakeVolumeComponent(volume0, "5Gi"), }, wantComponents: []v1.Component{ { - Name: container0, + Name: "comp1", ComponentUnion: v1.ComponentUnion{ Container: &v1.ContainerComponent{ Container: v1.Container{ - Image: image0, + VolumeMounts: []v1.VolumeMount{ + testingutil.GetFakeVolumeMount("comp3", "/path"), + }, }, }, }, }, { - Name: container1, + Name: "comp4", ComponentUnion: v1.ComponentUnion{ Container: &v1.ContainerComponent{ Container: v1.Container{ - Image: image1, + VolumeMounts: []v1.VolumeMount{}, }, }, }, }, }, - cmpName: volume0, wantErr: false, }, { - name: "case 2: delete only the required volume in case of multiples", - currentComponents: []v1.Component{ - { - Name: container0, - ComponentUnion: v1.ComponentUnion{ - Container: &v1.ContainerComponent{ - Container: v1.Container{ - Image: image0, - VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume0, "/path"), - testingutil.GetFakeVolumeMount(volume1, "/data"), - }, - }, - }, - }, - }, + name: "Missing mount name", + volMountToDelete: "comp1", + components: []v1.Component{ { - Name: container1, + Name: "comp4", ComponentUnion: v1.ComponentUnion{ Container: &v1.ContainerComponent{ Container: v1.Container{ - Image: image1, VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume1, "/data"), + testingutil.GetFakeVolumeMount("comp2", "/path"), }, }, }, }, }, - testingutil.GetFakeVolumeComponent(volume0, "5Gi"), - testingutil.GetFakeVolumeComponent(volume1, "5Gi"), }, wantComponents: []v1.Component{ { - Name: container0, - ComponentUnion: v1.ComponentUnion{ - Container: &v1.ContainerComponent{ - Container: v1.Container{ - Image: image0, - VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume1, "/data"), - }, - }, - }, - }, - }, - { - Name: container1, - ComponentUnion: v1.ComponentUnion{ - Container: &v1.ContainerComponent{ - Container: v1.Container{ - Image: image1, - VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume1, "/data"), - }, - }, - }, - }, - }, - testingutil.GetFakeVolumeComponent(volume1, "5Gi"), - }, - cmpName: volume0, - wantErr: false, - }, - { - name: "case 3: volume is not present", - currentComponents: []v1.Component{ - { - Name: container0, + Name: "comp4", ComponentUnion: v1.ComponentUnion{ Container: &v1.ContainerComponent{ Container: v1.Container{ - Image: image0, VolumeMounts: []v1.VolumeMount{ - testingutil.GetFakeVolumeMount(volume1, "/data"), + testingutil.GetFakeVolumeMount("comp2", "/path"), }, }, }, }, }, - testingutil.GetFakeVolumeComponent(volume1, "5Gi"), }, - wantComponents: []v1.Component{}, - cmpName: volume0, - wantErr: true, - }, - { - name: "case 4: volume is present but not mounted to any component", - currentComponents: []v1.Component{ - testingutil.GetFakeVolumeComponent(volume0, "5Gi"), - }, - wantComponents: []v1.Component{}, - cmpName: volume0, - wantErr: false, + wantErr: true, }, } for _, tt := range tests { @@ -370,42 +273,39 @@ func TestDevfile200_DeleteVolume(t *testing.T) { v1.Devfile{ DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{ DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{ - Components: tt.currentComponents, + Components: tt.components, }, }, }, } - err := d.DeleteVolume(tt.cmpName) - if (err != nil) != tt.wantErr { - t.Errorf("DeleteVolume() error = %v, wantErr %v", err, tt.wantErr) - } - if err != nil && tt.wantErr { - return - } - - if !reflect.DeepEqual(d.Components, tt.wantComponents) { - t.Errorf("wanted: %v, got: %v, difference at %v", tt.wantComponents, d.Components, pretty.Compare(tt.wantComponents, d.Components)) + err := d.DeleteVolumeMount(tt.volMountToDelete) + if tt.wantErr && err == nil { + t.Errorf("Expected error from test but got nil") + } else if !tt.wantErr && err != nil { + t.Errorf("Got unexpected error: %s", err) + } else if err == nil { + assert.Equal(t, tt.wantComponents, d.Components, "The two values should be the same.") } }) } + } func TestDevfile200_GetVolumeMountPath(t *testing.T) { volume1 := "volume1" + component1 := "component1" - type args struct { - name string - } tests := []struct { name string currentComponents []v1.Component + mountName string + componentName string wantPath string - args args wantErr bool }{ { - name: "case 1: volume is present and mounted on a component", + name: "vol is mounted on the specified container component", currentComponents: []v1.Component{ { ComponentUnion: v1.ComponentUnion{ @@ -417,17 +317,16 @@ func TestDevfile200_GetVolumeMountPath(t *testing.T) { }, }, }, + Name: component1, }, - testingutil.GetFakeVolumeComponent(volume1, "5Gi"), - }, - wantPath: "/path", - args: args{ - name: volume1, }, - wantErr: false, + wantPath: "/path", + mountName: volume1, + componentName: component1, + wantErr: false, }, { - name: "case 2: volume is not present but mounted on a component", + name: "vol is not mounted on the specified container component", currentComponents: []v1.Component{ { ComponentUnion: v1.ComponentUnion{ @@ -439,30 +338,32 @@ func TestDevfile200_GetVolumeMountPath(t *testing.T) { }, }, }, + Name: component1, }, }, - args: args{ - name: volume1, - }, - wantErr: true, - }, - { - name: "case 3: volume is not present and not mounted on a component", - currentComponents: []v1.Component{}, - args: args{ - name: volume1, - }, - wantErr: true, + mountName: "volume2", + componentName: component1, + wantErr: true, }, { - name: "case 4: volume is present but not mounted", + name: "invalid specified container", currentComponents: []v1.Component{ - testingutil.GetFakeVolumeComponent(volume1, "5Gi"), - }, - args: args{ - name: volume1, + { + ComponentUnion: v1.ComponentUnion{ + Container: &v1.ContainerComponent{ + Container: v1.Container{ + VolumeMounts: []v1.VolumeMount{ + testingutil.GetFakeVolumeMount(volume1, "/path"), + }, + }, + }, + }, + Name: component1, + }, }, - wantErr: true, + mountName: volume1, + componentName: "component2", + wantErr: true, }, } for _, tt := range tests { @@ -476,17 +377,13 @@ func TestDevfile200_GetVolumeMountPath(t *testing.T) { }, }, } - got, err := d.GetVolumeMountPath(tt.args.name) - if (err != nil) != tt.wantErr { - t.Errorf("GetVolumeMountPath() error = %v, wantErr %v", err, tt.wantErr) - } - - if err != nil && tt.wantErr { - return - } - - if !reflect.DeepEqual(got, tt.wantPath) { - t.Errorf("wanted: %v, got: %v, difference at %v", tt.wantPath, got, pretty.Compare(tt.wantPath, got)) + gotPath, err := d.GetVolumeMountPath(tt.mountName, tt.componentName) + if tt.wantErr && err == nil { + t.Errorf("Expected error from test but got nil") + } else if !tt.wantErr && err != nil { + t.Errorf("Got unexpected error: %s", err) + } else if err == nil { + assert.Equal(t, tt.wantPath, gotPath, "The two values should be the same.") } }) }