github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/model/core/cache_test.go (about) 1 // Ultimate Provisioner: UP cmd 2 // Copyright (c) 2019 Stephen Cheng and contributors 3 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 7 8 package core 9 10 import ( 11 u "github.com/upcmd/up/utils" 12 "testing" 13 ) 14 15 type TestObj struct { 16 Fa string 17 Fb int 18 Fc []string 19 } 20 21 func TestCache(t *testing.T) { 22 //TODO: fix it 23 //u.SetMockConfig() 24 u.Pln("start testing") 25 26 c := GetCache() 27 c.Put("1key", "key1_value") 28 c.Put("2key", "key2_value") 29 c.Put("3obj", TestObj{"fa", 24, []string{"a1", "b2"}}) 30 31 c.List() 32 33 c.SafeGet("1key") 34 v1, ok := c.SafeGet("1key") 35 36 u.Pf("%+v -> %+v\n", ok, v1) 37 c.Update("1key", "key1_value_with_update") 38 u.Pln(c.Get("1key")) 39 c.Obsolete("2key") 40 c.List() 41 u.Pln("-2key deleted") 42 c.Delete("2key") 43 c.List() 44 45 }