mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 06:09:53 +05:00
Add ApierV1.GetAttributeProfileIDs method + test for it
This commit is contained in:
committed by
Dan Christian Bogos
parent
6a73a7cf2c
commit
c34bba1749
@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user