forked from hashicorp/memberlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging_test.go
50 lines (41 loc) · 871 Bytes
/
logging_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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package memberlist
import (
"fmt"
"net"
"testing"
)
func TestLogging_Address(t *testing.T) {
s := LogAddress(nil)
if s != "from=<unknown address>" {
t.Fatalf("bad: %s", s)
}
addr, err := net.ResolveIPAddr("ip4", "127.0.0.1")
if err != nil {
t.Fatalf("err: %v", err)
}
s = LogAddress(addr)
if s != "from=127.0.0.1" {
t.Fatalf("bad: %s", s)
}
}
func TestLogging_Conn(t *testing.T) {
s := LogConn(nil)
if s != "from=<unknown address>" {
t.Fatalf("bad: %s", s)
}
ln, err := net.Listen("tcp", ":0")
if err != nil {
t.Fatalf("err: %v", err)
}
conn, err := net.Dial("tcp", ln.Addr().String())
if err != nil {
t.Fatalf("err: %v", err)
}
defer conn.Close()
s = LogConn(conn)
if s != fmt.Sprintf("from=%s", conn.RemoteAddr().String()) {
t.Fatalf("bad: %s", s)
}
}