From 634638184d5fbcc0b6b546035bc5b79bd39dae1e Mon Sep 17 00:00:00 2001 From: andronache Date: Fri, 29 Jan 2021 16:16:04 +0200 Subject: [PATCH] Coverage tests in console --- console/command_executer_test.go | 28 +++++++++++++++++++ console/command_test.go | 48 ++++++++++++++++++++++++++++++-- console/parse.go | 3 -- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/console/command_executer_test.go b/console/command_executer_test.go index 317e7b4fb..f273adec6 100644 --- a/console/command_executer_test.go +++ b/console/command_executer_test.go @@ -19,6 +19,8 @@ package console import ( "encoding/json" + "fmt" + "reflect" "testing" "time" @@ -253,3 +255,29 @@ func TestFromJSONInterestingFields2(t *testing.T) { t.Errorf("Expected: %s got: '%s'", expected, line) } } + +func TestGetStringValueInterface(t *testing.T) { + dflt := utils.StringSet{} + expected := getSliceAsString([]interface{}{}, dflt) + rply := getStringValue([]interface{}{}, dflt) + if rply != expected { + t.Errorf("Expecting: %s , received: %s", expected, rply) + } +} + +func TestGetFormatedSliceResultCase2(t *testing.T) { + dflt := utils.StringSet{} + rply := GetFormatedSliceResult(true, dflt) + expected := true + if reflect.DeepEqual(expected, rply) { + t.Errorf("Expecting: %+v , received: %+v", expected, rply) + } +} + +func TestLocalExecute(t *testing.T) { + testStruct := CommandExecuter{} + result := testStruct.LocalExecute() + if reflect.DeepEqual(utils.EmptyString, result) { + fmt.Errorf("Expected <%+v>, Received <%+v>", utils.EmptyString, result) + } +} diff --git a/console/command_test.go b/console/command_test.go index 34dba6a40..c86b08a4e 100644 --- a/console/command_test.go +++ b/console/command_test.go @@ -19,15 +19,59 @@ along with this program. If not, see package console import ( - "fmt" "reflect" "testing" + + "github.com/cgrates/cgrates/utils" ) func TestCmdGetCommands(t *testing.T) { expected := commands result := GetCommands() if !reflect.DeepEqual(result, expected) { - fmt.Errorf("Expected <%+v>, Received <%+v>", expected, result) + t.Errorf("\nExpected <%+v>,\nReceived <%+v>", expected, result) + } +} + +func TestGetAvailableCommandsErr(t *testing.T) { + err := getAvailabelCommandsErr() + if err == nil { + t.Errorf("\nExpected not nil,\nReceived <%+v>", err) + } +} + +func TestGetCommandValueCase1(t *testing.T) { + expected := &CmdGetChargersForEvent{ + name: "chargers_for_event", + rpcMethod: utils.ChargerSv1GetChargersForEvent, + rpcParams: &utils.CGREvent{}, + } + result, err := GetCommandValue("chargers_for_event", false) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(utils.ToJSON(result), utils.ToJSON(expected)) { + t.Errorf("\nExpected <%+v>,\nReceived <%+v>", utils.ToJSON(result), utils.ToJSON(expected)) + } +} + +func TestGetCommandValueCase2(t *testing.T) { + _, err := GetCommandValue("", false) + if err == nil { + t.Fatal(err) + } +} + +func TestGetCommandValueCase3(t *testing.T) { + _, err := GetCommandValue("false_command", false) + if err == nil { + t.Fatal(err) + } +} + +func TestGetCommandValueCase4(t *testing.T) { + _, err := GetCommandValue("chargers _for_event", false) + if err == nil { + t.Fatal(err) } } diff --git a/console/parse.go b/console/parse.go index 8e310c3cc..ebce7b134 100644 --- a/console/parse.go +++ b/console/parse.go @@ -19,8 +19,6 @@ along with this program. If not, see package console import ( - "fmt" - "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -79,7 +77,6 @@ func (self *CmdParse) LocalExecute() string { if rsrField, err := config.NewRSRParser(self.rpcParams.Expression); err != nil { return err.Error() } else if parsed, err := rsrField.ParseValue(self.rpcParams.Value); err != nil { - fmt.Println("yay") return err.Error() } else { return parsed