-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_bool_test.go
62 lines (45 loc) · 1.18 KB
/
custom_bool_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
58
59
60
61
62
package grocery
import (
"testing"
"github.com/redis/go-redis/v9"
)
type ZContains bool
func (ZContains) Load(itemID, fieldName string) (bool, error) {
_, err := C.ZRank(ctx, fieldName, itemID).Result()
return err == nil, nil
}
type ZContainsTestModel struct {
Base
Name string `grocery:"name"`
IsMember ZContains `grocery:"sortedSetTest"`
}
func TestZContains(t *testing.T) {
model := &ZContainsTestModel{
Name: "hello world",
}
model2 := &ZContainsTestModel{
Name: "hello world 2",
}
id, err := Store(model)
id2, _ := Store(model2)
if err != nil {
t.Error(err)
}
C.ZAdd(ctx, "sortedSetTest", redis.Z{Score: 1, Member: id}).Result()
loadedModel := new(ZContainsTestModel)
err = Load(id, loadedModel)
loadedModel2 := new(ZContainsTestModel)
Load(id2, loadedModel2)
if err != nil {
t.Error(err)
}
if !loadedModel.IsMember {
t.Errorf("zcontains FAILED, expected %t but got %t", true, loadedModel.IsMember)
}
if loadedModel2.IsMember {
t.Errorf("zcontains FAILED, expected %t but got %t", false, loadedModel2.IsMember)
}
if loadedModel.Name != model.Name {
t.Errorf("zcontains name FAILED, expected %s but got %s", model.Name, loadedModel.Name)
}
}