From c34bba1749c957062ec65fe600a99c8ca8433a0b Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 2 Aug 2018 08:42:40 -0400 Subject: [PATCH] Add ApierV1.GetAttributeProfileIDs method + test for it --- apier/v1/attributes.go | 19 +++++++++++++++++++ apier/v1/attributes_it_test.go | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/apier/v1/attributes.go b/apier/v1/attributes.go index 1b00be1a4..2984564ce 100644 --- a/apier/v1/attributes.go +++ b/apier/v1/attributes.go @@ -19,6 +19,8 @@ along with this program. If not, see package v1 import ( + "strings" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -39,6 +41,23 @@ func (apierV1 *ApierV1) GetAttributeProfile(arg utils.TenantID, reply *engine.At return nil } +// GetAttributeProfileIDs returns list of threshold IDs registered for a tenant +func (apierV1 *ApierV1) GetAttributeProfileIDs(tenant string, attrPrfIDs *[]string) error { + prfx := utils.AttributeProfilePrefix + keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx) + if err != nil { + return err + } + retIDs := make([]string, 0) + for _, key := range keys { + if strings.Contains(key, tenant) { + retIDs = append(retIDs, key[len(prfx):]) + } + } + *attrPrfIDs = retIDs + return nil +} + //SetAttributeProfile add/update a new Attribute Profile func (apierV1 *ApierV1) SetAttributeProfile(alsPrf *engine.AttributeProfile, reply *string) error { if missing := utils.MissingStructFields(alsPrf, []string{"Tenant", "ID"}); len(missing) != 0 { diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index c16d76457..f58b711a8 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -58,6 +58,7 @@ var sTestsAlsPrf = []func(t *testing.T){ testAttributeSProcessEventWithNoneSubstitute2, testAttributeSProcessEventWithNoneSubstitute3, testAttributeSProcessEventWithHeader, + testAttributeSGetAttPrfIDs, testAttributeSGetAlsPrfBeforeSet, testAttributeSSetAlsPrf, testAttributeSUpdateAlsPrf, @@ -614,6 +615,16 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { } } +func testAttributeSGetAttPrfIDs(t *testing.T) { + expected := []string{"ATTR_2", "ATTR_1", "ATTR_3", "ATTR_Header", "AttributeWithNonSubstitute"} + var result []string + if err := attrSRPC.Call("ApierV1.GetAttributeProfileIDs", "cgrates.org", &result); err != nil { + t.Error(err) + } else if len(expected) != len(result) { + t.Errorf("Expecting : %+v, received: %+v", expected, result) + } +} + func testAttributeSSetAlsPrf(t *testing.T) { alsPrf = &engine.AttributeProfile{ Tenant: "cgrates.org",