mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add test for apier with dispatcher
This commit is contained in:
committed by
Dan Christian Bogos
parent
fbc9f2332d
commit
648911d82b
@@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
// GetAttributeProfile returns an Attribute Profile
|
||||
func (apierV1 *ApierV1) GetAttributeProfile(arg utils.TenantID, reply *engine.AttributeProfile) error {
|
||||
func (apierV1 *ApierV1) GetAttributeProfile(arg utils.TenantIDWithArgDispatcher, reply *engine.AttributeProfile) error {
|
||||
if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
@@ -65,6 +65,7 @@ func (apierV1 *ApierV1) GetAttributeProfileIDs(args utils.TenantArgWithPaginator
|
||||
type AttributeWithCache struct {
|
||||
*engine.AttributeProfile
|
||||
Cache *string
|
||||
*utils.ArgDispatcher
|
||||
}
|
||||
|
||||
//SetAttributeProfile add/update a new Attribute Profile
|
||||
|
||||
@@ -205,15 +205,15 @@ func (dS *DispatcherService) V1Apier(apier interface{}, args *utils.MethodParame
|
||||
var argD *utils.ArgDispatcher
|
||||
//check if we have APIKey in event and in case it has add it in ArgDispatcher
|
||||
apiKeyIface, hasApiKey := parameters[utils.APIKey]
|
||||
if hasApiKey {
|
||||
if hasApiKey && apiKeyIface != nil {
|
||||
argD = &utils.ArgDispatcher{
|
||||
APIKey: utils.StringPointer(apiKeyIface.(string)),
|
||||
}
|
||||
}
|
||||
//check if we have RouteID in event and in case it has add it in ArgDispatcher
|
||||
routeIDIface, hasRouteID := parameters[utils.RouteID]
|
||||
if hasRouteID {
|
||||
if !hasApiKey { //in case we don't have APIKey, but we have RouteID we need to initialize the struct
|
||||
if hasRouteID && routeIDIface != nil {
|
||||
if !hasApiKey || apiKeyIface == nil { //in case we don't have APIKey, but we have RouteID we need to initialize the struct
|
||||
argD = &utils.ArgDispatcher{
|
||||
RouteID: utils.StringPointer(routeIDIface.(string)),
|
||||
}
|
||||
|
||||
@@ -19,3 +19,112 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package dispatchers
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var sTestsDspApier = []func(t *testing.T){
|
||||
testDspApierSetAttributes,
|
||||
testDspApierGetAttributes,
|
||||
testDspApierUnkownAPiKey,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestDspApierITMySQL(t *testing.T) {
|
||||
testDsp(t, sTestsDspApier, "TestDspApier", "all", "all2", "dispatchers", "tutorial", "oldtutorial", "dispatchers")
|
||||
}
|
||||
|
||||
func TestDspApierITMongo(t *testing.T) {
|
||||
testDsp(t, sTestsDspApier, "TestDspApier", "all", "all2", "dispatchers_mongo", "tutorial", "oldtutorial", "dispatchers")
|
||||
}
|
||||
|
||||
//because we import dispatchers in apierV1 we will send information as map[string]interface{}
|
||||
func testDspApierSetAttributes(t *testing.T) {
|
||||
ev := &map[string]interface{}{
|
||||
utils.Tenant: "cgrates.org",
|
||||
"ID": "ATTR_Dispatcher",
|
||||
"Contexts": []string{utils.MetaSessionS},
|
||||
"FilterIDs": []string{"*string:~Account:1234"},
|
||||
"ActivationInterval": &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
"Attributes": []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.Subject,
|
||||
Value: config.RSRParsers{
|
||||
&config.RSRParser{
|
||||
Rules: "roam",
|
||||
AllFiltersMatch: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"Weight": 10,
|
||||
utils.APIKey: utils.StringPointer("apier12345"),
|
||||
}
|
||||
var result string
|
||||
if err := dispEngine.RCP.Call("ApierV1.SetAttributeProfile", ev, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testDspApierGetAttributes(t *testing.T) {
|
||||
var reply *engine.AttributeProfile
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ATTR_Dispatcher",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"*string:~Account:1234"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.Subject,
|
||||
Value: config.RSRParsers{
|
||||
&config.RSRParser{
|
||||
Rules: "roam",
|
||||
AllFiltersMatch: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Weight: 10,
|
||||
}
|
||||
alsPrf.Compile()
|
||||
if err := dispEngine.RCP.Call("ApierV1.GetAttributeProfile",
|
||||
utils.TenantIDWithArgDispatcher{
|
||||
TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_Dispatcher"},
|
||||
ArgDispatcher: &utils.ArgDispatcher{APIKey: utils.StringPointer("apier12345")}}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testDspApierUnkownAPiKey(t *testing.T) {
|
||||
var reply *engine.AttributeProfile
|
||||
|
||||
if err := dispEngine.RCP.Call("ApierV1.GetAttributeProfile",
|
||||
utils.TenantIDWithArgDispatcher{
|
||||
TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_Dispatcher"},
|
||||
ArgDispatcher: &utils.ArgDispatcher{APIKey: utils.StringPointer("RandomApiKey")}}, &reply); err == nil || err.Error() != utils.ErrUnknownApiKey.Error() {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user