Skip to content

Commit 4a91989

Browse files
author
Ben Schwartz
committed
Convert to testify
1 parent 95e4aa9 commit 4a91989

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed

service/udp_test.go

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
ss "github.com/Jigsaw-Code/outline-ss-server/shadowsocks"
2828
logging "github.com/op/go-logging"
2929
"github.com/shadowsocks/go-shadowsocks2/socks"
30+
"github.com/stretchr/testify/assert"
3031
)
3132

3233
const timeout = 5 * time.Minute
@@ -158,29 +159,17 @@ func TestIPFilter(t *testing.T) {
158159

159160
t.Run("Localhost allowed", func(t *testing.T) {
160161
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)
164163
})
165164

166165
t.Run("Localhost not allowed", func(t *testing.T) {
167166
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)
174169
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)
184173
}
185174
})
186175
}
@@ -195,22 +184,12 @@ func TestUpstreamMetrics(t *testing.T) {
195184

196185
metrics := sendToDiscard(payloads, allowAll)
197186

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)
201188
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)
214193
}
215194
}
216195

0 commit comments

Comments
 (0)