refactor(tunnel): pass the config as a pointer (#288)

Part of https://github.com/ooni/probe/issues/985
This commit is contained in:
Simone Basso
2021-04-03 20:12:56 +02:00
committed by GitHub
parent ecb2aae1e8
commit b53290cbfe
5 changed files with 18 additions and 11 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ func TestPsiphonStartWithCancelledContext(t *testing.T) {
if err != nil {
t.Fatal(err)
}
tunnel, err := tunnel.Start(ctx, tunnel.Config{
tunnel, err := tunnel.Start(ctx, &tunnel.Config{
Name: "psiphon",
Session: sess,
})
@@ -45,7 +45,7 @@ func TestPsiphonStartStop(t *testing.T) {
if err != nil {
t.Fatal(err)
}
tunnel, err := tunnel.Start(context.Background(), tunnel.Config{
tunnel, err := tunnel.Start(context.Background(), &tunnel.Config{
Name: "psiphon",
Session: sess,
})
+10 -3
View File
@@ -27,16 +27,23 @@ type Tunnel interface {
Stop()
}
// Config contains config for the session tunnel.
// Config contains the configuration for creating a Tunnel instance.
type Config struct {
Name string
// Name is the mandatory name of the tunnel. We support
// "tor" and "psiphon" tunnels.
Name string
// Session is the current measurement session.
Session Session
// WorkDir is the directory in which the tunnel SHOULD
// store its state, if any.
WorkDir string
}
// Start starts a new tunnel by name or returns an error. Note that if you
// pass to this function the "" tunnel, you get back nil, nil.
func Start(ctx context.Context, config Config) (Tunnel, error) {
func Start(ctx context.Context, config *Config) (Tunnel, error) {
logger := config.Session.Logger()
switch config.Name {
case "":
+4 -4
View File
@@ -12,7 +12,7 @@ import (
func TestStartNoTunnel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
tunnel, err := Start(ctx, Config{
tunnel, err := Start(ctx, &Config{
Name: "",
Session: &mockable.Session{
MockableLogger: log.Log,
@@ -29,7 +29,7 @@ func TestStartNoTunnel(t *testing.T) {
func TestStartPsiphonTunnel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
tunnel, err := Start(ctx, Config{
tunnel, err := Start(ctx, &Config{
Name: "psiphon",
Session: &mockable.Session{
MockableLogger: log.Log,
@@ -46,7 +46,7 @@ func TestStartPsiphonTunnel(t *testing.T) {
func TestStartTorTunnel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
tunnel, err := Start(ctx, Config{
tunnel, err := Start(ctx, &Config{
Name: "tor",
Session: &mockable.Session{
MockableLogger: log.Log,
@@ -63,7 +63,7 @@ func TestStartTorTunnel(t *testing.T) {
func TestStartInvalidTunnel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
tunnel, err := Start(ctx, Config{
tunnel, err := Start(ctx, &Config{
Name: "antani",
Session: &mockable.Session{
MockableLogger: log.Log,