chore(updater): incorporate FetchServers method in Provider interface

- Each provider interface can now fetch updated servers data
- Rename each provider updater subpackage name to `updater`
- Updater constructor does not take a settings struct
- Updater update method takes in a slice of provider strings
This commit is contained in:
Quentin McGaw
2022-06-09 23:47:12 +00:00
parent 11b55abff3
commit ebd94723c1
148 changed files with 374 additions and 281 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"math/rand"
"net"
"net/http"
"testing"
"github.com/golang/mock/gomock"
@@ -96,7 +97,8 @@ func Test_Provider_GetConnection(t *testing.T) {
Return(testCase.filteredServers, testCase.storageErr)
randSource := rand.NewSource(0)
provider := New(storage, randSource)
client := (*http.Client)(nil)
provider := New(storage, randSource, client)
connection, err := provider.GetConnection(testCase.selection)

View File

@@ -2,9 +2,11 @@ package mullvad
import (
"math/rand"
"net/http"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/mullvad/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
)
@@ -12,13 +14,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
client *http.Client) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Mullvad),
Fetcher: updater.New(client),
}
}

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"errors"

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"bytes"

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"net"

View File

@@ -1,6 +1,6 @@
// Package mullvad contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the Mullvad provider.
package mullvad
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"net/http"