-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_test.go
75 lines (65 loc) · 1.31 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
package riaken_struct
import (
"testing"
)
import (
"github.com/riaken/riaken-core/rpb"
)
type User struct {
Name string `json:"name"`
}
func TestObject(t *testing.T) {
client, err := dial()
if err != nil {
t.Fatal(err.Error())
}
defer client.Close()
session := client.Session()
defer session.Release()
user := &User{
Name: "User",
}
bucket := session.GetBucket("b1")
object := bucket.Object("o1")
if _, err := object.Store(user); err != nil {
t.Error(err.Error())
}
check := User{}
if _, err := object.Fetch(&check); err != nil {
t.Error(err.Error())
}
if check.Name != user.Name {
t.Errorf("got: %s, expected: %s", check.Name, user.Name)
}
if _, err := object.Delete(); err != nil {
t.Error(err.Error())
}
}
func TestObjectDo(t *testing.T) {
client, err := dial()
if err != nil {
t.Fatal(err.Error())
}
defer client.Close()
session := client.Session()
defer session.Release()
user := &User{
Name: "User",
}
rb := true
opts := &rpb.RpbPutReq{
ReturnBody: &rb,
}
bucket := session.GetBucket("b1")
object := bucket.Object("o1")
if check, err := object.Do(opts).Store(user); err != nil {
t.Error(err.Error())
} else {
if len(check.GetContent()) == 0 {
t.Error("expected content to be returned")
}
}
if _, err := object.Delete(); err != nil {
t.Error(err.Error())
}
}