Unverified Commit d14e9326 authored by Bryan Liles's avatar Bryan Liles Committed by GitHub
Browse files

Merge pull request #559 from bryanl/do-not-panic-when-running-ks-out-of-app

Error gracefully when running app related commands outside of app
parents 8b01ddc4 b76c29ff
......@@ -123,7 +123,7 @@ const (
var (
// ErrNotInApp is an error stating the user is not in a ksonnet application directory
// hierarchy.
ErrNotInApp = errors.Errorf("could not find ksonnet app")
ErrNotInApp = errors.Errorf("this command has to be run within a ksonnet application")
)
type missingOptionError struct {
......@@ -154,7 +154,12 @@ func (e *invalidOptionError) Error() string {
return fmt.Sprintf("invalid type for option %s", e.name)
}
// optionLoader loads typed option from a configuration map. If an error
// occurs in any of the load processes, the loader will return default
// values for type.
type optionLoader struct {
// err is the error state for the optionLoader. If this is not nil, all
// subsequent calls to load will return nil.
err error
m map[string]interface{}
}
......
......@@ -104,3 +104,9 @@ func TestApply_invalid_input(t *testing.T) {
require.Error(t, err)
})
}
func TestApply_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := newApply(in)
require.Error(t, err)
}
......@@ -146,3 +146,9 @@ func TestComponentList_wide(t *testing.T) {
assertOutput(t, "component/list/wide.txt", buf.String())
})
}
func TestComponentList_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewComponentList(in)
require.Error(t, err)
}
......@@ -52,3 +52,9 @@ func TestComponentRm(t *testing.T) {
assert.True(t, didDelete)
})
}
func TestComponentRm_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewComponentRm(in)
require.Error(t, err)
}
......@@ -98,3 +98,9 @@ func TestDelete_invalid_input(t *testing.T) {
require.Error(t, err)
})
}
func TestDelete_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := newDelete(in)
require.Error(t, err)
}
......@@ -95,3 +95,9 @@ func TestDiff(t *testing.T) {
})
}
}
func TestDiff_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewDiff(in)
require.Error(t, err)
}
......@@ -62,3 +62,9 @@ func TestEnvAdd(t *testing.T) {
require.NoError(t, err)
})
}
func TestEnvAdd_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewEnvAdd(in)
require.Error(t, err)
}
......@@ -95,3 +95,9 @@ func TestEnvCurrent_invalid_input(t *testing.T) {
require.Error(t, err)
})
}
func TestEnvCurrent_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := newEnvCurrent(in)
require.Error(t, err)
}
......@@ -51,3 +51,9 @@ func TestEnvDescribe(t *testing.T) {
assertOutput(t, "env/describe/output.txt", buf.String())
})
}
func TestEnvDescribe_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewEnvDescribe(in)
require.Error(t, err)
}
......@@ -95,3 +95,9 @@ func TestEnvList(t *testing.T) {
})
}
func TestEnvList_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewEnvList(in)
require.Error(t, err)
}
......@@ -50,3 +50,9 @@ func TestEnvRm(t *testing.T) {
require.NoError(t, err)
})
}
func TestEnvRm_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewEnvRm(in)
require.Error(t, err)
}
......@@ -143,3 +143,9 @@ func TestEnvSet_name_and_namespace(t *testing.T) {
require.NoError(t, err)
})
}
func TestEnvSet_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewEnvSet(in)
require.Error(t, err)
}
......@@ -113,3 +113,9 @@ func TestEnvTargets_invalid_environment(t *testing.T) {
require.Error(t, err)
})
}
func TestEnvTargets_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewEnvTargets(in)
require.Error(t, err)
}
......@@ -51,3 +51,9 @@ func TestEnvUpdate(t *testing.T) {
require.NoError(t, err)
})
}
func TestEnvUpdate_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := newEnvUpdate(in)
require.Error(t, err)
}
......@@ -167,3 +167,9 @@ func TestImport_invalid_file(t *testing.T) {
require.Error(t, err)
})
}
func TestImport_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewImport(in)
require.Error(t, err)
}
......@@ -49,6 +49,10 @@ func NewModuleCreate(m map[string]interface{}) (*ModuleCreate, error) {
cm: component.DefaultManager,
}
if ol.err != nil {
return nil, ol.err
}
return mc, nil
}
......
......@@ -71,3 +71,9 @@ func TestModuleCreate_already_exists(t *testing.T) {
require.Error(t, err)
})
}
func TestModuleCreate_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewModuleCreate(in)
require.Error(t, err)
}
......@@ -54,3 +54,9 @@ func TestModuleList(t *testing.T) {
assertOutput(t, "ns/list/output.txt", buf.String())
})
}
func TestModuleList_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewModuleList(in)
require.Error(t, err)
}
......@@ -131,3 +131,9 @@ func TestParamDelete_env_global(t *testing.T) {
require.NoError(t, err)
})
}
func TestParamDelete_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewParamDelete(in)
require.Error(t, err)
}
......@@ -78,3 +78,9 @@ func TestParamDiff(t *testing.T) {
assertOutput(t, filepath.Join("param", "diff", "output.txt"), buf.String())
})
}
func TestParamDiff_requires_app(t *testing.T) {
in := make(map[string]interface{})
_, err := NewParamDiff(in)
require.Error(t, err)
}
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