forked from hanguofeng/gocaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cstore_test.go
57 lines (46 loc) · 1.02 KB
/
cstore_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2013 hanguofeng. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gocaptcha
import (
"os"
"testing"
"time"
)
func TestStore(t *testing.T) {
store := CreateCStore(10*time.Second, 1, 100) //10 s
captcha := new(CaptchaInfo)
captcha.Text = "hello"
captcha.CreateTime = time.Now()
//test add and get
key := store.Add(captcha)
retV := store.Get(key)
if retV != captcha {
t.Errorf("not equal")
}
retV.Text = "world"
store.Update(key, retV)
retV = store.Get(key)
if retV.Text != "world" {
t.Errorf("update not equal")
}
//test dump,destroy and loaddumped
store.Dump("data/data.dat")
store.Destroy()
retV = store.Get(key)
if nil != retV {
t.Errorf("Destroy error")
}
store.LoadDumped("data/data.dat")
retV = store.Get(key)
if captcha.Text != retV.Text {
t.Errorf("LoadDumped error")
}
os.Remove("data/data.dat")
//test del
store.Del(key)
retV = store.Get(key)
if nil != retV {
t.Errorf("not del")
}
}