From e4ca20d63c96ac56b1816a3b03e6c4c6b6f176b1 Mon Sep 17 00:00:00 2001 From: Ric Szopa Date: Wed, 14 Nov 2012 13:41:46 -0800 Subject: [PATCH] Test for Redactor. --- go/relog/relog_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 go/relog/relog_test.go diff --git a/go/relog/relog_test.go b/go/relog/relog_test.go new file mode 100644 index 0000000000..c0b9adc20d --- /dev/null +++ b/go/relog/relog_test.go @@ -0,0 +1,32 @@ +package relog + +import ( + "bytes" + "log" + "strings" + "testing" +) + +type sensitive struct { + Password string + Normal string +} + +func (s sensitive) Redacted() interface{} { + s.Password = Redact(s.Password) + return s +} + +func TestRedacted(t *testing.T) { + s := sensitive{"dupa55", "normal"} + var _ Redactor = s + for _, format := range []string{"%s", "%v", "%#v", "%q"} { + b := new(bytes.Buffer) + log := New(b, "test", log.LstdFlags, DEBUG) + log.Info(format, s) + + if logged := b.String(); strings.Contains(logged, s.Password) { + t.Errorf("Not redacted: %#v in %#v.", s.Password, logged) + } + } +}