-
Notifications
You must be signed in to change notification settings - Fork 456
/
Copy pathdirection_test.go
67 lines (58 loc) · 1.9 KB
/
direction_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
package stream_test
import (
"testing"
"github.com/Shopify/toxiproxy/v2/stream"
)
func TestDirection_String(t *testing.T) {
testCases := []struct {
name string
direction stream.Direction
expected string
}{
{"Downstream to string", stream.Downstream, "downstream"},
{"Upstream to string", stream.Upstream, "upstream"},
{"NumDirections to string", stream.NumDirections, "num_directions"},
{"Upstream via number direction to string", stream.Direction(0), "upstream"},
{"Downstream via number direction to string", stream.Direction(1), "downstream"},
{"High number direction to string", stream.Direction(5), "num_directions"},
}
for _, tc := range testCases {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
actual := tc.direction.String()
if actual != tc.expected {
t.Errorf("got \"%s\"; expected \"%s\"", actual, tc.expected)
}
})
}
}
func TestParseDirection(t *testing.T) {
testCases := []struct {
name string
input string
expected stream.Direction
err error
}{
{"parse empty", "", stream.NumDirections, stream.ErrInvalidDirectionParameter},
{"parse upstream", "upstream", stream.Upstream, nil},
{"parse downstream", "downstream", stream.Downstream, nil},
{"parse unknown", "unknown", stream.NumDirections, stream.ErrInvalidDirectionParameter},
{"parse number", "-123", stream.NumDirections, stream.ErrInvalidDirectionParameter},
{"parse upper case", "DOWNSTREAM", stream.Downstream, nil},
{"parse camel case", "UpStream", stream.Upstream, nil},
}
for _, tc := range testCases {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
actual, err := stream.ParseDirection(tc.input)
if actual != tc.expected {
t.Errorf("got \"%s\"; expected \"%s\"", actual, tc.expected)
}
if err != tc.err {
t.Errorf("got \"%s\"; expected \"%s\"", err, tc.err)
}
})
}
}