diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 1e5ffc1df..c0f7aee32 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -70,6 +70,7 @@ var sTestsOnStorIT = []func(t *testing.T){ testOnStorITCacheTiming, testOnStorITCacheFilter, testOnStorITCacheSupplierProfile, + testOnStorITCacheAliasProfile, // ToDo: test cache flush for a prefix // ToDo: testOnStorITLoadAccountingCache testOnStorITHasData, @@ -102,6 +103,7 @@ var sTestsOnStorIT = []func(t *testing.T){ testOnStorITCRUDThreshold, testOnStorITCRUDFilter, testOnStorITCRUDSupplierProfile, + testOnStorITCRUDAliasProfile, } func TestOnStorITRedisConnect(t *testing.T) { @@ -1145,6 +1147,43 @@ func testOnStorITCacheSupplierProfile(t *testing.T) { } } +func testOnStorITCacheAliasProfile(t *testing.T) { + mapAliases := make(map[string]map[string]string) + mapAliases["FN1"] = make(map[string]string) + mapAliases["FN1"]["Init1"] = "Al1" + alsProfile := &AliasProfile{ + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), + }, + Aliases: mapAliases, + Weight: 20, + } + if err := onStor.SetAliasProfile(alsProfile); err != nil { + t.Error(err) + } + expectedT := []string{"alp_cgrates.org:ALS1"} + if itm, err := onStor.DataDB().GetKeysForPrefix(utils.AliasProfilePrefix); 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.AliasProfilePrefix + alsProfile.TenantID()); hasIt { + t.Error("Already in cache") + } + if err := onStor.CacheDataFromDB(utils.AliasProfilePrefix, []string{alsProfile.TenantID()}, false); err != nil { + t.Error(err) + } + if itm, hasIt := cache.Get(utils.AliasProfilePrefix + alsProfile.TenantID()); !hasIt { + t.Error("Did not cache") + } else if rcv := itm.(*AliasProfile); !reflect.DeepEqual(alsProfile, rcv) { + t.Errorf("Expecting: %+v, received: %+v", alsProfile, rcv) + } +} + func testOnStorITHasData(t *testing.T) { rp := &RatingPlan{ Id: "HasData", @@ -2446,3 +2485,41 @@ func testOnStorITCRUDSupplierProfile(t *testing.T) { t.Error(rcvErr) } } + +func testOnStorITCRUDAliasProfile(t *testing.T) { + mapAliases := make(map[string]map[string]string) + mapAliases["FN1"] = make(map[string]string) + mapAliases["FN1"]["Init1"] = "Al1" + alsProfile := &AliasProfile{ + Tenant: "cgrates.org", + ID: "ALS1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), + }, + Aliases: mapAliases, + Weight: 20, + } + if _, rcvErr := onStor.GetAliasProfile("cgrates.org", "ALS1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { + t.Error(rcvErr) + } + if err := onStor.SetAliasProfile(alsProfile); err != nil { + t.Error(err) + } + if rcv, err := onStor.GetAliasProfile("cgrates.org", "ALS1", true, utils.NonTransactional); err != nil { + t.Error(err) + } else if !(reflect.DeepEqual(alsProfile, rcv)) { + t.Errorf("Expecting: %v, received: %v", alsProfile, rcv) + } + if rcv, err := onStor.GetAliasProfile("cgrates.org", "ALS1", false, utils.NonTransactional); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(alsProfile, rcv) { + t.Errorf("Expecting: %v, received: %v", alsProfile, rcv) + } + if err := onStor.RemoveAliasProfile(alsProfile.Tenant, alsProfile.ID, utils.NonTransactional); err != nil { + t.Error(err) + } + if _, rcvErr := onStor.GetAliasProfile("cgrates.org", "ALS1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { + t.Error(rcvErr) + } +}