diff --git a/engine/resources_test.go b/engine/resources_test.go index 42bfaf1f4..66816ad12 100644 --- a/engine/resources_test.go +++ b/engine/resources_test.go @@ -18,9 +18,11 @@ along with this program. If not, see package engine import ( + "reflect" "testing" "time" + "github.com/cgrates/cgrates/cache" "github.com/cgrates/cgrates/utils" ) @@ -240,3 +242,52 @@ func TestRSAllocateResource(t *testing.T) { t.Error("Duplicate ResourceUsage id should not be allowed") } } + +// TestRSCacheSetGet assurace the presence of private params in cached resource +func TestRSCacheSetGet(t *testing.T) { + r := &Resource{ + ID: "RL", + rPrf: &ResourceProfile{ + ID: "RL", + Filters: []*RequestFilter{ + &RequestFilter{ + Type: MetaString, + FieldName: "Account", + Values: []string{"1001", "1002"}, + }, + &RequestFilter{ + Type: MetaRSRFields, + Values: []string{"Subject(~^1.*1$)", "Destination(1002)"}, + rsrFields: utils.ParseRSRFieldsMustCompile("Subject(~^1.*1$);Destination(1002)", utils.INFIELD_SEP), + }, + }, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 3, 13, 43, 0, 1, time.UTC), + ExpiryTime: time.Date(2014, 7, 3, 13, 43, 0, 1, time.UTC), + }, + AllocationMessage: "ALLOC_RL", + Weight: 50, + Limit: 2, + Thresholds: []string{"TEST_ACTIONS"}, + UsageTTL: time.Duration(1 * time.Millisecond), + }, + Usages: map[string]*ResourceUsage{ + "RU2": &ResourceUsage{ + ID: "RU2", + ExpiryTime: time.Date(2014, 7, 3, 13, 43, 0, 1, time.UTC), + Units: 2, + }, + }, + tUsage: utils.Float64Pointer(2), + dirty: utils.BoolPointer(true), + } + key := utils.ResourcesPrefix + r.ID + cache.Set(key, r, true, "") + if x, ok := cache.Get(key); !ok { + t.Error("not in cache") + } else if x == nil { + t.Error("nil resource") + } else if !reflect.DeepEqual(r, x.(*Resource)) { + t.Errorf("Expecting: +v, received: %+v", r, x) + } +}