-
Notifications
You must be signed in to change notification settings - Fork 1
/
upstream_test.go
110 lines (102 loc) · 2.69 KB
/
upstream_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
package main
import (
"errors"
"testing"
)
func TestGetHcProto(t *testing.T) {
testCases := []struct {
input string
err error
result hcProto
}{
{input: "tcp", err: nil, result: hcProtoTcp},
{input: "udp", err: nil, result: hcProtoUdp},
{input: "sctp", err: nil, result: hcProtoSctp},
{input: "http", err: nil, result: hcProtoHttp},
{input: "grpc", err: nil, result: hcProtoGrpc},
{input: "misteak", err: errHcp, result: hcProtoUnknown},
}
for _, tc := range testCases {
t.Run(tc.input, func(t *testing.T) {
hcp, err := getHcProto(tc.input)
if !errors.Is(err, tc.err) {
t.Errorf("%s: expected %v, but got %v", tc.input, tc.err, err)
}
if hcp != tc.result {
t.Errorf("%s: expected %v, but got %v", tc.input, tc.result, hcp)
}
})
}
}
func TestHcPString(t *testing.T) {
testCases := []struct {
input hcProto
result string
}{
{input: hcProtoTcp, result: "tcp"},
{input: hcProtoUdp, result: "udp"},
{input: hcProtoSctp, result: "sctp"},
{input: hcProtoHttp, result: "http"},
{input: hcProtoGrpc, result: "grpc"},
{input: hcProtoUnknown, result: "unknown"},
}
for _, tc := range testCases {
t.Run(tc.result, func(t *testing.T) {
r := tc.input.String()
if r != tc.result {
t.Errorf("%s: expected %v, but got %v", tc.result, tc.result, r)
}
})
}
}
func TestGetId(t *testing.T) {
testCases := []struct {
input ugFoMode
result string
}{
{input: ugFoModeUnknown, result: "0"},
{input: ugFoModeInactive, result: "1"},
{input: ugFoModeActive1, result: "2"},
{input: ugFoModeActive2, result: "3"},
{input: ugFoModeDown, result: "4"},
{input: 9, result: "0"},
}
for _, tc := range testCases {
t.Run(tc.result, func(t *testing.T) {
ugFM := tc.input.getId()
if ugFM != tc.result {
t.Errorf("%v: expected %v, but got %v", tc.result, tc.input, ugFM)
}
})
}
}
func TestNextMode(t *testing.T) {
testCases := []struct {
input ugFoMode
err error
result ugFoMode
}{
{input: ugFoModeUnknown, err: errUgFM, result: ugFoModeUnknown},
{input: ugFoModeInactive, err: nil, result: ugFoModeActive1},
{input: ugFoModeActive1, err: nil, result: ugFoModeActive2},
{input: ugFoModeActive2, err: nil, result: ugFoModeActive1},
{input: ugFoModeDown, err: nil, result: ugFoModeActive1},
{input: 9, err: errUgFM, result: ugFoModeUnknown},
}
for _, tc := range testCases {
t.Run(tc.input.getId(), func(t *testing.T) {
ugFM, err := tc.input.nextMode()
if ugFM != tc.result {
t.Errorf(
"%v: expected %v, but got %v",
tc.input.getId(),
tc.input.getId(),
ugFM.getId(),
)
}
if !errors.Is(err, tc.err) {
t.Errorf("%v: expected %v, but got %v", tc.input.getId(), tc.err, err)
}
})
}
}