Maint: utils.FilterByProtocol function

This commit is contained in:
Quentin McGaw (desktop)
2021-08-23 20:16:29 +00:00
parent f1a82d9d9c
commit f1a6594474
13 changed files with 101 additions and 22 deletions

View File

@@ -52,3 +52,81 @@ func Test_GetProtocol(t *testing.T) {
})
}
}
func Test_FilterByProtocol(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
selection configuration.ServerSelection
serverTCP bool
serverUDP bool
filtered bool
}{
"Wireguard and server has UDP": {
selection: configuration.ServerSelection{
VPN: constants.Wireguard,
},
serverUDP: true,
filtered: false,
},
"Wireguard and server has not UDP": {
selection: configuration.ServerSelection{
VPN: constants.Wireguard,
},
serverUDP: false,
filtered: true,
},
"OpenVPN UDP and server has UDP": {
selection: configuration.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: configuration.OpenVPNSelection{
TCP: false,
},
},
serverUDP: true,
filtered: false,
},
"OpenVPN UDP and server has not UDP": {
selection: configuration.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: configuration.OpenVPNSelection{
TCP: false,
},
},
serverUDP: false,
filtered: true,
},
"OpenVPN TCP and server has TCP": {
selection: configuration.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: configuration.OpenVPNSelection{
TCP: true,
},
},
serverTCP: true,
filtered: false,
},
"OpenVPN TCP and server has not TCP": {
selection: configuration.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: configuration.OpenVPNSelection{
TCP: true,
},
},
serverTCP: false,
filtered: true,
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
filtered := FilterByProtocol(testCase.selection,
testCase.serverTCP, testCase.serverUDP)
assert.Equal(t, testCase.filtered, filtered)
})
}
}