From c5275c31fbd11fafd64d2214cd2d1de2151e6e8c Mon Sep 17 00:00:00 2001 From: half-shell Date: Wed, 4 Jan 2023 20:02:07 +0100 Subject: [PATCH 1/2] test(actions): add a simple test for "help" action --- src/actions/help_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/actions/help_test.go diff --git a/src/actions/help_test.go b/src/actions/help_test.go new file mode 100644 index 0000000..68379a4 --- /dev/null +++ b/src/actions/help_test.go @@ -0,0 +1,29 @@ +package actions + +import ( + "errors" + "reflect" + "testing" + + "src/exeiac/arguments" + exinfra "src/exeiac/infra" +) + +var infra *exinfra.Infra +var conf *arguments.Configuration +var bricksToExecute exinfra.Bricks + +func TestHelpWhenNoBricksToExecute(t *testing.T) { + bricksToExecute = exinfra.Bricks{} + expectedStatusCode := 3 + + statusCode, err := Help(infra, conf, bricksToExecute) + + if statusCode != expectedStatusCode { + t.Fatalf(`statusCode should be %v; is "%v"`, expectedStatusCode, statusCode) + } + + if errors.Is(err, exinfra.ErrBadArg{}) { + t.Fatalf("Errors should be of type ErrBadArg, is %v", reflect.TypeOf(err)) + } +} From 621aca5d1569f3c4bb477fedb5c5a1d425020b51 Mon Sep 17 00:00:00 2001 From: half-shell Date: Wed, 4 Jan 2023 20:05:44 +0100 Subject: [PATCH 2/2] chore: improve ErrBadArg display --- src/actions/help.go | 5 +++-- src/infra/error.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/actions/help.go b/src/actions/help.go index 7e66ca9..20df016 100644 --- a/src/actions/help.go +++ b/src/actions/help.go @@ -36,8 +36,8 @@ func Help( err error, ) { if len(bricksToExecute) == 0 { - err = exinfra.ErrBadArg{Reason: "Error: you should specify at least a brick for help action" + - "\nif you want to display exeiac help use --help option"} + err = exinfra.ErrBadArg{Reason: `you should specify at least one brick for the "help" action if you want to display exeiac help use the --help option.`} + return 3, err } @@ -72,5 +72,6 @@ func Help( } execSummary.Display() + return } diff --git a/src/infra/error.go b/src/infra/error.go index d4da666..985cbff 100755 --- a/src/infra/error.go +++ b/src/infra/error.go @@ -38,8 +38,8 @@ func (err ActionNotImplementedError) Error() string { func (e ErrBadArg) Error() string { if e.Value == "" { - return fmt.Sprintf("! Bad argument: %s", e.Reason) + return fmt.Sprintf("Error(Bad argument): %s", e.Reason) } else { - return fmt.Sprintf("! Bad argument: %s: %s", e.Reason, e.Value) + return fmt.Sprintf("Error(Bad argument): %s: %s", e.Reason, e.Value) } }