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/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)) + } +} 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) } }