| 18 | ) |
| 19 | |
| 20 | func 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 | |
| 54 | func TestSetRedaction(t *testing.T) { |
| 55 | // reset |