Add ApierV1.GetAttributeProfileIDs method + test for it

This commit is contained in:
TeoV
2018-08-02 08:42:40 -04:00
committed by Dan Christian Bogos
parent 6a73a7cf2c
commit c34bba1749
2 changed files with 30 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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",