Files
gluetun/internal/provider/utils/wireguard_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

68 lines
1.6 KiB
Go

package utils
import (
"net"
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/wireguard"
"github.com/stretchr/testify/assert"
)
func stringPtr(s string) *string { return &s }
func Test_BuildWireguardSettings(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
connection models.Connection
userSettings settings.Wireguard
settings wireguard.Settings
}{
"some settings": {
connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4),
Port: 51821,
PubKey: "public",
},
userSettings: settings.Wireguard{
PrivateKey: stringPtr("private"),
PreSharedKey: stringPtr("pre-shared"),
Addresses: []net.IPNet{
{IP: net.IPv4(1, 1, 1, 1), Mask: net.IPv4Mask(255, 255, 255, 255)},
{IP: net.IPv4(2, 2, 2, 2), Mask: net.IPv4Mask(255, 255, 255, 255)},
},
Interface: "wg1",
},
settings: wireguard.Settings{
InterfaceName: "wg1",
PrivateKey: "private",
PublicKey: "public",
PreSharedKey: "pre-shared",
Endpoint: &net.UDPAddr{
IP: net.IPv4(1, 2, 3, 4),
Port: 51821,
},
Addresses: []*net.IPNet{
{IP: net.IPv4(1, 1, 1, 1), Mask: net.IPv4Mask(255, 255, 255, 255)},
{IP: net.IPv4(2, 2, 2, 2), Mask: net.IPv4Mask(255, 255, 255, 255)},
},
RulePriority: 101,
},
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
settings := BuildWireguardSettings(testCase.connection,
testCase.userSettings)
assert.Equal(t, testCase.settings, settings)
})
}
}