-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock_logger_test.go
48 lines (37 loc) · 1.13 KB
/
mock_logger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"errors"
"fmt"
)
// This file defines mock structures for testing. It does not contain test.
// discardLogger does not write any log.
type discardLogger struct{}
func (dl discardLogger) Error(...interface{}) {}
func (dl discardLogger) Errorf(string, ...interface{}) {}
func (dl discardLogger) Notice(...interface{}) {}
func (dl discardLogger) Noticef(string, ...interface{}) {}
// bufferedLogger does not write any log but keep them into a buffer instead.
type bufferedLogger struct {
errBuf, noticeBuf string
}
func (bl *bufferedLogger) Error(v ...interface{}) {
bl.errBuf = fmt.Sprint(v...)
}
func (bl *bufferedLogger) Errorf(format string, v ...interface{}) {
bl.errBuf = fmt.Sprintf(format, v...)
}
func (bl *bufferedLogger) Notice(v ...interface{}) {
bl.noticeBuf = fmt.Sprint(v...)
}
func (bl *bufferedLogger) Noticef(format string, v ...interface{}) {
bl.noticeBuf = fmt.Sprintf(format, v...)
}
func (bl *bufferedLogger) GetLastError() error {
if bl.errBuf == "" {
return nil
}
return errors.New(bl.errBuf)
}
func (bl *bufferedLogger) GetLastNotice() string {
return bl.noticeBuf
}