@@ -27,6 +27,7 @@ import (
27
27
ss "github.com/Jigsaw-Code/outline-ss-server/shadowsocks"
28
28
logging "github.com/op/go-logging"
29
29
"github.com/shadowsocks/go-shadowsocks2/socks"
30
+ "github.com/stretchr/testify/assert"
30
31
)
31
32
32
33
const timeout = 5 * time .Minute
@@ -158,29 +159,17 @@ func TestIPFilter(t *testing.T) {
158
159
159
160
t .Run ("Localhost allowed" , func (t * testing.T ) {
160
161
metrics := sendToDiscard (payloads , allowAll )
161
- if metrics .natEntriesAdded != 1 {
162
- t .Errorf ("Expected 1 NAT entry, not %d" , metrics .natEntriesAdded )
163
- }
162
+ assert .Equal (t , metrics .natEntriesAdded , 1 , "Expected 1 NAT entry, not %d" , metrics .natEntriesAdded )
164
163
})
165
164
166
165
t .Run ("Localhost not allowed" , func (t * testing.T ) {
167
166
metrics := sendToDiscard (payloads , onet .RequirePublicIP )
168
- if metrics .natEntriesAdded != 0 {
169
- t .Error ("Unexpected NAT entry on rejected packet" )
170
- }
171
- if len (metrics .upstreamPackets ) != 2 {
172
- t .Errorf ("Expected 2 reports, not %v" , metrics .upstreamPackets )
173
- }
167
+ assert .Equal (t , 0 , metrics .natEntriesAdded , "Unexpected NAT entry on rejected packet" )
168
+ assert .Equal (t , 2 , len (metrics .upstreamPackets ), "Expected 2 reports, not %v" , metrics .upstreamPackets )
174
169
for _ , report := range metrics .upstreamPackets {
175
- if report .clientProxyBytes == 0 {
176
- t .Error ("Expected nonzero input packet size" )
177
- }
178
- if report .proxyTargetBytes != 0 {
179
- t .Error ("No bytes should be sent due to a disallowed packet" )
180
- }
181
- if report .accessKey != "id-0" {
182
- t .Errorf ("Unexpected access key: %s" , report .accessKey )
183
- }
170
+ assert .Greater (t , report .clientProxyBytes , 0 , "Expected nonzero input packet size" )
171
+ assert .Equal (t , 0 , report .proxyTargetBytes , "No bytes should be sent due to a disallowed packet" )
172
+ assert .Equal (t , report .accessKey , "id-0" , "Unexpected access key: %s" , report .accessKey )
184
173
}
185
174
})
186
175
}
@@ -195,22 +184,12 @@ func TestUpstreamMetrics(t *testing.T) {
195
184
196
185
metrics := sendToDiscard (payloads , allowAll )
197
186
198
- if len (metrics .upstreamPackets ) != N {
199
- t .Errorf ("Expected %d reports, not %v" , N , metrics .upstreamPackets )
200
- }
187
+ assert .Equal (t , N , len (metrics .upstreamPackets ), "Expected %d reports, not %v" , N , metrics .upstreamPackets )
201
188
for i , report := range metrics .upstreamPackets {
202
- if report .proxyTargetBytes != i + 1 {
203
- t .Errorf ("Expected %d payload bytes, not %d" , i , report .proxyTargetBytes )
204
- }
205
- if report .clientProxyBytes <= report .proxyTargetBytes {
206
- t .Errorf ("Expected nonzero input overhead (%d > %d)" , report .clientProxyBytes , report .proxyTargetBytes )
207
- }
208
- if report .accessKey != "id-0" {
209
- t .Errorf ("Unexpected access key name: %s" , report .accessKey )
210
- }
211
- if report .status != "OK" {
212
- t .Errorf ("Wrong status: %s" , report .status )
213
- }
189
+ assert .Equal (t , i + 1 , report .proxyTargetBytes , "Expected %d payload bytes, not %d" , i + 1 , report .proxyTargetBytes )
190
+ assert .Greater (t , report .clientProxyBytes , report .proxyTargetBytes , "Expected nonzero input overhead (%d > %d)" , report .clientProxyBytes , report .proxyTargetBytes )
191
+ assert .Equal (t , "id-0" , report .accessKey , "Unexpected access key name: %s" , report .accessKey )
192
+ assert .Equal (t , "OK" , report .status , "Wrong status: %s" , report .status )
214
193
}
215
194
}
216
195
0 commit comments