Commit 704baddf authored by GuessWhoSamFoo's avatar GuessWhoSamFoo
Browse files

Check component exists prior to delete in local case


Signed-off-by: default avatarGuessWhoSamFoo <sfoohei@gmail.com>
parent 03566e32
......@@ -117,6 +117,10 @@ func (pd *ParamDelete) deleteLocal(path []string) error {
return errors.Wrap(err, "could not find component")
}
if c == nil {
return errors.New("invalid component or param key")
}
if err := c.DeleteParam(path); err != nil {
return errors.Wrap(err, "delete param")
}
......
......@@ -27,29 +27,59 @@ import (
)
func TestParamDelete(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
componentName := "deployment"
path := "replicas"
c := &cmocks.Component{}
c.On("DeleteParam", []string{"replicas"}).Return(nil)
in := map[string]interface{}{
OptionApp: appMock,
OptionName: componentName,
OptionPath: path,
}
a, err := NewParamDelete(in)
require.NoError(t, err)
a.resolvePathFn = func(app.App, string) (component.Module, component.Component, error) {
return nil, c, nil
}
err = a.Run()
require.NoError(t, err)
})
cases := []struct {
name string
componentName string
isErr bool
}{
{
name: "param delete",
componentName: "deployment",
isErr: false,
},
{
name: "param delete missing component or param key",
componentName: "",
isErr: true,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
componentName := tc.componentName
path := "replicas"
c := &cmocks.Component{}
c.On("DeleteParam", []string{"replicas"}).Return(nil)
in := map[string]interface{}{
OptionApp: appMock,
OptionName: componentName,
OptionPath: path,
}
a, err := NewParamDelete(in)
require.NoError(t, err)
a.resolvePathFn = func(app.App, string) (component.Module, component.Component, error) {
switch tc.componentName {
case "":
return nil, nil, nil
default:
return nil, c, nil
}
}
err = a.Run()
if tc.isErr {
require.Error(t, err)
return
}
require.NoError(t, err)
})
})
}
}
func TestParamDelete_global(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment