-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_test.go
36 lines (32 loc) · 730 Bytes
/
data_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
package mongotest_test
import (
"testing"
"github.com/pinzolo/mongotest"
)
func TestDocData_StringValue(t *testing.T) {
data := mongotest.DocData{
"foo": "foo",
"bar": 1,
}
testdata := []struct {
key string
val string
ok bool
memo string
}{
{key: "foo", val: "foo", ok: true, memo: "string value"},
{key: "bar", val: "", ok: false, memo: "not string"},
{key: "baz", val: "", ok: false, memo: "not exists"},
}
for _, d := range testdata {
t.Run(d.memo, func(t *testing.T) {
v, ok := data.StringValue(d.key)
if d.ok != ok {
t.Errorf("invalid result (want: %t, got: %t)", d.ok, ok)
}
if ok && v != d.val {
t.Errorf("invalid value (want: %s, got: %s)", d.val, v)
}
})
}
}