-
Notifications
You must be signed in to change notification settings - Fork 9
/
opts_test.go
160 lines (109 loc) · 4.69 KB
/
opts_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package httransform_test
import (
"testing"
"time"
"github.com/9seconds/httransform/v2"
"github.com/9seconds/httransform/v2/auth"
"github.com/9seconds/httransform/v2/events"
"github.com/9seconds/httransform/v2/layers"
"github.com/stretchr/testify/suite"
)
type OptsTestSuite struct {
suite.Suite
o httransform.ServerOpts
}
func (suite *OptsTestSuite) SetupTest() {
suite.o = httransform.ServerOpts{}
}
func (suite *OptsTestSuite) TestNil() {
var opts *httransform.ServerOpts
suite.Equal(httransform.DefaultConcurrency, opts.GetConcurrency())
suite.Equal(httransform.DefaultReadBufferSize, opts.GetReadBufferSize())
suite.Equal(httransform.DefaultWriteBufferSize, opts.GetWriteBufferSize())
suite.Equal(httransform.DefaultReadTimeout, opts.GetReadTimeout())
suite.Equal(httransform.DefaultWriteTimeout, opts.GetWriteTimeout())
suite.Equal(httransform.DefaultTCPKeepAlivePeriod, opts.GetTCPKeepAlivePeriod())
suite.NotNil(opts.GetEventProcessorFactory())
suite.Empty(opts.GetTLSCertCA())
suite.Empty(opts.GetTLSPrivateKey())
suite.False(opts.GetTLSSkipVerify())
suite.Len(opts.GetLayers(), 2)
suite.IsType(auth.NoopAuth{}, opts.GetAuthenticator())
suite.Nil(opts.GetExecutor())
}
func (suite *OptsTestSuite) TestGetConcurrency() {
suite.Equal(httransform.DefaultConcurrency, suite.o.GetConcurrency())
suite.o.Concurrency = httransform.DefaultConcurrency + 1
suite.Equal(httransform.DefaultConcurrency+1, suite.o.GetConcurrency())
}
func (suite *OptsTestSuite) TestGetReadBufferSize() {
suite.Equal(httransform.DefaultReadBufferSize, suite.o.GetReadBufferSize())
suite.o.ReadBufferSize = httransform.DefaultReadBufferSize + 1
suite.Equal(httransform.DefaultReadBufferSize+1, suite.o.GetReadBufferSize())
}
func (suite *OptsTestSuite) TestGetWriteBufferSize() {
suite.Equal(httransform.DefaultWriteBufferSize, suite.o.GetWriteBufferSize())
suite.o.WriteBufferSize = httransform.DefaultWriteBufferSize + 1
suite.Equal(httransform.DefaultWriteBufferSize+1, suite.o.GetWriteBufferSize())
}
func (suite *OptsTestSuite) TestGetReadTimeout() {
suite.Equal(httransform.DefaultReadTimeout, suite.o.GetReadTimeout())
suite.o.ReadTimeout = httransform.DefaultReadTimeout + time.Second
suite.Equal(httransform.DefaultReadTimeout+time.Second, suite.o.GetReadTimeout())
}
func (suite *OptsTestSuite) TestGetWriteTimeout() {
suite.Equal(httransform.DefaultWriteTimeout, suite.o.GetWriteTimeout())
suite.o.WriteTimeout = httransform.DefaultWriteTimeout + time.Second
suite.Equal(httransform.DefaultWriteTimeout+time.Second, suite.o.GetWriteTimeout())
}
func (suite *OptsTestSuite) TestGetTCPKeepAlivePeriod() {
suite.Equal(httransform.DefaultTCPKeepAlivePeriod, suite.o.GetTCPKeepAlivePeriod())
suite.o.TCPKeepAlivePeriod = httransform.DefaultTCPKeepAlivePeriod + time.Second
suite.Equal(httransform.DefaultTCPKeepAlivePeriod+time.Second, suite.o.GetTCPKeepAlivePeriod())
}
func (suite *OptsTestSuite) TestGetMaxRequestBodySize() {
suite.Equal(httransform.DefaultMaxRequestBodySize, suite.o.GetMaxRequestBodySize())
suite.o.MaxRequestBodySize = httransform.DefaultMaxRequestBodySize + 1
suite.Equal(httransform.DefaultMaxRequestBodySize+1, suite.o.GetMaxRequestBodySize())
}
func (suite *OptsTestSuite) TestGetEventProcessorFactory() {
suite.NotNil(suite.o.GetEventProcessorFactory())
suite.o.EventProcessorFactory = func() events.Processor { return nil }
// https://github.com/stretchr/testify/issues/182
suite.NotNil(suite.o.GetEventProcessorFactory())
}
func (suite *OptsTestSuite) TestGetTLSCertCA() {
suite.Empty(suite.o.GetTLSCertCA())
suite.o.TLSCertCA = []byte("hello")
suite.Equal("hello", string(suite.o.GetTLSCertCA()))
}
func (suite *OptsTestSuite) TestGetTLSPrivateKey() {
suite.Empty(suite.o.GetTLSPrivateKey())
suite.o.TLSPrivateKey = []byte("hello")
suite.Equal("hello", string(suite.o.GetTLSPrivateKey()))
}
func (suite *OptsTestSuite) TestGetTLSSkipVerify() {
suite.False(suite.o.GetTLSSkipVerify())
suite.o.TLSSkipVerify = true
suite.True(suite.o.GetTLSSkipVerify())
}
func (suite *OptsTestSuite) TestGetLayers() {
suite.Len(suite.o.GetLayers(), 2)
lr := layers.TimeoutLayer{Timeout: time.Second}
suite.o.Layers = []layers.Layer{lr}
suite.Len(suite.o.GetLayers(), 3)
suite.Equal(lr, suite.o.GetLayers()[1])
}
func (suite *OptsTestSuite) TestGetAuthenticator() {
suite.IsType(auth.NoopAuth{}, suite.o.GetAuthenticator())
suite.o.Authenticator = auth.NewBasicAuth(nil)
suite.Equal(suite.o.Authenticator, suite.o.GetAuthenticator())
}
func (suite *OptsTestSuite) TestGetExecutor() {
suite.Nil(suite.o.GetExecutor())
suite.o.Executor = func(_ *layers.Context) error { return nil }
suite.NotNil(suite.o.GetExecutor())
}
func TestOpts(t *testing.T) {
suite.Run(t, &OptsTestSuite{})
}