From 049942ff2f8ce4ba7ac0d60063c033a87aa332f0 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Thu, 27 Oct 2011 18:37:55 +0100 Subject: [PATCH] Hmm, using a fixed-length filename doesn't work when you're allowing other people to use your mocks. --- logging/mock.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/logging/mock.go b/logging/mock.go index a335b1a..c126251 100644 --- a/logging/mock.go +++ b/logging/mock.go @@ -58,25 +58,25 @@ func (m writerMap) CheckWrittenAtLevel(t *testing.T, lv LogLevel, exp string) { } else { w = m[lv] } - // 32 bytes covers the date, time and filename up to the colon in + // 20 bytes covers the date and time in // 2011/10/22 10:22:57 log_test.go:: - if len(w.written) <= 33 { + if len(w.written) <= 20 { t.Errorf("Not enough bytes logged at level %s:", LogString(lv)) - t.Errorf("exp: %s\ngot: %s", exp, string(w.written)) + t.Errorf("exp: %s\ngot: %s", exp, w.written) // Check nothing was written to a different log level here, too. m.CheckNothingWritten(t) return } - s := string(w.written[32:]) - // 2 covers the : itself and the extra space - idx := strings.Index(s, ":") + 2 + s := string(w.written[20:]) + // consume the log line file:line: and the level prefix + idx := strings.Index(s, ":") + 1 + idx += strings.Index(s[idx:], ":") + len(LogString(lv)) + 3 // s will end in "\n", so -1 to chop that off too s = s[idx:len(s)-1] - // expected won't contain the log level prefix, so prepend that - exp = LogString(lv) + " " + exp if s != exp { t.Errorf("Log message at level %s differed.", LogString(lv)) t.Errorf("exp: %s\ngot: %s", exp, s) + t.Errorf("orig: %s", w.written) } w.reset() // Calling checkNothingWritten here both tests that w.reset() works