Coverage in console

This commit is contained in:
andronache
2021-01-28 14:10:38 +02:00
committed by Dan Christian Bogos
parent 5dabd5c618
commit 1973d906d4
9 changed files with 134 additions and 32 deletions

View File

@@ -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)
}
}

View File

@@ -18,8 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
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)
}
}
*/

View File

@@ -18,8 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
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)
}
}
*/

View File

@@ -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)
}
}

View File

@@ -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())
}
}

View File

@@ -18,8 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
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)
}
}
*/

View File

@@ -18,7 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import "github.com/cgrates/cgrates/utils"
import (
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdSleep{

View File

@@ -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 <time: invalid duration \"test_item\">, Received <%T>", err)
}
}

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 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)
}
}
*/