-
Notifications
You must be signed in to change notification settings - Fork 225
/
store_test.go
115 lines (105 loc) · 2.36 KB
/
store_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
114
115
package dbus
import (
"reflect"
"testing"
)
func TestStoreStringToInterface(t *testing.T) {
var dest interface{}
err := Store([]interface{}{"foobar"}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest.(string)
}
func TestStoreVariantToInterface(t *testing.T) {
src := MakeVariant("foobar")
var dest interface{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest.(string)
}
func TestStoreMapStringToMapInterface(t *testing.T) {
src := map[string]string{"foo": "bar"}
dest := map[string]interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest["foo"].(string)
}
func TestStoreMapVariantToMapInterface(t *testing.T) {
src := map[string]Variant{"foo": MakeVariant("foobar")}
dest := map[string]interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest["foo"].(string)
}
func TestStoreSliceStringToSliceInterface(t *testing.T) {
src := []string{"foo"}
dest := []interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest[0].(string)
}
func TestStoreSliceVariantToSliceInterface(t *testing.T) {
src := []Variant{MakeVariant("foo")}
dest := []interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest[0].(string)
}
func TestStoreSliceVariantToSliceInterfaceMulti(t *testing.T) {
src := []Variant{MakeVariant("foo"), MakeVariant(int32(1))}
dest := []interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
_ = dest[0].(string)
_ = dest[1].(int32)
}
func TestStoreNested(t *testing.T) {
src := map[string]interface{}{
"foo": []interface{}{
"1", "2", "3", "5",
map[string]interface{}{
"bar": "baz",
},
},
"bar": map[string]interface{}{
"baz": "quux",
"quux": "quuz",
},
}
dest := map[string]interface{}{}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(src, dest) {
t.Errorf("not equal: got '%v', want '%v'",
dest, src)
}
}
func TestStoreSmallerSliceToLargerSlice(t *testing.T) {
src := []string{"baz"}
dest := []interface{}{"foo", "bar"}
err := Store([]interface{}{src}, &dest)
if err != nil {
t.Fatal(err)
}
if len(dest) != 1 {
t.Fatal("Expected dest slice to shrink")
}
if dest[0].(string) != "baz" {
t.Fatal("Wrong element saved in dest slice")
}
}