Change error reporting in get.go from logger.Failure to fmt.Errorf to give non 0 exit code
Signed-off-by: Daniel Guns <danbguns@gmail.com>
This commit is contained in:
@@ -184,13 +184,13 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if get.list.len() == 0 {
|
||||
if len(args) > 0 {
|
||||
logger.Failuref("%s object '%s' not found in %s namespace",
|
||||
return fmt.Errorf("%s object '%s' not found in %s namespace",
|
||||
get.kind,
|
||||
args[0],
|
||||
namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace),
|
||||
)
|
||||
} else if !getAll {
|
||||
logger.Failuref("no %s objects found in %s namespace",
|
||||
return fmt.Errorf("no %s objects found in %s namespace",
|
||||
get.kind,
|
||||
namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace),
|
||||
)
|
||||
|
||||
@@ -19,7 +19,10 @@ limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_GetCmd(t *testing.T) {
|
||||
tmpl := map[string]string{
|
||||
@@ -59,3 +62,76 @@ func Test_GetCmd(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_GetCmdErrors(t *testing.T) {
|
||||
tmpl := map[string]string{
|
||||
"fluxns": allocateNamespace("flux-system"),
|
||||
}
|
||||
testEnv.CreateObjectFile("./testdata/get/objects.yaml", tmpl, t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args string
|
||||
assert assertFunc
|
||||
}{
|
||||
{
|
||||
name: "specific object not found",
|
||||
args: "get kustomization non-existent-resource -n " + tmpl["fluxns"],
|
||||
assert: assertError(fmt.Sprintf("Kustomization object 'non-existent-resource' not found in \"%s\" namespace", tmpl["fluxns"])),
|
||||
},
|
||||
{
|
||||
name: "no objects found in namespace",
|
||||
args: "get helmrelease -n " + tmpl["fluxns"],
|
||||
assert: assertError(fmt.Sprintf("no HelmRelease objects found in \"%s\" namespace", tmpl["fluxns"])),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := cmdTestCase{
|
||||
args: tt.args,
|
||||
assert: tt.assert,
|
||||
}
|
||||
cmd.runTestCmd(t)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_GetCmdSuccess(t *testing.T) {
|
||||
tmpl := map[string]string{
|
||||
"fluxns": allocateNamespace("flux-system"),
|
||||
}
|
||||
testEnv.CreateObjectFile("./testdata/get/objects.yaml", tmpl, t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args string
|
||||
assert assertFunc
|
||||
}{
|
||||
{
|
||||
name: "list sources git",
|
||||
args: "get sources git -n " + tmpl["fluxns"],
|
||||
assert: assertSuccess(),
|
||||
},
|
||||
{
|
||||
name: "get help",
|
||||
args: "get --help",
|
||||
assert: assertSuccess(),
|
||||
},
|
||||
{
|
||||
name: "get with all namespaces flag",
|
||||
args: "get sources git -A",
|
||||
assert: assertSuccess(),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := cmdTestCase{
|
||||
args: tt.args,
|
||||
assert: tt.assert,
|
||||
}
|
||||
cmd.runTestCmd(t)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user