mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Coverage tests in console
This commit is contained in:
committed by
Dan Christian Bogos
parent
6b4b92545d
commit
634638184d
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,59 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user