Files
gluetun/internal/provider/utils/port_test.go
Quentin McGaw 7d824a5179 chore(settings): refactor settings processing (#756)
- Better settings tree structure logged using `qdm12/gotree`
- Read settings from environment variables, then files, then secret files
- Settings methods to default them, merge them and override them
- `DNS_PLAINTEXT_ADDRESS` default changed to `127.0.0.1` to use DoT. Warning added if set to something else.
- `HTTPPROXY_LISTENING_ADDRESS` instead of `HTTPPROXY_PORT` (with retro-compatibility)
2022-01-06 06:40:23 -05:00

89 lines
1.9 KiB
Go

package utils
import (
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/stretchr/testify/assert"
)
func boolPtr(b bool) *bool { return &b }
func uint16Ptr(n uint16) *uint16 { return &n }
func Test_GetPort(t *testing.T) {
t.Parallel()
const (
defaultOpenVPNTCP = 443
defaultOpenVPNUDP = 1194
defaultWireguard = 51820
)
testCases := map[string]struct {
selection settings.ServerSelection
port uint16
}{
"default": {
selection: settings.ServerSelection{}.WithDefaults(""),
port: defaultOpenVPNUDP,
},
"OpenVPN UDP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
TCP: boolPtr(false),
},
},
port: defaultOpenVPNUDP,
},
"OpenVPN TCP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
TCP: boolPtr(true),
},
},
port: defaultOpenVPNTCP,
},
"OpenVPN custom port": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(1234),
},
},
port: 1234,
},
"Wireguard": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
}.WithDefaults(""),
port: defaultWireguard,
},
"Wireguard custom port": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
Wireguard: settings.WireguardSelection{
EndpointPort: uint16Ptr(1234),
},
},
port: 1234,
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
port := GetPort(testCase.selection,
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard)
assert.Equal(t, testCase.port, port)
})
}
}