-
Notifications
You must be signed in to change notification settings - Fork 1
/
decorator_test.go
69 lines (58 loc) · 1.43 KB
/
decorator_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
package mapdecor
import (
"strings"
"testing"
"github.com/linkosmos/mapop"
"github.com/stretchr/testify/assert"
)
var decorateTests = []struct {
input map[string]interface{}
expected map[string]interface{}
decorFunc Decor
}{
{
input: map[string]interface{}{
"key1": nil,
"key2": "with",
"val1": "1",
"val2": "2",
"val3": "3",
"val4": "4",
},
expected: map[string]interface{}{
"key1": nil,
"key2": "with",
"values": map[string]interface{}{
"val1": "1",
"val2": "2",
"val3": "3",
"val4": "4",
},
},
decorFunc: func(input map[string]interface{}) (output map[string]interface{}) {
partitonFunc := func(s string, i interface{}) bool {
return strings.Contains(s, "val")
}
// For first (inputPartitioned[0]) partition we get key-values of val
// For second (inputPartitioned[1]) partition what is left
inputPartitioned := mapop.Partition(partitonFunc, input)
// Assigning values key to first partition
inputPartitioned[1]["values"] = inputPartitioned[0]
return inputPartitioned[1]
},
},
}
func TestDecorateFromRegistry(t *testing.T) {
ResetRegistry()
for _, test := range decorateTests {
Register(test.decorFunc)
got := DecorateFromRegistry(test.input)
assert.Equal(t, test.expected, got)
}
}
func TestDecorator(t *testing.T) {
for _, test := range decorateTests {
got := Decorate(test.input, test.decorFunc)
assert.Equal(t, test.expected, got)
}
}