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:
parent
d7cd1ebcaf
commit
ecb2aae1e8
13 changed files with 256 additions and 270 deletions
112
internal/engine/tunnel/psiphon_test.go
Normal file
112
internal/engine/tunnel/psiphon_test.go
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
package tunnel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/internal/mockable"
|
||||
"github.com/ooni/psiphon/oopsi/github.com/Psiphon-Labs/psiphon-tunnel-core/ClientLibrary/clientlib"
|
||||
)
|
||||
|
||||
func TestPsiphonFetchPsiphonConfigFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
sess := &mockable.Session{
|
||||
MockableFetchPsiphonConfigErr: expected,
|
||||
}
|
||||
tunnel, err := psiphonStart(context.Background(), sess, psiphonConfig{})
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
if tunnel != nil {
|
||||
t.Fatal("expected nil tunnel here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPsiphonMakeMkdirAllFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
dependencies := psiphonFakeDependencies{
|
||||
MkdirAllErr: expected,
|
||||
}
|
||||
sess := &mockable.Session{
|
||||
MockableFetchPsiphonConfigResult: []byte(`{}`),
|
||||
}
|
||||
tunnel, err := psiphonStart(context.Background(), sess, psiphonConfig{
|
||||
Dependencies: dependencies,
|
||||
})
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
if tunnel != nil {
|
||||
t.Fatal("expected nil tunnel here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPsiphonMakeRemoveAllFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
dependencies := psiphonFakeDependencies{
|
||||
RemoveAllErr: expected,
|
||||
}
|
||||
sess := &mockable.Session{
|
||||
MockableFetchPsiphonConfigResult: []byte(`{}`),
|
||||
}
|
||||
tunnel, err := psiphonStart(context.Background(), sess, psiphonConfig{
|
||||
Dependencies: dependencies,
|
||||
})
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
if tunnel != nil {
|
||||
t.Fatal("expected nil tunnel here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPsiphonMakeStartFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
dependencies := psiphonFakeDependencies{
|
||||
StartErr: expected,
|
||||
}
|
||||
sess := &mockable.Session{
|
||||
MockableFetchPsiphonConfigResult: []byte(`{}`),
|
||||
}
|
||||
tunnel, err := psiphonStart(context.Background(), sess, psiphonConfig{
|
||||
Dependencies: dependencies,
|
||||
})
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
if tunnel != nil {
|
||||
t.Fatal("expected nil tunnel here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPsiphonNilTunnel(t *testing.T) {
|
||||
var tunnel *psiphonTunnel
|
||||
if tunnel.BootstrapTime() != 0 {
|
||||
t.Fatal("expected zero bootstrap time")
|
||||
}
|
||||
if tunnel.SOCKS5ProxyURL() != nil {
|
||||
t.Fatal("expected nil SOCKS Proxy URL")
|
||||
}
|
||||
tunnel.Stop() // must not crash
|
||||
}
|
||||
|
||||
type psiphonFakeDependencies struct {
|
||||
MkdirAllErr error
|
||||
RemoveAllErr error
|
||||
StartErr error
|
||||
}
|
||||
|
||||
func (fd psiphonFakeDependencies) MkdirAll(path string, perm os.FileMode) error {
|
||||
return fd.MkdirAllErr
|
||||
}
|
||||
|
||||
func (fd psiphonFakeDependencies) RemoveAll(path string) error {
|
||||
return fd.RemoveAllErr
|
||||
}
|
||||
|
||||
func (fd psiphonFakeDependencies) Start(
|
||||
ctx context.Context, config []byte, workdir string) (*clientlib.PsiphonTunnel, error) {
|
||||
return nil, fd.StartErr
|
||||
}
|
||||
Loading…
Reference in a new issue