-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrace_test.go
52 lines (41 loc) · 1.4 KB
/
trace_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
49
50
51
52
package incr
import (
"bytes"
"context"
"strings"
"testing"
. "github.com/wcharczuk/go-incr/testutil"
)
func Test_WithTracing(t *testing.T) {
ctx := context.Background()
tr := GetTracer(ctx)
Nil(t, tr)
ctx = WithTracing(ctx)
tr = GetTracer(ctx)
NotNil(t, tr)
NotNil(t, tr.(*tracer).log)
NotNil(t, tr.(*tracer).errLog)
}
func Test_WithTracingOutput(t *testing.T) {
output := new(bytes.Buffer)
errOutput := new(bytes.Buffer)
tr := GetTracer(context.Background())
Nil(t, tr)
ctx := WithTracingOutputs(context.Background(), output, errOutput)
tr = GetTracer(ctx)
NotNil(t, tr)
NotNil(t, tr.(*tracer).log)
NotNil(t, tr.(*tracer).errLog)
TracePrintln(ctx, "this is a println test")
Equal(t, true, strings.Contains(output.String(), "this is a println test"))
Equal(t, "", errOutput.String())
TraceErrorln(ctx, "this is a errorln test")
Equal(t, false, strings.Contains(output.String(), "this is a errorln test"))
Equal(t, true, strings.Contains(errOutput.String(), "this is a errorln test"))
TracePrintf(ctx, "this is a %s test", "printf")
Equal(t, true, strings.Contains(output.String(), "this is a printf test"))
Equal(t, false, strings.Contains(errOutput.String(), "this is a printf test"))
TraceErrorf(ctx, "this is a %s test", "errorf")
Equal(t, false, strings.Contains(output.String(), "this is a errorf test"))
Equal(t, true, strings.Contains(errOutput.String(), "this is a errorf test"))
}