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)
This commit is contained in:
Quentin McGaw
2022-01-06 06:40:23 -05:00
committed by GitHub
parent 46738b2934
commit 7d824a5179
275 changed files with 7167 additions and 6328 deletions

View File

@@ -3,11 +3,14 @@ package utils
import (
"testing"
"github.com/qdm12/gluetun/internal/configuration"
"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()
@@ -18,47 +21,53 @@ func Test_GetPort(t *testing.T) {
)
testCases := map[string]struct {
selection configuration.ServerSelection
selection settings.ServerSelection
port uint16
}{
"default": {
port: defaultOpenVPNUDP,
selection: settings.ServerSelection{}.WithDefaults(""),
port: defaultOpenVPNUDP,
},
"OpenVPN UDP": {
selection: configuration.ServerSelection{
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
TCP: boolPtr(false),
},
},
port: defaultOpenVPNUDP,
},
"OpenVPN TCP": {
selection: configuration.ServerSelection{
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: configuration.OpenVPNSelection{
TCP: true,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
TCP: boolPtr(true),
},
},
port: defaultOpenVPNTCP,
},
"OpenVPN custom port": {
selection: configuration.ServerSelection{
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
OpenVPN: configuration.OpenVPNSelection{
CustomPort: 1234,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(1234),
},
},
port: 1234,
},
"Wireguard": {
selection: configuration.ServerSelection{
selection: settings.ServerSelection{
VPN: constants.Wireguard,
},
}.WithDefaults(""),
port: defaultWireguard,
},
"Wireguard custom port": {
selection: configuration.ServerSelection{
selection: settings.ServerSelection{
VPN: constants.Wireguard,
Wireguard: configuration.WireguardSelection{
EndpointPort: 1234,
Wireguard: settings.WireguardSelection{
EndpointPort: uint16Ptr(1234),
},
},
port: 1234,