mirror of https://github.com/fluffle/goirc
Hmm, using a fixed-length filename doesn't work when you're allowing other people to use your mocks.
This commit is contained in:
parent
97783df463
commit
049942ff2f
|
@ -58,25 +58,25 @@ func (m writerMap) CheckWrittenAtLevel(t *testing.T, lv LogLevel, exp string) {
|
||||||
} else {
|
} else {
|
||||||
w = m[lv]
|
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:<line no>: <level> <log message>
|
// 2011/10/22 10:22:57 log_test.go:<line no>: <level> <log message>
|
||||||
if len(w.written) <= 33 {
|
if len(w.written) <= 20 {
|
||||||
t.Errorf("Not enough bytes logged at level %s:", LogString(lv))
|
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.
|
// Check nothing was written to a different log level here, too.
|
||||||
m.CheckNothingWritten(t)
|
m.CheckNothingWritten(t)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s := string(w.written[32:])
|
s := string(w.written[20:])
|
||||||
// 2 covers the : itself and the extra space
|
// consume the log line file:line: and the level prefix
|
||||||
idx := strings.Index(s, ":") + 2
|
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 will end in "\n", so -1 to chop that off too
|
||||||
s = s[idx:len(s)-1]
|
s = s[idx:len(s)-1]
|
||||||
// expected won't contain the log level prefix, so prepend that
|
|
||||||
exp = LogString(lv) + " " + exp
|
|
||||||
if s != exp {
|
if s != exp {
|
||||||
t.Errorf("Log message at level %s differed.", LogString(lv))
|
t.Errorf("Log message at level %s differed.", LogString(lv))
|
||||||
t.Errorf("exp: %s\ngot: %s", exp, s)
|
t.Errorf("exp: %s\ngot: %s", exp, s)
|
||||||
|
t.Errorf("orig: %s", w.written)
|
||||||
}
|
}
|
||||||
w.reset()
|
w.reset()
|
||||||
// Calling checkNothingWritten here both tests that w.reset() works
|
// Calling checkNothingWritten here both tests that w.reset() works
|
||||||
|
|
Loading…
Reference in New Issue