initial code
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -23,6 +24,7 @@ func Test_GetPort(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
selection settings.ServerSelection
|
||||
server models.Server
|
||||
defaultOpenVPNTCP uint16
|
||||
defaultOpenVPNUDP uint16
|
||||
defaultWireguard uint16
|
||||
@@ -49,6 +51,20 @@ func Test_GetPort(t *testing.T) {
|
||||
defaultWireguard: defaultWireguard,
|
||||
port: defaultOpenVPNUDP,
|
||||
},
|
||||
"OpenVPN_server_port_udp": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
server: models.Server{
|
||||
PortsUDP: []uint16{1234},
|
||||
},
|
||||
defaultOpenVPNUDP: defaultOpenVPNUDP,
|
||||
port: 1234,
|
||||
},
|
||||
"OpenVPN UDP no default port defined": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.OpenVPN,
|
||||
@@ -89,6 +105,20 @@ func Test_GetPort(t *testing.T) {
|
||||
},
|
||||
port: 1234,
|
||||
},
|
||||
"OpenVPN_server_port_tcp": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
Protocol: constants.TCP,
|
||||
},
|
||||
},
|
||||
server: models.Server{
|
||||
PortsTCP: []uint16{1234},
|
||||
},
|
||||
defaultOpenVPNTCP: defaultOpenVPNTCP,
|
||||
port: 1234,
|
||||
},
|
||||
"Wireguard": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.Wireguard,
|
||||
@@ -106,6 +136,19 @@ func Test_GetPort(t *testing.T) {
|
||||
defaultWireguard: defaultWireguard,
|
||||
port: 1234,
|
||||
},
|
||||
"Wireguard_server_port": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.Wireguard,
|
||||
Wireguard: settings.WireguardSelection{
|
||||
EndpointPort: uint16Ptr(0),
|
||||
},
|
||||
},
|
||||
server: models.Server{
|
||||
PortsUDP: []uint16{1234},
|
||||
},
|
||||
defaultWireguard: defaultWireguard,
|
||||
port: 1234,
|
||||
},
|
||||
"Wireguard no default port defined": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: vpn.Wireguard,
|
||||
@@ -121,6 +164,7 @@ func Test_GetPort(t *testing.T) {
|
||||
if testCase.panics != "" {
|
||||
assert.PanicsWithValue(t, testCase.panics, func() {
|
||||
_ = getPort(testCase.selection,
|
||||
testCase.server,
|
||||
testCase.defaultOpenVPNTCP,
|
||||
testCase.defaultOpenVPNUDP,
|
||||
testCase.defaultWireguard)
|
||||
@@ -129,6 +173,7 @@ func Test_GetPort(t *testing.T) {
|
||||
}
|
||||
|
||||
port := getPort(testCase.selection,
|
||||
testCase.server,
|
||||
testCase.defaultOpenVPNTCP,
|
||||
testCase.defaultOpenVPNUDP,
|
||||
testCase.defaultWireguard)
|
||||
|
||||
Reference in New Issue
Block a user