Coverage tests in console

This commit is contained in:
andronache
2021-01-27 17:27:52 +02:00
committed by Dan Christian Bogos
parent 8b94da6bed
commit c8d0ee6045
9 changed files with 97 additions and 10 deletions

View File

@@ -51,4 +51,15 @@ func TestCmdAccounts(t *testing.T) {
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
}
}

View File

@@ -51,4 +51,15 @@ func TestCmdActiveSessions(t *testing.T) {
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedSliceResult(command.RpcResult(), utils.StringSet{
utils.Usage: {},
utils.DurationIndex: {},
utils.MaxRateUnit: {},
utils.DebitInterval: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
}
}

View File

@@ -51,4 +51,12 @@ func TestCmdAttributesProcessEvent(t *testing.T) {
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
utils.Usage: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
}
}

View File

@@ -50,4 +50,13 @@ func TestCmdChargersProcessEvent(t *testing.T) {
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
utils.Usage: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
}
}

View File

@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
//willfix
/*
func TestCmdComputeActionPlanIndexes(t *testing.T) {
// commands map is initiated in init function
@@ -31,8 +30,7 @@ func TestCmdComputeActionPlanIndexes(t *testing.T) {
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
fmt.Println(m.Type.In(1))
fmt.Println(reflect.TypeOf(command.RpcParams(true)))
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")

View File

@@ -50,4 +50,21 @@ func TestCmdCost(t *testing.T) {
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
// for coverage purpose
formatedResult := command.GetFormatedResult(command.RpcResult())
expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
if !reflect.DeepEqual(formatedResult, expected) {
t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
}
// for coverage purpose
result := command.ClientArgs()
expected2 := []string{utils.Tenant, utils.Category, utils.Subject, utils.AnswerTime, utils.Destination, utils.Usage}
if !reflect.DeepEqual(result, expected2) {
t.Errorf("Expected <%+v>, Received <%+v>", expected2, result)
}
}

View File

@@ -18,7 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
/*
import (
"reflect"
"strings"
"testing"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func TestCmdRatingPlanRem(t *testing.T) {
// commands map is initiated in init function
command := commands["ratingprofile_remove"]
@@ -38,9 +46,36 @@ func TestCmdRatingPlanRem(t *testing.T) {
if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
t.Fatalf("cannot assign output parameter")
}
// for coverage purpose
if err := command.PostprocessRpcParams(); err != nil {
}
func TestCmdRatingPlanRemPostprocessRpcParams(t *testing.T) {
testStruct := CmdRemRatingProfile{
name: "",
rpcMethod: "",
rpcParams: nil,
rpcResult: "",
CommandExecuter: nil,
}
if err := testStruct.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}
*/
func TestCmdRatingPlanRemPostprocessRpcParamsError(t *testing.T) {
testStruct := CmdRemRatingProfile{
name: "",
rpcMethod: "",
rpcParams: &v1.AttrRemoveRatingProfile{},
rpcResult: "",
CommandExecuter: nil,
}
err := testStruct.PostprocessRpcParams()
if err == nil || err != utils.ErrMandatoryIeMissing {
t.Fatal(err)
}
}

View File

@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
//willfix
/*
func TestCmdStorDBVersions(t *testing.T) {
// commands map is initiated in init function
@@ -31,8 +30,6 @@ func TestCmdStorDBVersions(t *testing.T) {
if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
t.Fatalf("invalid number of input parameters ")
}
fmt.Println(m.Type.In(1))
fmt.Println(reflect.TypeOf(command.RpcParams(true)))
// verify the type of input parameter
if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
t.Fatalf("cannot assign input parameter")

View File

@@ -50,4 +50,5 @@ func TestCmdThreshold(t *testing.T) {
if err := command.PostprocessRpcParams(); err != nil {
t.Fatal(err)
}
}