-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleaner_test.go
More file actions
119 lines (102 loc) · 2.83 KB
/
Copy pathcleaner_test.go
File metadata and controls
119 lines (102 loc) · 2.83 KB
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
116
117
118
119
package gooc
import (
"github.com/stretchr/testify/assert"
"testing"
)
var (
src = map[string]interface{}{
"a": map[string]interface{}{
"b": []interface{}{map[string]interface{}{"c": "c", "vvv": "vvv", "ops": "osp"}},
"d": []interface{}{"1", "2", "3"},
"i": 111,
"o": map[string]interface{}{},
},
"k": []interface{}{
map[string]interface{}{"c": "c", "vvv": "vvv", "ops": "osp"},
map[string]interface{}{"c": "c", "vvv": "vvv", "ops": "osp"},
},
"v": &[]interface{}{
map[string]interface{}{"c": "c", "i": "i", "ops": "osp"},
map[string]interface{}{"c": "c", "i": "i", "ops": "osp"},
},
"j": "j",
}
dst = map[string]interface{}{
"a": map[string]interface{}{
"b": []interface{}{map[string]interface{}{"c": "c", "vvv": "vvv", "ops": "osp"}},
"d": []interface{}{"1", "2", "3"},
},
"k": []interface{}{
map[string]interface{}{"c": "c", "vvv": "vvv", "ops": "osp"},
map[string]interface{}{"c": "c", "vvv": "vvv", "ops": "osp"},
},
"v": []interface{}{
map[string]interface{}{"i": "i"},
map[string]interface{}{"i": "i"},
},
"j": "j",
}
)
func TestCompile(t *testing.T) {
assert := assert.New(t)
m := compile([]string{"a.b.c", "a.b", "a.d", "k", "v.i"})
assert.EqualValues(map[string][]string{
"a": {"b.c", "b", "d"},
"a.d": {"*"},
"a.b.c": {"*"},
"a.b": {"*"},
"k": {"*"},
"v": {"i"},
"v.i": {"*"},
}, m)
}
func TestCleaner_Perform(t *testing.T) {
assert := assert.New(t)
c := NewCleaner([]string{"a.b.c", "a.b", "a.d", "k", "v.i", "j"}, nil)
res := c.Apply(src)
assert.EqualValues(dst, res)
}
func TestBlackList(t *testing.T) {
assert := assert.New(t)
dst := map[string]interface{}{
"a": map[string]interface{}{
"b": []interface{}{map[string]interface{}{"c": "c"}},
"i": 111,
"o": map[string]interface{}{},
},
"v": []interface{}{
map[string]interface{}{"c": "c", "i": "i", "ops": "osp"},
map[string]interface{}{"c": "c", "i": "i", "ops": "osp"},
},
}
c := NewCleaner([]string{"*"}, []string{"j", "a.d", "a.b.vvv", "a.b.ops", "k"})
res := c.Apply(src)
assert.EqualValues(dst, res)
}
func TestAllMatchBlackList(t *testing.T) {
assert := assert.New(t)
c := NewCleaner([]string{"a.b.c", "a.b", "a.d", "k", "v.i", "j"}, []string{"*"})
res := c.Apply(src)
assert.Nil(res)
c = NewCleaner([]string{"*"}, []string{"*", "ignore_it"})
res = c.Apply(src)
assert.Nil(res)
}
func TestCleaner_PerformEmpty(t *testing.T) {
assert := assert.New(t)
c := NewCleaner([]string{}, nil)
res := c.Apply(src)
assert.Nil(res)
}
func TestCleaner_PerformAllMatch(t *testing.T) {
assert := assert.New(t)
c := NewCleaner(AllMatch, nil)
res := c.Apply(src)
assert.EqualValues(src, res)
}
func BenchmarkCleaner_Perform(b *testing.B) {
c := NewCleaner([]string{"a.b.c", "a.b", "a.d", "k", "v.i", "j"}, nil)
for i := 0; i < b.N; i++ {
_ = c.Apply(src)
}
}