-
Notifications
You must be signed in to change notification settings - Fork 46
/
get_test.go
113 lines (87 loc) · 2.27 KB
/
get_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
104
105
106
107
108
109
110
111
112
113
// Copyright 2016 Tim Shannon. All rights reserved.
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
package bolthold_test
import (
"testing"
"time"
"github.com/timshannon/bolthold"
)
func TestGet(t *testing.T) {
testWrap(t, func(store *bolthold.Store, t *testing.T) {
key := "testKey"
data := &ItemTest{
Name: "Test Name",
Created: time.Now(),
}
err := store.Insert(key, data)
if err != nil {
t.Fatalf("Error creating data for get test: %s", err)
}
result := &ItemTest{}
err = store.Get(key, result)
if err != nil {
t.Fatalf("Error getting data from bolthold: %s", err)
}
if !data.equal(result) {
t.Fatalf("Got %v wanted %v.", result, data)
}
})
}
func TestGetKeyStructTag(t *testing.T) {
testWrap(t, func(store *bolthold.Store, t *testing.T) {
type KeyTest struct {
Key int `boltholdKey:"Key"`
Value string
}
key := 3
err := store.Insert(key, &KeyTest{
Value: "test value",
})
if err != nil {
t.Fatalf("Error inserting KeyTest struct for Key struct tag testing. Error: %s", err)
}
var result KeyTest
err = store.Get(key, &result)
if err != nil {
t.Fatalf("Error running Get in TestKeyStructTag. ERROR: %s", err)
}
if result.Key != key {
t.Fatalf("Key struct tag was not set correctly. Expected %d, got %d", key, result.Key)
}
})
}
func TestGetKeyStructTagIntoPtr(t *testing.T) {
testWrap(t, func(store *bolthold.Store, t *testing.T) {
type KeyTest struct {
Key *int `boltholdKey:"Key"`
Value string
}
key := 3
err := store.Insert(&key, &KeyTest{
Value: "test value",
})
if err != nil {
t.Fatalf("Error inserting KeyTest struct for Key struct tag testing. Error: %s", err)
}
var result KeyTest
err = store.Get(key, &result)
if err != nil {
t.Fatalf("Error running Get in TestKeyStructTag. ERROR: %s", err)
}
if result.Key == nil || *result.Key != key {
t.Fatalf("Key struct tag was not set correctly. Expected %d, got %d", key, result.Key)
}
})
}
func TestIssue103(t *testing.T) {
testWrap(t, func(store *bolthold.Store, t *testing.T) {
type Counterer struct {
State uint
}
count := new(Counterer)
count.State++
ok(t, store.Upsert("count", count))
ok(t, store.Get("count", &count))
})
}