refactor: move tunnel pkg down one level (#358)
* refactor: move tunnel pkg down one level While there, reduce unnecessary dependency on external packages. * file I forgot to commit
This commit is contained in:
parent
39aec6677d
commit
3cb6c7c6fb
21 changed files with 69 additions and 65 deletions
70
internal/tunnel/tunnel_test.go
Normal file
70
internal/tunnel/tunnel_test.go
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package tunnel_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/tunnel"
|
||||
)
|
||||
|
||||
func TestStartNoTunnel(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tun, err := tunnel.Start(ctx, &tunnel.Config{
|
||||
Name: "",
|
||||
Session: &tunnel.MockableSession{},
|
||||
})
|
||||
if !errors.Is(err, tunnel.ErrUnsupportedTunnelName) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
if tun != nil {
|
||||
t.Fatal("expected nil tunnel here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStartPsiphonWithCancelledContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // fail immediately
|
||||
tun, err := tunnel.Start(ctx, &tunnel.Config{
|
||||
Name: "psiphon",
|
||||
Session: &tunnel.MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
})
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
if tun != nil {
|
||||
t.Fatal("expected nil tunnel here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStartTorWithCancelledContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // fail immediately
|
||||
tun, err := tunnel.Start(ctx, &tunnel.Config{
|
||||
Name: "tor",
|
||||
Session: &tunnel.MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
})
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
if tun != nil {
|
||||
t.Fatal("expected nil tunnel here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStartInvalidTunnel(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tun, err := tunnel.Start(ctx, &tunnel.Config{
|
||||
Name: "antani",
|
||||
Session: &tunnel.MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
})
|
||||
if !errors.Is(err, tunnel.ErrUnsupportedTunnelName) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
if tun != nil {
|
||||
t.Fatal("expected nil tunnel here")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue