MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestRedactHelper

Function TestRedactHelper

base/redactor_test.go:20–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestRedactHelper(t *testing.T) {
21 defer func() { RedactUserData = defaultRedactUserData }()
22
23 RedactUserData = true
24
25 ptr := UserData("hello")
26
27 var in = []interface{}{
28 UserData("alice"),
29 &ptr,
30 "bob",
31 1234,
32 big.NewInt(1234),
33 struct{}{},
34 }
35
36 out := redact(in)
37
38 // Since redact performs an in-place redaction,
39 // we'd expect the input slice to change too.
40 assert.Equal(t, in, out)
41
42 // Check that ptr wasn't redacted outside of the slice... this could be dangerous!
43 assert.Equal(t, "hello", string(ptr))
44
45 // Verify that only the types implementing Redactor have changed.
46 assert.Equal(t, UserData("alice").Redact(), out[0])
47 assert.Equal(t, ptr.Redact(), out[1])
48 assert.Equal(t, "bob", out[2])
49 assert.Equal(t, 1234, out[3])
50 assert.Equal(t, big.NewInt(1234).String(), out[4].(*big.Int).String())
51 assert.Equal(t, struct{}{}, out[5])
52}
53
54func TestSetRedaction(t *testing.T) {
55 // reset

Callers

nothing calls this directly

Calls 5

UserDataTypeAlias · 0.85
redactFunction · 0.85
RedactMethod · 0.65
StringMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected