mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update integration test with SupplierProfile
This commit is contained in:
committed by
Dan Christian Bogos
parent
d1e5ad908a
commit
215146ea14
@@ -108,7 +108,7 @@ func TestLoaderITLoadFromCSV(t *testing.T) {
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.StatsCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ThresholdsCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.FiltersCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.LCRCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SuppliersCsv),
|
||||
), "", "")
|
||||
|
||||
if err = loader.LoadDestinations(); err != nil {
|
||||
@@ -165,7 +165,7 @@ func TestLoaderITLoadFromCSV(t *testing.T) {
|
||||
if err = loader.LoadThresholds(); err != nil {
|
||||
t.Error("Failed loading thresholds: ", err.Error())
|
||||
}
|
||||
if err = loader.LoadLCRProfiles(); err != nil {
|
||||
if err = loader.LoadSupplierProfiles(); err != nil {
|
||||
t.Error("Failed loading lcr profiles: ", err.Error())
|
||||
}
|
||||
if err := loader.WriteToDatabase(true, false, false); err != nil {
|
||||
@@ -358,12 +358,12 @@ func TestLoaderITWriteToDatabase(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
for tenatid, th := range loader.lcrProfiles {
|
||||
rcv, err := loader.dm.GetLCRProfile(tenatid.Tenant, tenatid.ID, true, utils.NonTransactional)
|
||||
for tenatid, th := range loader.sppProfiles {
|
||||
rcv, err := loader.dm.GetSupplierProfile(tenatid.Tenant, tenatid.ID, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Errorf("Failed GetLCRProfile, tenant: %s, id: %s, error: %s ", th.Tenant, th.ID, err.Error())
|
||||
t.Errorf("Failed GetSupplierProfile, tenant: %s, id: %s, error: %s ", th.Tenant, th.ID, err.Error())
|
||||
}
|
||||
sts, err := APItoLCRProfile(th, "UTC")
|
||||
sts, err := APItoSupplierProfile(th, "UTC")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ var sTestsOnStorIT = []func(t *testing.T){
|
||||
testOnStorITCacheThreshold,
|
||||
testOnStorITCacheTiming,
|
||||
testOnStorITCacheFilter,
|
||||
testOnStorITCacheLCRProfile,
|
||||
testOnStorITCacheSupplierProfile,
|
||||
// ToDo: test cache flush for a prefix
|
||||
// ToDo: testOnStorITLoadAccountingCache
|
||||
testOnStorITHasData,
|
||||
@@ -1099,46 +1099,48 @@ func testOnStorITCacheFilter(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func testOnStorITCacheLCRProfile(t *testing.T) {
|
||||
lcrProfile := &LCRProfile{
|
||||
func testOnStorITCacheSupplierProfile(t *testing.T) {
|
||||
splProfile := &SupplierProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "LCR_1",
|
||||
ID: "SPRF_1",
|
||||
FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(),
|
||||
},
|
||||
Strategy: "*lowest_cost",
|
||||
StrategyParams: []string{},
|
||||
Suppliers: []*LCRSupplier{
|
||||
&LCRSupplier{
|
||||
Sorting: "*lowest_cost",
|
||||
SortingParams: []string{},
|
||||
Suppliers: []*Supplier{
|
||||
&Supplier{
|
||||
ID: "supplier1",
|
||||
RatingPlanIDs: []string{"RPL_1"},
|
||||
FilterIDs: []string{"FLTR_DST_DE"},
|
||||
ResourceIDs: []string{"ResGR1"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
if err := onStor.SetLCRProfile(lcrProfile); err != nil {
|
||||
if err := onStor.SetSupplierProfile(splProfile); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedT := []string{"lcp_cgrates.org:LCR_1"}
|
||||
if itm, err := onStor.DataDB().GetKeysForPrefix(utils.LCRProfilePrefix); err != nil {
|
||||
expectedT := []string{"spp_cgrates.org:SPRF_1"}
|
||||
if itm, err := onStor.DataDB().GetKeysForPrefix(utils.SupplierProfilePrefix); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedT, itm) {
|
||||
t.Errorf("Expected : %+v, but received %+v", expectedT, itm)
|
||||
}
|
||||
|
||||
if _, hasIt := cache.Get(utils.LCRProfilePrefix + lcrProfile.TenantID()); hasIt {
|
||||
if _, hasIt := cache.Get(utils.SupplierProfilePrefix + splProfile.TenantID()); hasIt {
|
||||
t.Error("Already in cache")
|
||||
}
|
||||
if err := onStor.CacheDataFromDB(utils.LCRProfilePrefix, []string{lcrProfile.TenantID()}, false); err != nil {
|
||||
if err := onStor.CacheDataFromDB(utils.SupplierProfilePrefix, []string{splProfile.TenantID()}, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if itm, hasIt := cache.Get(utils.LCRProfilePrefix + lcrProfile.TenantID()); !hasIt {
|
||||
if itm, hasIt := cache.Get(utils.SupplierProfilePrefix + splProfile.TenantID()); !hasIt {
|
||||
t.Error("Did not cache")
|
||||
} else if rcv := itm.(*LCRProfile); !reflect.DeepEqual(lcrProfile, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", lcrProfile, rcv)
|
||||
} else if rcv := itm.(*SupplierProfile); !reflect.DeepEqual(splProfile, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", splProfile, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2398,45 +2400,47 @@ func testOnStorITCRUDFilter(t *testing.T) {
|
||||
}
|
||||
|
||||
func testOnStorITCRUDLCRProfile(t *testing.T) {
|
||||
lcrProfile := &LCRProfile{
|
||||
splProfile := &SupplierProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "LCR_1",
|
||||
ID: "SPRF_1",
|
||||
FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(),
|
||||
},
|
||||
Strategy: "*lowest_cost",
|
||||
StrategyParams: []string{},
|
||||
Suppliers: []*LCRSupplier{
|
||||
&LCRSupplier{
|
||||
Sorting: "*lowest_cost",
|
||||
SortingParams: []string{},
|
||||
Suppliers: []*Supplier{
|
||||
&Supplier{
|
||||
ID: "supplier1",
|
||||
RatingPlanIDs: []string{"RPL_1"},
|
||||
FilterIDs: []string{"FLTR_DST_DE"},
|
||||
ResourceIDs: []string{"ResGR1"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
if _, rcvErr := onStor.GetLCRProfile("cgrates.org", "LCR_1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
if _, rcvErr := onStor.GetSupplierProfile("cgrates.org", "SPRF_1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
if err := onStor.SetLCRProfile(lcrProfile); err != nil {
|
||||
if err := onStor.SetSupplierProfile(splProfile); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rcv, err := onStor.GetLCRProfile("cgrates.org", "LCR_1", true, utils.NonTransactional); err != nil {
|
||||
if rcv, err := onStor.GetSupplierProfile("cgrates.org", "SPRF_1", true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(lcrProfile, rcv)) {
|
||||
t.Errorf("Expecting: %v, received: %v", lcrProfile, rcv)
|
||||
} else if !(reflect.DeepEqual(splProfile, rcv)) {
|
||||
t.Errorf("Expecting: %v, received: %v", splProfile, rcv)
|
||||
}
|
||||
if rcv, err := onStor.GetLCRProfile("cgrates.org", "LCR_1", false, utils.NonTransactional); err != nil {
|
||||
if rcv, err := onStor.GetSupplierProfile("cgrates.org", "SPRF_1", false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(lcrProfile, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", lcrProfile, rcv)
|
||||
} else if !reflect.DeepEqual(splProfile, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", splProfile, rcv)
|
||||
}
|
||||
if err := onStor.RemoveLCRProfile(lcrProfile.Tenant, lcrProfile.ID, utils.NonTransactional); err != nil {
|
||||
if err := onStor.RemoveSupplierProfile(splProfile.Tenant, splProfile.ID, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, rcvErr := onStor.GetLCRProfile("cgrates.org", "LCR_1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
if _, rcvErr := onStor.GetSupplierProfile("cgrates.org", "SPRF_1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestTutSMGCacheStats(t *testing.T) {
|
||||
expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 10,
|
||||
Actions: 9, ActionPlans: 4, AccountActionPlans: 5, SharedGroups: 1, DerivedChargers: 1, LcrProfiles: 5,
|
||||
CdrStats: 6, Users: 3, Aliases: 1, ReverseAliases: 2, ResourceProfiles: 3, Resources: 3, StatQueues: 1,
|
||||
StatQueueProfiles: 1, Thresholds: 7, ThresholdProfiles: 7, Filters: 16, LCRProfiles: 1}
|
||||
StatQueueProfiles: 1, Thresholds: 7, ThresholdProfiles: 7, Filters: 16, SupplierProfiles: 2}
|
||||
var args utils.AttrCacheStats
|
||||
if err := tutSMGRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil {
|
||||
t.Error("Got error on ApierV2.GetCacheStats: ", err.Error())
|
||||
|
||||
@@ -105,7 +105,7 @@ func TestTutITCacheStats(t *testing.T) {
|
||||
expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 10,
|
||||
Actions: 9, ActionPlans: 4, AccountActionPlans: 5, SharedGroups: 1, DerivedChargers: 1, LcrProfiles: 5,
|
||||
CdrStats: 6, Users: 3, Aliases: 1, ReverseAliases: 2, ResourceProfiles: 3, Resources: 3, StatQueues: 1,
|
||||
StatQueueProfiles: 1, Thresholds: 7, ThresholdProfiles: 7, Filters: 16, LCRProfiles: 1}
|
||||
StatQueueProfiles: 1, Thresholds: 7, ThresholdProfiles: 7, Filters: 16, SupplierProfiles: 2}
|
||||
var args utils.AttrCacheStats
|
||||
if err := tutLocalRpc.Call("ApierV1.GetCacheStats", args, &rcvStats); err != nil {
|
||||
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
|
||||
|
||||
Reference in New Issue
Block a user