chore(config): use openvpn protocol string field instead of TCP bool
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
@@ -50,7 +51,7 @@ func Test_FilterServers(t *testing.T) {
|
||||
"filter by network protocol": {
|
||||
selection: settings.ServerSelection{
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
Protocol: constants.TCP,
|
||||
},
|
||||
}.WithDefaults(providers.Ivpn),
|
||||
servers: []models.Server{
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
)
|
||||
|
||||
@@ -22,7 +23,7 @@ func getPort(selection settings.ServerSelection,
|
||||
if customPort > 0 {
|
||||
return customPort
|
||||
}
|
||||
if *selection.OpenVPN.TCP {
|
||||
if selection.OpenVPN.Protocol == constants.TCP {
|
||||
checkDefined("OpenVPN TCP", defaultOpenVPNTCP)
|
||||
return defaultOpenVPNTCP
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -40,7 +41,7 @@ func Test_GetPort(t *testing.T) {
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
TCP: boolPtr(false),
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
defaultOpenVPNTCP: defaultOpenVPNTCP,
|
||||
@@ -53,7 +54,7 @@ func Test_GetPort(t *testing.T) {
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
TCP: boolPtr(false),
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
panics: "no default OpenVPN UDP port is defined!",
|
||||
@@ -63,7 +64,7 @@ func Test_GetPort(t *testing.T) {
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
TCP: boolPtr(true),
|
||||
Protocol: constants.TCP,
|
||||
},
|
||||
},
|
||||
defaultOpenVPNTCP: defaultOpenVPNTCP,
|
||||
@@ -74,7 +75,7 @@ func Test_GetPort(t *testing.T) {
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
TCP: boolPtr(true),
|
||||
Protocol: constants.TCP,
|
||||
},
|
||||
},
|
||||
panics: "no default OpenVPN TCP port is defined!",
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func getProtocol(selection settings.ServerSelection) (protocol string) {
|
||||
if selection.VPN == vpn.OpenVPN && *selection.OpenVPN.TCP {
|
||||
if selection.VPN == vpn.OpenVPN && selection.OpenVPN.Protocol == constants.TCP {
|
||||
return constants.TCP
|
||||
}
|
||||
return constants.UDP
|
||||
@@ -19,7 +19,7 @@ func filterByProtocol(selection settings.ServerSelection,
|
||||
case vpn.Wireguard:
|
||||
return !serverUDP
|
||||
default: // OpenVPN
|
||||
wantTCP := *selection.OpenVPN.TCP
|
||||
wantTCP := selection.OpenVPN.Protocol == constants.TCP
|
||||
wantUDP := !wantTCP
|
||||
return (wantTCP && !serverTCP) || (wantUDP && !serverUDP)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func Test_getProtocol(t *testing.T) {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(false),
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
protocol: constants.UDP,
|
||||
@@ -32,7 +32,7 @@ func Test_getProtocol(t *testing.T) {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
Protocol: constants.TCP,
|
||||
},
|
||||
},
|
||||
protocol: constants.TCP,
|
||||
@@ -84,7 +84,7 @@ func Test_filterByProtocol(t *testing.T) {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(false),
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
serverUDP: true,
|
||||
@@ -94,7 +94,7 @@ func Test_filterByProtocol(t *testing.T) {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(false),
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
serverUDP: false,
|
||||
@@ -104,7 +104,7 @@ func Test_filterByProtocol(t *testing.T) {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
Protocol: constants.TCP,
|
||||
},
|
||||
},
|
||||
serverTCP: true,
|
||||
@@ -114,7 +114,7 @@ func Test_filterByProtocol(t *testing.T) {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
Protocol: constants.TCP,
|
||||
},
|
||||
},
|
||||
serverTCP: false,
|
||||
|
||||
Reference in New Issue
Block a user