refactor: merge psiphonx and torx into tunnel (#287)

* refactor: merge psiphonx and torx into tunnel

This is a case where it seems that merging these three packages into
a single package will enable us to better the implementation.

The goal is still https://github.com/ooni/probe/issues/985.

The roadblock I'm trying to overcome is
https://github.com/ooni/probe-cli/pull/286#pullrequestreview-627460104.

* avoid duplicating logger for now
This commit is contained in:
Simone Basso 2021-04-03 19:57:21 +02:00 committed by GitHub
commit ecb2aae1e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 256 additions and 270 deletions

View file

@ -1,80 +0,0 @@
package tunnel_test
import (
"context"
"errors"
"testing"
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/internal/mockable"
"github.com/ooni/probe-cli/v3/internal/engine/internal/tunnel"
)
func TestNoTunnel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
tunnel, err := tunnel.Start(ctx, tunnel.Config{
Name: "",
Session: &mockable.Session{
MockableLogger: log.Log,
},
})
if err != nil {
t.Fatal(err)
}
if tunnel != nil {
t.Fatal("expected nil tunnel here")
}
}
func TestPsiphonTunnel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
tunnel, err := tunnel.Start(ctx, tunnel.Config{
Name: "psiphon",
Session: &mockable.Session{
MockableLogger: log.Log,
},
})
if !errors.Is(err, context.Canceled) {
t.Fatal("not the error we expected")
}
if tunnel != nil {
t.Fatal("expected nil tunnel here")
}
}
func TestTorTunnel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
tunnel, err := tunnel.Start(ctx, tunnel.Config{
Name: "tor",
Session: &mockable.Session{
MockableLogger: log.Log,
},
})
if !errors.Is(err, context.Canceled) {
t.Fatal("not the error we expected")
}
if tunnel != nil {
t.Fatal("expected nil tunnel here")
}
}
func TestInvalidTunnel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
tunnel, err := tunnel.Start(ctx, tunnel.Config{
Name: "antani",
Session: &mockable.Session{
MockableLogger: log.Log,
},
})
if err == nil || err.Error() != "unsupported tunnel" {
t.Fatal("not the error we expected")
}
t.Log(tunnel)
if tunnel != nil {
t.Fatal("expected nil tunnel here")
}
}