mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
ResourceS cache for private vars test
This commit is contained in:
@@ -18,9 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user