-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_test.go
52 lines (40 loc) · 926 Bytes
/
redis_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
package redis_test
import (
"testing"
"github.com/botopolis/bot"
"github.com/botopolis/bot/mock"
"github.com/botopolis/redis"
"github.com/stretchr/testify/assert"
)
type TestData struct {
Name string
Age int
}
func TestRedis(t *testing.T) {
assert := assert.New(t)
store := redis.New("redis://localhost:6379")
data := TestData{"Jean", 32}
err := store.Set("jj", &data)
assert.Nil(err)
var out TestData
err = store.Get("yy", &out)
assert.NotNil(err)
err = store.Get("jj", &out)
assert.Nil(err)
assert.Equal(data, out)
err = store.Delete("jj")
assert.Nil(err)
err = store.Get("jj", &out)
assert.NotNil(err)
}
func TestLoad(t *testing.T) {
store := redis.New("redis://localhost:6379")
robot := bot.New(mock.NewChat())
store.Load(robot)
err := store.Set("foo", "bar")
assert.Nil(t, err)
var out string
err = robot.Brain.Get("foo", &out)
assert.Nil(t, err)
assert.Equal(t, "bar", out)
}