mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add coverage tests for engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
8db9d6ca4d
commit
e90ef030d1
@@ -848,3 +848,83 @@ func TestPopulateSortingDataStatMetrics(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibSuppliersSupplierIDs(t *testing.T) {
|
||||
sSpls := &SortedSuppliers{
|
||||
ProfileID: str,
|
||||
Sorting: str,
|
||||
Count: nm,
|
||||
SortedSuppliers: []*SortedSupplier{
|
||||
{
|
||||
SupplierID: str,
|
||||
SupplierParameters: str,
|
||||
SortingData: map[string]any{str: str},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rcv := sSpls.SupplierIDs()
|
||||
exp := []string{str}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("expected %s, received %s", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibSupplierAsNavigableMap(t *testing.T) {
|
||||
ss := &SortedSupplier{
|
||||
SupplierID: str,
|
||||
SupplierParameters: str,
|
||||
SortingData: map[string]any{str: str},
|
||||
}
|
||||
|
||||
rcv := ss.AsNavigableMap()
|
||||
exp := utils.NavigableMap2{
|
||||
"SupplierID": utils.NewNMData(ss.SupplierID),
|
||||
"SupplierParameters": utils.NewNMData(ss.SupplierParameters),
|
||||
"SortingData": utils.NavigableMap2{str: utils.NewNMData(str)},
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("expected %s, received %s", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibSuppliersAsNavigableMap(t *testing.T) {
|
||||
sSpls := &SortedSuppliers{
|
||||
ProfileID: str,
|
||||
Sorting: str,
|
||||
Count: nm,
|
||||
SortedSuppliers: []*SortedSupplier{
|
||||
{
|
||||
SupplierID: str,
|
||||
SupplierParameters: str,
|
||||
SortingData: map[string]any{str: str},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rcv := sSpls.AsNavigableMap()
|
||||
exp := utils.NavigableMap2{
|
||||
"ProfileID": utils.NewNMData(sSpls.ProfileID),
|
||||
"Sorting": utils.NewNMData(sSpls.Sorting),
|
||||
"Count": utils.NewNMData(sSpls.Count),
|
||||
"SortedSuppliers": &utils.NMSlice{sSpls.SortedSuppliers[0].AsNavigableMap()},
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("expected %s, received %s", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibSuppliersSortSuppliers(t *testing.T) {
|
||||
ssd := SupplierSortDispatcher{}
|
||||
|
||||
_, err := ssd.SortSuppliers(str, str, []*Supplier{}, &utils.CGREvent{}, &optsGetSuppliers{}, nil)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "unsupported sorting strategy: test" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -395,3 +397,128 @@ func TestRatingProfileSubjectPrefixMatching(t *testing.T) {
|
||||
}
|
||||
rpSubjectPrefixMatching = false
|
||||
}
|
||||
|
||||
func TestRatingProfileEqual(t *testing.T) {
|
||||
rpa := &RatingPlanActivation{
|
||||
ActivationTime: time.Date(2021, 7, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RatingPlanId: "test",
|
||||
FallbackKeys: []string{"test"},
|
||||
}
|
||||
orpa := &RatingPlanActivation{
|
||||
ActivationTime: time.Date(2021, 7, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RatingPlanId: "test",
|
||||
FallbackKeys: []string{"test"},
|
||||
}
|
||||
|
||||
rcv := rpa.Equal(orpa)
|
||||
|
||||
if rcv != true {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRatingProfileSwap(t *testing.T) {
|
||||
rpa := &RatingPlanActivation{
|
||||
ActivationTime: time.Date(2021, 7, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RatingPlanId: "test",
|
||||
FallbackKeys: []string{"test"},
|
||||
}
|
||||
orpa := &RatingPlanActivation{
|
||||
ActivationTime: time.Date(2021, 7, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RatingPlanId: "val1",
|
||||
FallbackKeys: []string{"val1"},
|
||||
}
|
||||
rpas := RatingPlanActivations{rpa, orpa}
|
||||
|
||||
rpas.Swap(0, 1)
|
||||
|
||||
if !reflect.DeepEqual(rpas[0], orpa) {
|
||||
t.Error("didn't swap")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRatingProfileSwapInfos(t *testing.T) {
|
||||
ri := &RatingInfo{
|
||||
MatchedSubject: str,
|
||||
RatingPlanId: str,
|
||||
MatchedPrefix: str,
|
||||
MatchedDestId: str,
|
||||
ActivationTime: time.Date(2021, 7, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RateIntervals: RateIntervalList{},
|
||||
FallbackKeys: []string{str},
|
||||
}
|
||||
ri2 := &RatingInfo{
|
||||
MatchedSubject: "val1",
|
||||
RatingPlanId: "val2",
|
||||
MatchedPrefix: str,
|
||||
MatchedDestId: str,
|
||||
ActivationTime: time.Date(2021, 7, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RateIntervals: RateIntervalList{},
|
||||
FallbackKeys: []string{"val1"},
|
||||
}
|
||||
ris := RatingInfos{ri, ri2}
|
||||
|
||||
ris.Swap(1, 0)
|
||||
|
||||
if !reflect.DeepEqual(ris[1], ri) {
|
||||
t.Error("didn't swap")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRatingProfileLess(t *testing.T) {
|
||||
ri := &RatingInfo{
|
||||
MatchedSubject: str,
|
||||
RatingPlanId: str,
|
||||
MatchedPrefix: str,
|
||||
MatchedDestId: str,
|
||||
ActivationTime: time.Date(2021, 7, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RateIntervals: RateIntervalList{},
|
||||
FallbackKeys: []string{str},
|
||||
}
|
||||
ri2 := &RatingInfo{
|
||||
MatchedSubject: "val1",
|
||||
RatingPlanId: "val2",
|
||||
MatchedPrefix: str,
|
||||
MatchedDestId: str,
|
||||
ActivationTime: time.Date(2021, 5, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RateIntervals: RateIntervalList{},
|
||||
FallbackKeys: []string{"val1"},
|
||||
}
|
||||
ris := RatingInfos{ri, ri2}
|
||||
|
||||
rcv := ris.Less(0, 1)
|
||||
|
||||
if rcv != false {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRatingProfileString(t *testing.T) {
|
||||
ri := &RatingInfo{
|
||||
MatchedSubject: str,
|
||||
RatingPlanId: str,
|
||||
MatchedPrefix: str,
|
||||
MatchedDestId: str,
|
||||
ActivationTime: time.Date(2021, 7, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RateIntervals: RateIntervalList{},
|
||||
FallbackKeys: []string{str},
|
||||
}
|
||||
ri2 := &RatingInfo{
|
||||
MatchedSubject: "val1",
|
||||
RatingPlanId: "val2",
|
||||
MatchedPrefix: str,
|
||||
MatchedDestId: str,
|
||||
ActivationTime: time.Date(2021, 5, 2, 4, 23, 3, 1234, time.UTC),
|
||||
RateIntervals: RateIntervalList{},
|
||||
FallbackKeys: []string{"val1"},
|
||||
}
|
||||
ris := RatingInfos{ri, ri2}
|
||||
|
||||
rcv := ris.String()
|
||||
b, _ := json.MarshalIndent(ris, "", " ")
|
||||
exp := string(b)
|
||||
|
||||
if rcv != exp {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,3 +135,39 @@ func TestTaskRemoteHost(t *testing.T) {
|
||||
t.Errorf("Expecting: %q, received: %q", eOut, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskExecute(t *testing.T) {
|
||||
ts := &Task{
|
||||
Uuid: str,
|
||||
AccountID: str,
|
||||
ActionsID: str,
|
||||
}
|
||||
|
||||
err := ts.Execute()
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "NOT_FOUND" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskFieldAsString2(t *testing.T) {
|
||||
ts := &Task{
|
||||
Uuid: str,
|
||||
AccountID: str,
|
||||
ActionsID: str,
|
||||
}
|
||||
|
||||
rcv, err := ts.FieldAsString([]string{"test"})
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "NOT_FOUND:test" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if rcv != "" {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,71 @@ func TestVarsionCheckVersions(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
vrs := Versions{"test": 1}
|
||||
data.SetVersions(vrs, true)
|
||||
|
||||
err = CheckVersions(data)
|
||||
|
||||
if err != nil {
|
||||
if err.Error()[0] != 'M' {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
vrs2 := Versions{
|
||||
utils.StatS: 3,
|
||||
utils.Accounts: 3,
|
||||
utils.Actions: 2,
|
||||
utils.ActionTriggers: 2,
|
||||
utils.ActionPlans: 3,
|
||||
utils.SharedGroups: 2,
|
||||
utils.Thresholds: 3,
|
||||
utils.Suppliers: 1,
|
||||
utils.Attributes: 5,
|
||||
utils.Timing: 1,
|
||||
utils.RQF: 4,
|
||||
utils.Resource: 1,
|
||||
utils.Subscribers: 1,
|
||||
utils.Destinations: 1,
|
||||
utils.ReverseDestinations: 1,
|
||||
utils.RatingPlan: 1,
|
||||
utils.RatingProfile: 1,
|
||||
utils.Chargers: 1,
|
||||
utils.Dispatchers: 1,
|
||||
utils.LoadIDsVrs: 1,
|
||||
utils.CostDetails: 2,
|
||||
utils.SessionSCosts: 3,
|
||||
utils.CDRs: 2,
|
||||
utils.TpRatingPlans: 1,
|
||||
utils.TpFilters: 1,
|
||||
utils.TpDestinationRates: 1,
|
||||
utils.TpActionTriggers: 1,
|
||||
utils.TpAccountActionsV: 1,
|
||||
utils.TpActionPlans: 1,
|
||||
utils.TpActions: 1,
|
||||
utils.TpThresholds: 1,
|
||||
utils.TpSuppliers: 1,
|
||||
utils.TpStats: 1,
|
||||
utils.TpSharedGroups: 1,
|
||||
utils.TpRatingProfiles: 1,
|
||||
utils.TpResources: 1,
|
||||
utils.TpRates: 1,
|
||||
utils.TpTiming: 1,
|
||||
utils.TpResource: 1,
|
||||
utils.TpDestinations: 1,
|
||||
utils.TpRatingPlan: 1,
|
||||
utils.TpRatingProfile: 1,
|
||||
utils.TpChargers: 1,
|
||||
utils.TpDispatchers: 1,
|
||||
}
|
||||
data.SetVersions(vrs2, true)
|
||||
|
||||
err = CheckVersions(data)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionSetDBVersions(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user