MCPcopy Index your code
hub / github.com/koding/kite / TestScrub

Function TestScrub

dnode/scrub_test.go:8–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestScrub(t *testing.T) {
9 type Case struct {
10 obj interface{}
11 callbacks map[string]Path
12 }
13
14 cb := Callback(func(*Partial) {})
15
16 cases := []Case{
17 {nil, nil},
18 {"foo", nil},
19 {[]interface{}{"foo", "bar"}, nil},
20 {[]interface{}{cb}, map[string]Path{"0": {0}}},
21 {[]interface{}{cb, "foo", cb}, map[string]Path{"0": {0}, "1": {2}}},
22 {[]interface{}{"foo", "bar", cb}, map[string]Path{"0": {2}}},
23 {[]interface{}{"foo", []interface{}{"bar", cb}}, map[string]Path{"0": {1, 1}}},
24 {[...]interface{}{"foo", cb, cb}, map[string]Path{"0": {1}, "1": {2}}},
25 {map[string]interface{}{"foo": 1, "bar": 2}, nil},
26 {map[string]interface{}{"foo": 1, "bar": 2, "cb": cb}, map[string]Path{"0": {"cb"}}},
27 {T{privT{0, cb, cb}, 1, 2, cb, cb, nil}, map[string]Path{
28 "0": {"embedB"},
29 "1": {"c"},
30 "2": {"f1"},
31 }},
32 {T{A: 1, b: 2, C: cb, d: cb, E: &T{C: cb, d: cb}}, map[string]Path{
33 "0": {"c"},
34 "1": {"E", "c"},
35 "2": {"E", "f1"},
36 "3": {"E", "f3"},
37 "4": {"f1"},
38 }},
39 }
40
41 for i, c := range cases {
42 scrubber := NewScrubber()
43 callbacks := scrubber.Scrub(c.obj)
44 if len(callbacks) == 0 && len(c.callbacks) == 0 {
45 continue
46 }
47 if !reflect.DeepEqual(callbacks, c.callbacks) {
48 t.Errorf("test case %d, expected: %+v", i, c.callbacks)
49 t.Errorf("got: %+v", callbacks)
50 }
51 }
52}
53
54type privT struct {
55 A int

Callers

nothing calls this directly

Calls 3

ScrubMethod · 0.95
NewScrubberFunction · 0.85
CallbackFunction · 0.70

Tested by

no test coverage detected