chore(constants): internal/constants/providers

- New package to avoid package import cycles
This commit is contained in:
Quentin McGaw
2022-04-16 19:30:26 +00:00
parent ad80e0c1ab
commit 54b7e23974
51 changed files with 335 additions and 339 deletions

View File

@@ -8,6 +8,7 @@ import (
"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/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -23,7 +24,7 @@ func Test_Mullvad_GetConnection(t *testing.T) {
err error
}{
"no server available": {
selection: settings.ServerSelection{}.WithDefaults(constants.Mullvad),
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
err: errors.New("no server found: for VPN openvpn; protocol udp"),
},
"no filter": {
@@ -32,7 +33,7 @@ func Test_Mullvad_GetConnection(t *testing.T) {
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
},
selection: settings.ServerSelection{}.WithDefaults(constants.Mullvad),
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
connection: models.Connection{
Type: constants.OpenVPN,
IP: net.IPv4(1, 1, 1, 1),
@@ -43,7 +44,7 @@ func Test_Mullvad_GetConnection(t *testing.T) {
"target IP": {
selection: settings.ServerSelection{
TargetIP: net.IPv4(2, 2, 2, 2),
}.WithDefaults(constants.Mullvad),
}.WithDefaults(providers.Mullvad),
servers: []models.MullvadServer{
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
@@ -59,7 +60,7 @@ func Test_Mullvad_GetConnection(t *testing.T) {
"with filter": {
selection: settings.ServerSelection{
Hostnames: []string{"b"},
}.WithDefaults(constants.Mullvad),
}.WithDefaults(providers.Mullvad),
servers: []models.MullvadServer{
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},

View File

@@ -7,6 +7,7 @@ import (
"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/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -24,7 +25,7 @@ func Test_Mullvad_filterServers(t *testing.T) {
err error
}{
"no server available": {
selection: settings.ServerSelection{}.WithDefaults(constants.Mullvad),
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
err: errors.New("no server found: for VPN openvpn; protocol udp"),
},
"no filter": {
@@ -33,7 +34,7 @@ func Test_Mullvad_filterServers(t *testing.T) {
{VPN: constants.OpenVPN, Hostname: "b"},
{VPN: constants.OpenVPN, Hostname: "c"},
},
selection: settings.ServerSelection{}.WithDefaults(constants.Mullvad),
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
filtered: []models.MullvadServer{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b"},
@@ -43,7 +44,7 @@ func Test_Mullvad_filterServers(t *testing.T) {
"filter OpenVPN out": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
}.WithDefaults(constants.Mullvad),
}.WithDefaults(providers.Mullvad),
servers: []models.MullvadServer{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.Wireguard, Hostname: "b"},
@@ -56,7 +57,7 @@ func Test_Mullvad_filterServers(t *testing.T) {
"filter by country": {
selection: settings.ServerSelection{
Countries: []string{"b"},
}.WithDefaults(constants.Mullvad),
}.WithDefaults(providers.Mullvad),
servers: []models.MullvadServer{
{VPN: constants.OpenVPN, Country: "a"},
{VPN: constants.OpenVPN, Country: "b"},
@@ -69,7 +70,7 @@ func Test_Mullvad_filterServers(t *testing.T) {
"filter by city": {
selection: settings.ServerSelection{
Cities: []string{"b"},
}.WithDefaults(constants.Mullvad),
}.WithDefaults(providers.Mullvad),
servers: []models.MullvadServer{
{VPN: constants.OpenVPN, City: "a"},
{VPN: constants.OpenVPN, City: "b"},
@@ -82,7 +83,7 @@ func Test_Mullvad_filterServers(t *testing.T) {
"filter by ISP": {
selection: settings.ServerSelection{
ISPs: []string{"b"},
}.WithDefaults(constants.Mullvad),
}.WithDefaults(providers.Mullvad),
servers: []models.MullvadServer{
{VPN: constants.OpenVPN, ISP: "a"},
{VPN: constants.OpenVPN, ISP: "b"},
@@ -95,7 +96,7 @@ func Test_Mullvad_filterServers(t *testing.T) {
"filter by hostname": {
selection: settings.ServerSelection{
Hostnames: []string{"b"},
}.WithDefaults(constants.Mullvad),
}.WithDefaults(providers.Mullvad),
servers: []models.MullvadServer{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b"},
@@ -108,7 +109,7 @@ func Test_Mullvad_filterServers(t *testing.T) {
"filter by owned": {
selection: settings.ServerSelection{
OwnedOnly: boolPtr(true),
}.WithDefaults(constants.Mullvad),
}.WithDefaults(providers.Mullvad),
servers: []models.MullvadServer{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b", Owned: true},

View File

@@ -3,7 +3,7 @@ package mullvad
import (
"math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
)
@@ -18,6 +18,6 @@ func New(servers []models.MullvadServer, randSource rand.Source) *Mullvad {
return &Mullvad{
servers: servers,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Mullvad),
NoPortForwarder: utils.NewNoPortForwarding(providers.Mullvad),
}
}