From 8014c9dffbc00c5c2aafb7fe891f555a7e5b1706 Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 4 Feb 2021 10:20:02 +0200 Subject: [PATCH] Add resource case in fullRemote integration tests --- apier/v1/full_remote_it_test.go | 62 +++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/apier/v1/full_remote_it_test.go b/apier/v1/full_remote_it_test.go index 371c3de35..8620b6a2a 100644 --- a/apier/v1/full_remote_it_test.go +++ b/apier/v1/full_remote_it_test.go @@ -51,8 +51,9 @@ var ( testFullRemoteITRPCConn, testFullRemoteITAttribute, - testFullRemoteITStatQueuq, + testFullRemoteITStatQueue, testFullRemoteITThreshold, + testFullRemoteITResource, testFullRemoteITKillEngine, } @@ -181,7 +182,7 @@ func testFullRemoteITAttribute(t *testing.T) { } } -func testFullRemoteITStatQueuq(t *testing.T) { +func testFullRemoteITStatQueue(t *testing.T) { // verify for not found in internal var reply *engine.StatQueueProfile if err := fullRemInternalRPC.Call(utils.APIerSv1GetStatQueueProfile, @@ -306,6 +307,63 @@ func testFullRemoteITThreshold(t *testing.T) { } } +func testFullRemoteITResource(t *testing.T) { + // verify for not found in internal + var reply *engine.ResourceProfile + if err := fullRemInternalRPC.Call(utils.APIerSv1GetResourceProfile, + utils.TenantIDWithOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}}, + &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Fatal(err) + } + + var replySet string + rlsPrf := &ResourceWithCache{ + ResourceProfile: &engine.ResourceProfile{ + Tenant: "cgrates.org", + ID: "ResGroup1", + FilterIDs: []string{"*string:~*req.Account:1001"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC), + }, + UsageTTL: -1, + Limit: 7, + AllocationMessage: "", + Stored: true, + Weight: 10, + ThresholdIDs: []string{utils.MetaNone}, + }, + } + // add a threshold profile in engine1 and verify it internal + if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetResourceProfile, rlsPrf, &replySet); err != nil { + t.Error(err) + } else if replySet != utils.OK { + t.Error("Unexpected reply returned", replySet) + } + + if err := fullRemInternalRPC.Call(utils.APIerSv1GetResourceProfile, + utils.TenantIDWithOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}}, + &reply); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(rlsPrf.ResourceProfile, reply) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(rlsPrf.ResourceProfile), utils.ToJSON(reply)) + } + // update the threshold profile and verify it to be updated + rlsPrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"} + if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetResourceProfile, rlsPrf, &replySet); err != nil { + t.Error(err) + } else if replySet != utils.OK { + t.Error("Unexpected reply returned", replySet) + } + + if err := fullRemInternalRPC.Call(utils.APIerSv1GetResourceProfile, + utils.TenantIDWithOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}}, + &reply); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(rlsPrf.ResourceProfile, reply) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(rlsPrf.ResourceProfile), utils.ToJSON(reply)) + } +} + func testFullRemoteITKillEngine(t *testing.T) { if err := engine.KillEngine(100); err != nil { t.Error(err)