forked from segmentio/analytics-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger_test.go
36 lines (30 loc) · 910 Bytes
/
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
package analytics
import (
"bytes"
"errors"
"log"
"testing"
)
// This test ensures that the interface doesn't get changed and stays compatible
// with the *testing.T type.
// If someone were to modify the interface in backward incompatible manner this
// test would break.
func TestTestingLogger(t *testing.T) {
_ = Logger(t)
}
// This test ensures the standard logger shim to the Logger interface is working
// as expected.
func TestStdLogger(t *testing.T) {
var buffer bytes.Buffer
var logger = StdLogger(log.New(&buffer, "test ", 0))
logger.Logf("Hello World!")
logger.Logf("The answer is %d", 42)
logger.Errorf("%s", errors.New("something went wrong!"))
const ref = `test INFO: Hello World!
test INFO: The answer is 42
test ERROR: something went wrong!
`
if res := buffer.String(); ref != res {
t.Errorf("invalid logs from standard logger:\n- expected: %s\n- found: %s", ref, res)
}
}