-
Notifications
You must be signed in to change notification settings - Fork 89
/
logger_test.go
43 lines (32 loc) · 881 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
37
38
39
40
41
42
43
package modbus
import (
"bytes"
"log"
"testing"
)
func TestClientCustomLogger(t *testing.T) {
var buf bytes.Buffer
var logger *log.Logger
logger = log.New(&buf, "external-prefix: ", 0)
_, _ = NewClient(&ClientConfiguration{
Logger: logger,
URL: "sometype://sometarget",
})
if buf.String() != "external-prefix: modbus-client(sometarget) [error]: unsupported client type 'sometype'\n" {
t.Errorf("unexpected logger output '%s'", buf.String())
}
return
}
func TestServerCustomLogger(t *testing.T) {
var buf bytes.Buffer
var logger *log.Logger
logger = log.New(&buf, "external-prefix: ", 0)
_, _ = NewServer(&ServerConfiguration{
Logger: logger,
URL: "tcp://",
}, nil)
if buf.String() != "external-prefix: modbus-server() [error]: missing host part in URL 'tcp://'\n" {
t.Errorf("unexpected logger output '%s'", buf.String())
}
return
}