-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsender_test.go
More file actions
39 lines (33 loc) · 1.04 KB
/
sender_test.go
File metadata and controls
39 lines (33 loc) · 1.04 KB
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
package errors
import (
"bytes"
"errors"
"log"
"net/http"
"testing"
)
var (
_ Sender = Send
_ Middleware = WithLogger(nil)
_ Middleware = (*ResponseLogger)(nil).Log
)
func TestWithLogger(t *testing.T) {
buff := bytes.NewBuffer([]byte{})
logger := log.New(buff, "", 0)
t.Run("test if the response is logged by logger wrapper", func(t *testing.T) {
WithLogger(logger)(func(http.ResponseWriter, interface{}) {})(nil, errors.New("failed"))
if buff.String() != "failed\n" {
t.Errorf("log output was expected to contain error message %q but instead of %q", "failed\n", buff.String())
}
})
}
func TestResponseLogger(t *testing.T) {
buff := bytes.NewBuffer([]byte{})
logger := log.New(buff, "", 0)
t.Run("test if the response is logged by ResponseLogger", func(t *testing.T) {
(&ResponseLogger{logger}).Log(func(http.ResponseWriter, interface{}) {})(nil, errors.New("failed"))
if buff.String() != "failed\n" {
t.Errorf("log output was expected to contain error message %q but instead of %q", "failed\n", buff.String())
}
})
}