diff --git a/console/datacost_test.go b/console/datacost_test.go index 85df700ff..2c2882a71 100644 --- a/console/datacost_test.go +++ b/console/datacost_test.go @@ -50,4 +50,21 @@ func TestCmdDatacost(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.Category, utils.Tenant, utils.AccountField, utils.Subject, utils.StartTime, utils.Usage} + if !reflect.DeepEqual(result, expected2) { + t.Errorf("Expected <%+v>, Received <%+v>", expected2, result) + } } diff --git a/console/datadb_versions_test.go b/console/datadb_versions_test.go index 9404c59b0..8dbb84836 100644 --- a/console/datadb_versions_test.go +++ b/console/datadb_versions_test.go @@ -18,8 +18,15 @@ along with this program. If not, see package console -//willfix -/* +import ( + "reflect" + "strings" + "testing" + + v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/utils" +) + func TestCmdDataDBVersions(t *testing.T) { // commands map is initiated in init function command := commands["datadb_versions"] @@ -31,11 +38,11 @@ func TestCmdDataDBVersions(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") + + // for coverage purpose + result := command.RpcParams(false) + if !reflect.DeepEqual(result, new(EmptyWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(EmptyWrapper), result) } // verify the type of output parameter if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { @@ -45,5 +52,8 @@ func TestCmdDataDBVersions(t *testing.T) { if err := command.PostprocessRpcParams(); err != nil { t.Fatal(err) } + // for coverage purpose + if err := command.ClientArgs(); err != nil { + t.Fatal(err) + } } -*/ diff --git a/console/load_ids_test.go b/console/load_ids_test.go index 03766fc14..a58775588 100644 --- a/console/load_ids_test.go +++ b/console/load_ids_test.go @@ -18,8 +18,15 @@ along with this program. If not, see package console -//willfix -/* +import ( + "reflect" + "strings" + "testing" + + v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/utils" +) + func TestCmdLoadIDs(t *testing.T) { // commands map is initiated in init function command := commands["get_load_ids"] @@ -31,9 +38,10 @@ func TestCmdLoadIDs(t *testing.T) { if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs t.Fatalf("invalid number of input parameters ") } - // 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") + // for coverage purpose + result := command.RpcParams(false) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { @@ -44,4 +52,3 @@ func TestCmdLoadIDs(t *testing.T) { t.Fatal(err) } } -*/ diff --git a/console/maxduration_test.go b/console/maxduration_test.go index e4f25d8d5..4fcfdaa1e 100644 --- a/console/maxduration_test.go +++ b/console/maxduration_test.go @@ -24,7 +24,6 @@ import ( "testing" v1 "github.com/cgrates/cgrates/apier/v1" - "github.com/cgrates/cgrates/utils" ) @@ -57,4 +56,24 @@ func TestCmdMaxDuration(t *testing.T) { if !reflect.DeepEqual(command.ClientArgs(), expected) { t.Errorf("Expected <%+v>, Received <%+v>", expected, command.ClientArgs()) } + result := command.GetFormatedResult(command.RpcResult()) + if !reflect.DeepEqual(result, `"0s"`) { + t.Errorf("Expected <%+v>, Received <%+v>", `"0s"`, result) + } + +} + +func TestCmdMaxDurationGetFormatedResultCase2(t *testing.T) { + testStruct := &CmdGetMaxDuration{ + name: "", + rpcMethod: "", + rpcParams: nil, + clientArgs: nil, + CommandExecuter: nil, + } + + result := testStruct.GetFormatedResult(testStruct) + if !reflect.DeepEqual(result, "{}") { + t.Errorf("Expected <%+v>, Received <%+v>", "{}", result) + } } diff --git a/console/maxusage_test.go b/console/maxusage_test.go index e1c03c163..bf189e2ba 100644 --- a/console/maxusage_test.go +++ b/console/maxusage_test.go @@ -51,11 +51,23 @@ func TestCmdMaxUsage(t *testing.T) { if err := command.PostprocessRpcParams(); err != nil { t.Fatal(err) } - expected := []string{utils.ToR, utils.RequestType, utils.Tenant, + // 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) + } + expected2 := []string{utils.ToR, utils.RequestType, utils.Tenant, utils.Category, utils.AccountField, utils.Subject, utils.Destination, utils.SetupTime, utils.AnswerTime, utils.Usage, utils.ExtraFields} - if !reflect.DeepEqual(command.ClientArgs(), expected) { - t.Errorf("Expected <%+v>, Received <%+v>", expected, command.ClientArgs()) + if !reflect.DeepEqual(command.ClientArgs(), expected2) { + t.Errorf("Expected <%+v>, Received <%+v>", expected2, command.ClientArgs()) } + } diff --git a/console/sharedgroup_test.go b/console/sharedgroup_test.go index a0491f662..0b56f28ce 100644 --- a/console/sharedgroup_test.go +++ b/console/sharedgroup_test.go @@ -18,8 +18,15 @@ along with this program. If not, see package console -//willfix -/* +import ( + "reflect" + "strings" + "testing" + + v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/utils" +) + func TestCmdSharedGroup(t *testing.T) { // commands map is initiated in init function command := commands["sharedgroup"] @@ -31,11 +38,10 @@ func TestCmdSharedGroup(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") + // for coverage purpose + result := command.RpcParams(false) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { @@ -46,4 +52,3 @@ func TestCmdSharedGroup(t *testing.T) { t.Fatal(err) } } -*/ diff --git a/console/sleep.go b/console/sleep.go index 6c02f23d6..de02f053e 100644 --- a/console/sleep.go +++ b/console/sleep.go @@ -18,7 +18,9 @@ along with this program. If not, see package console -import "github.com/cgrates/cgrates/utils" +import ( + "github.com/cgrates/cgrates/utils" +) func init() { c := &CmdSleep{ diff --git a/console/sleep_test.go b/console/sleep_test.go index 3b5167867..3821ce2b1 100644 --- a/console/sleep_test.go +++ b/console/sleep_test.go @@ -50,4 +50,21 @@ func TestCmdSleep(t *testing.T) { if err := command.PostprocessRpcParams(); err != nil { t.Fatal(err) } + +} +func TestCmdSleepPostprocessRpcParamsCase2(t *testing.T) { + testStruct := &CmdSleep{ + name: "", + rpcMethod: "", + rpcParams: &StringWrapper{ + Item: "test_item", + }, + CommandExecuter: nil, + } + + err := testStruct.PostprocessRpcParams() + if err == nil || err.Error() != "time: invalid duration \"test_item\"" { + t.Errorf("Expected , Received <%T>", err) + } + } diff --git a/console/stordb_versions_test.go b/console/stordb_versions_test.go index 8a6cab6f4..f92fa6b82 100644 --- a/console/stordb_versions_test.go +++ b/console/stordb_versions_test.go @@ -18,7 +18,15 @@ along with this program. If not, see package console -/* +import ( + "reflect" + "strings" + "testing" + + v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/utils" +) + func TestCmdStorDBVersions(t *testing.T) { // commands map is initiated in init function command := commands["stordb_versions"] @@ -30,10 +38,12 @@ 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 ") } - // 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") + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(EmptyWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(EmptyWrapper), result) } + // verify the type of output parameter if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") @@ -42,5 +52,8 @@ func TestCmdStorDBVersions(t *testing.T) { if err := command.PostprocessRpcParams(); err != nil { t.Fatal(err) } + // for coverage purpose + if err := command.ClientArgs(); err != nil { + t.Fatal(err) + } } -*/