From 5d2e83e1318bce13fc3cbec22217cae0b0e97bd9 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Fri, 4 Mar 2016 17:35:51 +0100 Subject: [PATCH 1/2] fleetctl:test: check for empty input Check that the return value is 0, when the following commands run without any input unit names: destroy, load, start, stop, and unload. --- fleetctl/destroy_test.go | 5 +++++ fleetctl/load_test.go | 5 +++++ fleetctl/start_test.go | 5 +++++ fleetctl/stop_test.go | 5 +++++ fleetctl/unload_test.go | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/fleetctl/destroy_test.go b/fleetctl/destroy_test.go index 601b59af8..e10111a9e 100644 --- a/fleetctl/destroy_test.go +++ b/fleetctl/destroy_test.go @@ -53,6 +53,11 @@ func TestRunDestroyUnits(t *testing.T) { []string{"y1", "y2", "y3", "y4", "j1", "j2", "j3", "j4", "j5", "y0"}, 0, }, + { + "destroy null input", + []string{}, + 0, + }, } // Check with two goroutines we don't care we should just get diff --git a/fleetctl/load_test.go b/fleetctl/load_test.go index 01ce9e2de..51b5f2739 100644 --- a/fleetctl/load_test.go +++ b/fleetctl/load_test.go @@ -76,6 +76,11 @@ func TestRunLoadUnits(t *testing.T) { []string{"y1", "y2", "y3", "y4", "load1", "load2", "load3", "load4", "load5", "load6", "y0"}, 1, }, + { + "load null input", + []string{}, + 0, + }, } sharedFlags.NoBlock = true diff --git a/fleetctl/start_test.go b/fleetctl/start_test.go index c97de662e..8a43b937f 100644 --- a/fleetctl/start_test.go +++ b/fleetctl/start_test.go @@ -111,6 +111,11 @@ func TestRunStartUnits(t *testing.T) { []string{"foo-template@1"}, 1, }, + { + "start null input", + []string{}, + 0, + }, } templateResults := []commandTestResults{ diff --git a/fleetctl/stop_test.go b/fleetctl/stop_test.go index 536419ec1..708bf42ae 100644 --- a/fleetctl/stop_test.go +++ b/fleetctl/stop_test.go @@ -66,6 +66,11 @@ func TestRunStopUnits(t *testing.T) { []string{"y1", "y2", "y3", "y4", "stop1", "stop2", "stop3", "stop4", "stop5", "y0"}, 0, }, + { + "stop null input", + []string{}, + 0, + }, } sharedFlags.NoBlock = true diff --git a/fleetctl/unload_test.go b/fleetctl/unload_test.go index 8e61b3dd9..169ebfea2 100644 --- a/fleetctl/unload_test.go +++ b/fleetctl/unload_test.go @@ -66,6 +66,11 @@ func TestRunUnloadUnits(t *testing.T) { []string{"y1", "y2", "y3", "y4", "unload1", "unload2", "unload3", "unload4", "unload5", "y0"}, 0, }, + { + "unload null input", + []string{}, + 0, + }, } sharedFlags.NoBlock = true From 80d37bbceae905a4472cd5cb1da256395deb13a8 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Fri, 4 Mar 2016 15:16:06 +0100 Subject: [PATCH 2/2] fleetctl: check for empty input unit strings If no unit name is given for fleetctl commands like destroy, load, start, stop, submit, and unload, then return with exit code 0, printing out a soft warning message to stderr. Fixes: https://github.com/coreos/fleet/issues/1443 --- fleetctl/destroy.go | 5 +++++ fleetctl/load.go | 5 +++++ fleetctl/start.go | 5 +++++ fleetctl/stop.go | 5 +++++ fleetctl/submit.go | 5 +++++ fleetctl/unload.go | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/fleetctl/destroy.go b/fleetctl/destroy.go index 4197e6890..31eb919b6 100644 --- a/fleetctl/destroy.go +++ b/fleetctl/destroy.go @@ -35,6 +35,11 @@ Destroyed units are impossible to start unless re-submitted.`, } func runDestroyUnits(args []string) (exit int) { + if len(args) == 0 { + stderr("No units given") + return 0 + } + units, err := findUnits(args) if err != nil { stderr("%v", err) diff --git a/fleetctl/load.go b/fleetctl/load.go index 0f7b0923c..9b1127dab 100644 --- a/fleetctl/load.go +++ b/fleetctl/load.go @@ -46,6 +46,11 @@ func init() { } func runLoadUnits(args []string) (exit int) { + if len(args) == 0 { + stderr("No units given") + return 0 + } + if err := lazyCreateUnits(args); err != nil { stderr("Error creating units: %v", err) return 1 diff --git a/fleetctl/start.go b/fleetctl/start.go index 2ded29539..99e03c2d1 100644 --- a/fleetctl/start.go +++ b/fleetctl/start.go @@ -54,6 +54,11 @@ func init() { } func runStartUnit(args []string) (exit int) { + if len(args) == 0 { + stderr("No units given") + return 0 + } + if err := lazyCreateUnits(args); err != nil { stderr("Error creating units: %v", err) return 1 diff --git a/fleetctl/stop.go b/fleetctl/stop.go index 941b33d7b..7ffe26254 100644 --- a/fleetctl/stop.go +++ b/fleetctl/stop.go @@ -52,6 +52,11 @@ func init() { } func runStopUnit(args []string) (exit int) { + if len(args) == 0 { + stderr("No units given") + return 0 + } + units, err := findUnits(args) if err != nil { stderr("%v", err) diff --git a/fleetctl/submit.go b/fleetctl/submit.go index cbfe03f93..1297cff50 100644 --- a/fleetctl/submit.go +++ b/fleetctl/submit.go @@ -36,6 +36,11 @@ func init() { } func runSubmitUnits(args []string) (exit int) { + if len(args) == 0 { + stderr("No units given") + return 0 + } + if err := lazyCreateUnits(args); err != nil { stderr("Error creating units: %v", err) exit = 1 diff --git a/fleetctl/unload.go b/fleetctl/unload.go index 48eb833fc..5bdbff3be 100644 --- a/fleetctl/unload.go +++ b/fleetctl/unload.go @@ -36,6 +36,11 @@ func init() { } func runUnloadUnit(args []string) (exit int) { + if len(args) == 0 { + stderr("No units given") + return 0 + } + units, err := findUnits(args) if err != nil { stderr("%v", err)