mirror of
https://github.com/fluffle/goirc
synced 2025-07-12 08:11:17 +00:00
Simpleish level-based logging library and the start of some tests.
This commit is contained in:
parent
c400a2141a
commit
d07471b93a
2 changed files with 226 additions and 0 deletions
32
logging/log_test.go
Normal file
32
logging/log_test.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type mockWriter struct {
|
||||
written []byte
|
||||
}
|
||||
|
||||
func (w *mockWriter) Write(p []byte) (n int, err os.Error) {
|
||||
w.written = append(w.written, p...)
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func TestDefaultLogging(t *testing.T) {
|
||||
w := &mockWriter{make([]byte, 0)}
|
||||
l := New(w, LogError, false)
|
||||
l.Log(4, "Nothing should be logged yet")
|
||||
l.Log(LogDebug, "or yet...")
|
||||
l.Log(LogWarn, "or yet!")
|
||||
if len(w.written) > 0 {
|
||||
t.Errorf("Unexpected low-level logging output.")
|
||||
}
|
||||
l.Log(LogError, "Error!")
|
||||
// Note: the below is deliberately fragile to ensure
|
||||
// the right file:line is logged on errors. Sorry!
|
||||
if s := string(w.written); s[20:] != "log_test.go:26: Error!\n" {
|
||||
t.Errorf("Error incorrectly logged (check line numbers!)")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue