1/* 2 * Copyright 2012-2019 Li Kexian 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 * A toolkit for Golang development 17 * https://www.likexian.com/ 18 */ 19 20package xcache 21 22import ( 23 "github.com/likexian/gokit/assert" 24 "testing" 25) 26 27func TestVersion(t *testing.T) { 28 assert.Contains(t, Version(), ".") 29 assert.Contains(t, Author(), "likexian") 30 assert.Contains(t, License(), "Apache License") 31} 32 33func TestNew(t *testing.T) { 34 c := New(MemoryCache) 35 defer c.Close() 36 37 b := c.Has("x") 38 assert.False(t, b) 39 40 v := c.Get("x") 41 assert.Equal(t, v, nil) 42 43 err := c.Set("x", 1, 0) 44 assert.Nil(t, err) 45 46 b = c.Has("x") 47 assert.True(t, b) 48 49 v = c.Get("x") 50 assert.Equal(t, v, 1) 51 52 err = c.Del("x") 53 assert.Nil(t, err) 54 55 b = c.Has("x") 56 assert.False(t, b) 57 58 v = c.Get("x") 59 assert.Equal(t, v, nil) 60} 61