-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
108 lines (83 loc) · 2.76 KB
/
config_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
103
104
105
106
107
108
// Copyright 2023 FishGoddess. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package vex
import (
"testing"
"time"
)
// go test -v -cover -count=1 -test.cpu=1 -run=^TestNewClientConfig$
func TestNewClientConfig(t *testing.T) {
conf := newClientConfig("127.0.0.1:5837")
if conf.address != "127.0.0.1:5837" {
t.Errorf("conf.address %s is wrong", conf.address)
}
if conf.readTimeout != 10*time.Minute {
t.Errorf("conf.readTimeout %d is wrong", conf.readTimeout)
}
if conf.writeTimeout != 10*time.Minute {
t.Errorf("conf.writeTimeout %d is wrong", conf.writeTimeout)
}
if conf.readBufferSize != 16*1024 {
t.Errorf("conf.readBufferSize %d is wrong", conf.readBufferSize)
}
if conf.writeBufferSize != 16*1024 {
t.Errorf("conf.writeBufferSize %d is wrong", conf.writeBufferSize)
}
}
// go test -v -cover -count=1 -test.cpu=1 -run=^TestNewServerConfig$
func TestNewServerConfig(t *testing.T) {
conf := newServerConfig("127.0.0.1:5837")
if conf.address != "127.0.0.1:5837" {
t.Errorf("conf.address %s is wrong", conf.address)
}
if conf.name != "127.0.0.1:5837" {
t.Errorf("conf.name %s is wrong", conf.name)
}
if conf.readTimeout != 10*time.Minute {
t.Errorf("conf.readTimeout %d is wrong", conf.readTimeout)
}
if conf.writeTimeout != 10*time.Minute {
t.Errorf("conf.writeTimeout %d is wrong", conf.writeTimeout)
}
if conf.connectTimeout != 30*time.Second {
t.Errorf("conf.connectTimeout %d is wrong", conf.connectTimeout)
}
if conf.closeTimeout != time.Minute {
t.Errorf("conf.closeTimeout %d is wrong", conf.closeTimeout)
}
if conf.readBufferSize != 4*1024 {
t.Errorf("conf.readBufferSize %d is wrong", conf.readBufferSize)
}
if conf.writeBufferSize != 4*1024 {
t.Errorf("conf.writeBufferSize %d is wrong", conf.writeBufferSize)
}
if conf.maxConnections != 4096 {
t.Errorf("conf.maxConnections %d is wrong", conf.maxConnections)
}
}
// go test -v -cover -count=1 -test.cpu=1 -run=^TestConfigApplyOptions$
func TestConfigApplyOptions(t *testing.T) {
conf := &Config{address: "127.0.0.1:5837"}
conf.ApplyOptions([]Option{
WithReadTimeout(time.Second),
WithWriteTimeout(3 * time.Second),
WithReadBufferSize(64),
WithWriteBufferSize(512),
})
if conf.address != "127.0.0.1:5837" {
t.Errorf("conf.address %s is wrong", conf.address)
}
if conf.readTimeout != time.Second {
t.Errorf("conf.readTimeout %d is wrong", conf.readTimeout)
}
if conf.writeTimeout != 3*time.Second {
t.Errorf("conf.writeTimeout %d is wrong", conf.writeTimeout)
}
if conf.readBufferSize != 64 {
t.Errorf("config.readBufferSize %d is wrong", conf.readBufferSize)
}
if conf.writeBufferSize != 512 {
t.Errorf("config.writeBufferSize %d is wrong", conf.writeBufferSize)
}
}