-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_test.go
102 lines (89 loc) · 2.46 KB
/
log_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package coreapi
import (
"fmt"
"testing"
)
func TestModuleLog_Error(t *testing.T) {
m := ModuleLog{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "log/error" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "text/plain" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "message" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return nil, fmt.Errorf("err1")
}}
err := m.Error("message")
if err == nil {
t.Fatalf("expected error, got nil")
}
if err.Error() != "err1" {
t.Fatalf("unexpected error value, got %s", err.Error())
}
}
func TestModuleLog_Warn(t *testing.T) {
m := ModuleLog{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "log/warn" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "text/plain" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "message" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return nil, fmt.Errorf("err1")
}}
err := m.Warn("message")
if err == nil {
t.Fatalf("expected error, got nil")
}
if err.Error() != "err1" {
t.Fatalf("unexpected error value, got %s", err.Error())
}
}
func TestModuleLog_Info(t *testing.T) {
m := ModuleLog{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "log/info" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "text/plain" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "message" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return nil, fmt.Errorf("err1")
}}
err := m.Info("message")
if err == nil {
t.Fatalf("expected error, got nil")
}
if err.Error() != "err1" {
t.Fatalf("unexpected error value, got %s", err.Error())
}
}
func TestModuleLog_Debug(t *testing.T) {
m := ModuleLog{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "log/debug" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "text/plain" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "message" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return nil, fmt.Errorf("err1")
}}
err := m.Debug("message")
if err == nil {
t.Fatalf("expected error, got nil")
}
if err.Error() != "err1" {
t.Fatalf("unexpected error value, got %s", err.Error())
}
}