• Akshay Bharambe's avatar
    Add: marshal with type check version · 0b0a7917
    Akshay Bharambe authored
    1. Add: marshal with type check version. This saves allocations and time if existing data is string or []byte.
    2. Fix: Typos.
    3. Add: Benchmarks for marshal and marshalWithTypeCheck
    0b0a7917
cachemdl_test.go 1.95 KiB
//@author  Ajit Jagtap
//@version Thu Jul 05 2018 06:11:54 GMT+0530 (IST)
package cachemdl
import (
	"reflect"
	"testing"
// import (
// 	"testing"
// 	"time"
// 	"github.com/stretchr/testify/assert"
// )
// var ch GCCacheHelper
// func init() {
// 	ch = GCCacheHelper{}
// 	ch.Setup(500, time.Minute*50)
// }
// func TestCacheGCHelper_Setup(t *testing.T) {
// 	assert.NotPanics(t, func() { ch.Setup(500, time.Minute*50) }, "This Setup method should never panic")
// }
// func TestCacheGCHelper_Set(t *testing.T) {
// 	ch.Set("a", 1)
// 	val, _ := ch.Get("a")
// 	assert.Equal(t, val, 1, "This Cache get should return same value as set")
// }
// func TestCacheGCHelper_GetAll(t *testing.T) {
// 	ch.Set("a", 1)
// 	val := ch.GetAll()
// 	assert.NotZero(t, len(val), "Check if GetAll return more than zero values")
// 	cnt := ch.Count()
// 	assert.NotZero(t, cnt, "Check if Count method will give more than zero value")
// 	ch.Remove("a")
// 	ch.Purge()
// 	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)
717273747576777879808182838485868788
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) } }) } }