From 954acb5f104c861e0200e49200b0862d71a52aeb Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 22 Feb 2018 05:22:31 -0500 Subject: [PATCH] Add test for GetFilterIndexes method from ApierV1 --- apier/v1/filter_indexes.go | 11 +- apier/v1/filter_indexes_it_test.go | 166 +++++++++++++++++++++++++++++ apier/v1/resourcesv1_it_test.go | 14 +-- 3 files changed, 177 insertions(+), 14 deletions(-) diff --git a/apier/v1/filter_indexes.go b/apier/v1/filter_indexes.go index b88757a59..c33bf0844 100644 --- a/apier/v1/filter_indexes.go +++ b/apier/v1/filter_indexes.go @@ -150,13 +150,10 @@ func (self *ApierV1) GetFilterIndexes(arg AttrGetFilterIndexes, reply *[]string) } type AttrGetFilterReverseIndexes struct { - Tenant string - Context string - ItemType string - ItemIDs []string - FilterType string - FilterField string - FilterValue string + Tenant string + Context string + ItemType string + ItemIDs []string utils.Paginator } diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go index 5c0c9d85d..22ff8395e 100644 --- a/apier/v1/filter_indexes_it_test.go +++ b/apier/v1/filter_indexes_it_test.go @@ -80,6 +80,13 @@ var sTestsFilterIndexesSV1 = []func(t *testing.T){ testV1FIdxSecondComputeAttributeProfileIndexes, testV1FIdxRemoveAttributeProfile, + testFlush, + testV1FIdxPopulateDatabase, + testV1FIdxGetFilterIndexes1, + testV1FIdxGetFilterIndexes2, + testV1FIdxGetFilterIndexes3, + testV1FIdxGetFilterIndexes4, + testV1FIdxStopEngine, } @@ -1523,6 +1530,165 @@ func testV1FIdxRemoveAttributeProfile(t *testing.T) { } } +func testV1FIdxPopulateDatabase(t *testing.T) { + var result string + resPrf := &engine.ResourceProfile{ + Tenant: "cgrates.org", + ID: "ResProfile1", + FilterIDs: []string{"*string:Account:1001", + "*string:Destination:1001", + "*string:Destination:2001", + "*string:Account:1002", + "*prefix:Account:10", + "*string:Destination:1001", + "*prefix:Destination:20", + "*string:Account:1002"}, + } + if err := tFIdxRpc.Call("ApierV1.SetResourceProfile", resPrf, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + resPrf = &engine.ResourceProfile{ + Tenant: "cgrates.org", + ID: "ResProfile2", + FilterIDs: []string{"*string:Account:1001", + "*string:Destination:1001", + "*string:Destination:2001", + "*string:Account:2002", + "*prefix:Account:10", + "*string:Destination:2001", + "*prefix:Destination:20", + "*string:Account:1002"}, + } + if err := tFIdxRpc.Call("ApierV1.SetResourceProfile", resPrf, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + resPrf = &engine.ResourceProfile{ + Tenant: "cgrates.org", + ID: "ResProfile3", + FilterIDs: []string{"*string:Account:3001", + "*string:Destination:1001", + "*string:Destination:2001", + "*string:Account:1002", + "*prefix:Account:10", + "*prefix:Destination:1001", + "*prefix:Destination:200", + "*string:Account:1003"}, + } + if err := tFIdxRpc.Call("ApierV1.SetResourceProfile", resPrf, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } +} + +func testV1FIdxGetFilterIndexes1(t *testing.T) { + arg := &AttrGetFilterIndexes{ + Tenant: "cgrates.org", + ItemType: "*resources", + } + expectedIndexes := []string{ + "*string:Account:1003:ResProfile3", + "*string:Account:3001:ResProfile3", + "*prefix:Destination:200:ResProfile3", + "*string:Destination:1001:ResProfile1", + "*string:Destination:1001:ResProfile2", + "*string:Destination:1001:ResProfile3", + "*string:Account:1002:ResProfile1", + "*string:Account:1002:ResProfile2", + "*string:Account:1002:ResProfile3", + "*string:Account:1001:ResProfile1", + "*string:Account:1001:ResProfile2", + "*string:Destination:2001:ResProfile3", + "*string:Destination:2001:ResProfile1", + "*string:Destination:2001:ResProfile2", + "*prefix:Destination:1001:ResProfile3", + "*string:Account:2002:ResProfile2", + "*prefix:Account:10:ResProfile3", + "*prefix:Destination:20:ResProfile2"} + reply := []string{} + if err := tFIdxRpc.Call("ApierV1.GetFilterIndexes", arg, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(len(expectedIndexes), len(reply)) { + t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(reply)) + } +} + +func testV1FIdxGetFilterIndexes2(t *testing.T) { + arg := &AttrGetFilterIndexes{ + Tenant: "cgrates.org", + ItemType: "*resources", + FilterType: "*string", + } + expectedIndexes := []string{ + "*string:Account:1003:ResProfile3", + "*string:Account:3001:ResProfile3", + "*string:Destination:1001:ResProfile1", + "*string:Destination:1001:ResProfile2", + "*string:Destination:1001:ResProfile3", + "*string:Account:1002:ResProfile1", + "*string:Account:1002:ResProfile2", + "*string:Account:1002:ResProfile3", + "*string:Account:1001:ResProfile1", + "*string:Account:1001:ResProfile2", + "*string:Destination:2001:ResProfile3", + "*string:Destination:2001:ResProfile1", + "*string:Destination:2001:ResProfile2", + "*string:Account:2002:ResProfile2"} + reply := []string{} + if err := tFIdxRpc.Call("ApierV1.GetFilterIndexes", arg, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(len(expectedIndexes), len(reply)) { + t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(reply)) + } +} + +func testV1FIdxGetFilterIndexes3(t *testing.T) { + arg := &AttrGetFilterIndexes{ + Tenant: "cgrates.org", + ItemType: "*resources", + FilterType: "*prefix", + } + expectedIndexes := []string{ + "*prefix:Destination:200:ResProfile3", + "*prefix:Destination:1001:ResProfile3", + "*prefix:Account:10:ResProfile3", + "*prefix:Destination:20:ResProfile2"} + reply := []string{} + if err := tFIdxRpc.Call("ApierV1.GetFilterIndexes", arg, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(len(expectedIndexes), len(reply)) { + t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(reply)) + } +} + +func testV1FIdxGetFilterIndexes4(t *testing.T) { + arg := &AttrGetFilterIndexes{ + Tenant: "cgrates.org", + ItemType: "*resources", + FilterType: "*string", + FilterField: "Account", + } + expectedIndexes := []string{ + "*string:Account:1003:ResProfile3", + "*string:Account:3001:ResProfile3", + "*string:Account:1002:ResProfile1", + "*string:Account:1002:ResProfile2", + "*string:Account:1002:ResProfile3", + "*string:Account:1001:ResProfile1", + "*string:Account:1001:ResProfile2", + "*string:Account:2002:ResProfile2"} + reply := []string{} + if err := tFIdxRpc.Call("ApierV1.GetFilterIndexes", arg, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(len(expectedIndexes), len(reply)) { + t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(reply)) + } +} + func testV1FIdxStopEngine(t *testing.T) { if err := engine.KillEngine(100); err != nil { t.Error(err) diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index f19902a2d..6f4b95742 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -54,13 +54,13 @@ var sTestsRLSV1 = []func(t *testing.T){ testV1RsAuthorizeResources, testV1RsReleaseResource, testV1RsDBStore, - // testV1RsGetResourceProfileBeforeSet, - // testV1RsSetResourceProfile, - // testV1RsGetResourceProfileAfterSet, - // testV1RsUpdateResourceProfile, - // testV1RsGetResourceProfileAfterUpdate, - // testV1RsRemResourceProfile, - // testV1RsGetResourceProfileAfterDelete, + testV1RsGetResourceProfileBeforeSet, + testV1RsSetResourceProfile, + testV1RsGetResourceProfileAfterSet, + testV1RsUpdateResourceProfile, + testV1RsGetResourceProfileAfterUpdate, + testV1RsRemResourceProfile, + testV1RsGetResourceProfileAfterDelete, testV1RsStopEngine, }