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
6ce6cbc47d
commit
6b4b92545d
123
console/parse_test.go
Normal file
123
console/parse_test.go
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCmdParse(t *testing.T) {
|
||||
// commands map is initiated in init function
|
||||
command := commands["parse"]
|
||||
|
||||
// for coverage purpose
|
||||
expected := command.Name()
|
||||
if !reflect.DeepEqual(expected, "parse") {
|
||||
fmt.Errorf("Expected <%+v>, Received <%+v>", "parse", expected)
|
||||
}
|
||||
|
||||
// for coverage purpose
|
||||
expected = command.RpcMethod()
|
||||
if !reflect.DeepEqual(expected, utils.EmptyString) {
|
||||
fmt.Errorf("Expected <%+v>, Received <%+v>", utils.EmptyString, expected)
|
||||
}
|
||||
|
||||
// for coverage purpose
|
||||
expected2 := command.RpcParams(true)
|
||||
if !reflect.DeepEqual(expected, &AttrParse{}) {
|
||||
fmt.Errorf("Expected <%+v>, Received <%+v>", &AttrParse{}, expected2)
|
||||
}
|
||||
|
||||
// for coverage purpose
|
||||
if err := command.RpcResult(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// for coverage purpose
|
||||
if err := command.PostprocessRpcParams(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
func TestCmdParseLocalExecuteCase1(t *testing.T) {
|
||||
// for coverage purpose
|
||||
testStruct := &CmdParse{
|
||||
rpcParams: &AttrParse{
|
||||
Expression: "",
|
||||
Value: "",
|
||||
},
|
||||
}
|
||||
|
||||
result := testStruct.LocalExecute()
|
||||
expected := "Empty expression error"
|
||||
if !reflect.DeepEqual(result, expected) {
|
||||
t.Errorf("Expected <%+v>, Received <%+v>", expected, result)
|
||||
}
|
||||
|
||||
}
|
||||
func TestCmdParseLocalExecuteCase2(t *testing.T) {
|
||||
// for coverage purpose
|
||||
testStruct := &CmdParse{
|
||||
rpcParams: &AttrParse{
|
||||
Expression: "test_exp",
|
||||
Value: "",
|
||||
},
|
||||
}
|
||||
|
||||
result := testStruct.LocalExecute()
|
||||
expected := "Empty value error"
|
||||
if !reflect.DeepEqual(result, expected) {
|
||||
t.Errorf("Expected <%+v>, Received <%+v>", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCmdParseLocalExecuteCase3(t *testing.T) {
|
||||
// for coverage purpose
|
||||
testStruct := &CmdParse{
|
||||
rpcParams: &AttrParse{
|
||||
Expression: "test_exp",
|
||||
Value: "test_val",
|
||||
},
|
||||
}
|
||||
|
||||
result := testStruct.LocalExecute()
|
||||
expected := "test_exp"
|
||||
if !reflect.DeepEqual(result, expected) {
|
||||
t.Errorf("Expected <%+v>, Received <%+v>", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCmdParseLocalExecuteCase4(t *testing.T) {
|
||||
// for coverage purpose
|
||||
testStruct := &CmdParse{
|
||||
rpcParams: &AttrParse{
|
||||
Expression: "~*req.Field{*}",
|
||||
Value: "~*req.Field{*}",
|
||||
},
|
||||
}
|
||||
err := testStruct.LocalExecute()
|
||||
expected := "invalid converter value in string: <*>, err: unsupported converter definition: <*>"
|
||||
if !reflect.DeepEqual(err, expected) {
|
||||
t.Errorf("Expected <%+v>, Received <%+v>", expected, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user