-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_test.go
103 lines (80 loc) · 2.37 KB
/
object_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package rkive
import (
"testing"
"unsafe"
)
func TestClientAlignment(t *testing.T) {
// we're doing atomic operations
// on 'conns', 'inuse', and 'tag', so
// let's keep them 8-byte aligned
cl := Client{}
t.Logf("Client alignment: %d", unsafe.Alignof(cl))
if (unsafe.Alignof(cl) % 8) != 0 {
t.Errorf("Wanted 8-byte alignment; addr%8 = %d", unsafe.Alignof(cl)%8)
}
t.Logf("'conns' offset: %d", unsafe.Offsetof(cl.conns))
if (unsafe.Offsetof(cl.conns) % 8) != 0 {
t.Errorf("Wanted 8-byte alignment; addr%8 = %d", unsafe.Offsetof(cl.conns)%8)
}
t.Logf("'inuse' offset: %d", unsafe.Offsetof(cl.inuse))
if (unsafe.Offsetof(cl.inuse) % 8) != 0 {
t.Errorf("Wanted 8-byte alignment; addr%8 = %d", unsafe.Offsetof(cl.inuse)%8)
}
t.Logf("'tag' offset: %d", unsafe.Offsetof(cl.tag))
if (unsafe.Offsetof(cl.tag) % 8) != 0 {
t.Errorf("Wanted 8-byte alignment; addr%8 = %d", unsafe.Offsetof(cl.tag)%8)
}
}
func TestAddRemoveLink(t *testing.T) {
info := Info{}
info.AddLink("testlink", "testbucket", "k")
bucket, key := info.GetLink("testlink")
if bucket != "testbucket" || key != "k" {
t.Errorf("Bucket: %q; key: %q", bucket, key)
}
info.RemoveLink("testlink")
bucket, key = info.GetLink("testlink")
if bucket != "" || key != "" {
t.Errorf("Bucket: %q; key: %q", bucket, key)
}
info.AddLink("testlink", "testbucket", "k1")
info.SetLink("testlink", "newbucket", "k2")
bucket, key = info.GetLink("testlink")
if bucket != "newbucket" || key != "k2" {
t.Errorf("Bucket: %q; key: %q", bucket, key)
}
}
func TestAddRemoveIndex(t *testing.T) {
info := Info{}
info.AddIndex("testidx", "blah")
val := info.GetIndex("testidx")
if val != "blah" {
t.Errorf("Val: %q", val)
t.Errorf("Indexes: %v", info.idxs)
}
info.SetIndex("testidx", "newblah")
val = info.GetIndex("testidx")
if val != "newblah" {
t.Errorf("Val: %q", val)
}
info.RemoveIndex("testidx")
val = info.GetIndex("testidx")
if val != "" {
t.Errorf("Val: %q", val)
}
info.AddIndexInt("myNum", 300)
ival := info.GetIndexInt("myNum")
if ival == nil || *ival != 300 {
t.Errorf("Ival is %d; expected %d", *ival, 300)
}
info.SetIndexInt("myNum", -84)
ival = info.GetIndexInt("myNum")
if ival == nil || *ival != -84 {
t.Errorf("Ival is %d; expected %d", *ival, -84)
}
info.RemoveIndexInt("myNum")
ival = info.GetIndexInt("myNum")
if ival != nil {
t.Errorf("Expected nil; got %d", *ival)
}
}