Commit aae0de39 authored by Akshay Bharambe's avatar Akshay Bharambe
Browse files

Add: GetAll for fastCache

parent 09b73e64
Branches
Tags
2 merge requests!210Staging mepdeployment05072020,!206Add: Enable users to view data present in session manager
Showing with 58 additions and 0 deletions
......@@ -103,3 +103,15 @@ func (fastCacheHelper *FastCacheHelper) GetItemsCount() int {
func (fh *FastCacheHelper) Type() int {
return TypeFastCache
}
// GetAll returns all keys with values present in memory. **This is not intended for production use. May hamper performance**
func (fastCacheHelper *FastCacheHelper) GetAll() map[string]interface{} {
items := fastCacheHelper.FastCache.Items()
result := make(map[string]interface{}, len(items))
for k, v := range items {
result[k] = v.Object
}
return result
}
//@author Ajit Jagtap
//@version Thu Jul 05 2018 06:11:54 GMT+0530 (IST)
package cachemdl
import (
"reflect"
"testing"
)
// import (
// "testing"
// "time"
......@@ -39,3 +46,42 @@ package cachemdl
// cnt = ch.Count()
// assert.Zero(t, cnt, "After Purge Count should be zero")
// }
func TestFastCacheHelper_GetAll(t *testing.T) {
tests := []struct {
name string
fastCacheHelper *FastCacheHelper
want map[string]interface{}
init func(fs *FastCacheHelper)
}{
{
name: "Get all items Success",
fastCacheHelper: &FastCacheHelper{},
want: map[string]interface{}{
"a": 1,
"b": 2,
},
init: func(fs *FastCacheHelper) {
fs.Setup(2, 0, 0)
fs.Set("a", 1)
fs.Set("b", 2)
},
},
{
name: "Get all items Empty",
fastCacheHelper: &FastCacheHelper{},
want: map[string]interface{}{},
init: func(fs *FastCacheHelper) {
fs.Setup(2, 0, 0)
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.init(tt.fastCacheHelper)
if got := tt.fastCacheHelper.GetAll(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("FastCacheHelper.GetAll() = %v, want %v", got, tt.want)
}
})
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment