chore(internal/provider): GetConnection test

This commit is contained in:
Quentin McGaw
2022-05-07 17:08:25 +00:00
parent e32d251cc1
commit 0ef7b66047
9 changed files with 205 additions and 39 deletions

View File

@@ -1,7 +1,7 @@
package utils
import (
"fmt"
"errors"
"math/rand"
"github.com/qdm12/gluetun/internal/configuration/settings"
@@ -24,14 +24,20 @@ func NewConnectionDefaults(openvpnTCPPort, openvpnUDPPort,
}
}
var ErrNoServer = errors.New("no server")
func GetConnection(servers []models.Server,
selection settings.ServerSelection,
defaults ConnectionDefaults,
randSource rand.Source) (
connection models.Connection, err error) {
servers, err = FilterServers(servers, selection)
if err != nil {
return connection, fmt.Errorf("cannot filter servers: %w", err)
if len(servers) == 0 {
return connection, ErrNoServer
}
servers = FilterServers(servers, selection)
if len(servers) == 0 {
return connection, NoServerFoundError(selection)
}
protocol := getProtocol(selection)