feat(tunnel): introduce persistent tunnel state dir (#294)

* feat(tunnel): introduce persistent tunnel state dir

This diff introduces a persistent state directory for tunnels, so that
we can bootstrap them more quickly after the first time.

Part of https://github.com/ooni/probe/issues/985

* fix: make tunnel dir optional

We have many tests where it does not make sense to explicitly
provide a tunnel dir because we're not using tunnels.

This should simplify setting up a session.

* fix(tunnel): repair tests

* final changes

* more cleanups
This commit is contained in:
Simone Basso 2021-04-05 11:27:41 +02:00 committed by GitHub
commit 8fe4e5410d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 166 additions and 105 deletions

View file

@ -16,7 +16,8 @@ func TestPsiphonFetchPsiphonConfigFailure(t *testing.T) {
MockableFetchPsiphonConfigErr: expected,
}
tunnel, err := psiphonStart(context.Background(), &Config{
Session: sess,
Session: sess,
TunnelDir: "testdata",
})
if !errors.Is(err, expected) {
t.Fatal("not the error we expected")
@ -32,7 +33,8 @@ func TestPsiphonMkdirAllFailure(t *testing.T) {
MockableFetchPsiphonConfigResult: []byte(`{}`),
}
tunnel, err := psiphonStart(context.Background(), &Config{
Session: sess,
Session: sess,
TunnelDir: "testdata",
testMkdirAll: func(path string, perm os.FileMode) error {
return expected
},
@ -45,32 +47,14 @@ func TestPsiphonMkdirAllFailure(t *testing.T) {
}
}
func TestPsiphonRemoveAllFailure(t *testing.T) {
expected := errors.New("mocked error")
sess := &mockable.Session{
MockableFetchPsiphonConfigResult: []byte(`{}`),
}
tunnel, err := psiphonStart(context.Background(), &Config{
Session: sess,
testRemoveAll: func(path string) error {
return expected
},
})
if !errors.Is(err, expected) {
t.Fatal("not the error we expected")
}
if tunnel != nil {
t.Fatal("expected nil tunnel here")
}
}
func TestPsiphonStartFailure(t *testing.T) {
expected := errors.New("mocked error")
sess := &mockable.Session{
MockableFetchPsiphonConfigResult: []byte(`{}`),
}
tunnel, err := psiphonStart(context.Background(), &Config{
Session: sess,
Session: sess,
TunnelDir: "testdata",
testStartPsiphon: func(ctx context.Context, config []byte,
workdir string) (*clientlib.PsiphonTunnel, error) {
return nil, expected