feat(tunnel): improve the test suite (#297)

Part of https://github.com/ooni/probe/issues/985
This commit is contained in:
Simone Basso 2021-04-05 16:38:25 +02:00 committed by GitHub
commit 76a50facc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 143 additions and 57 deletions

View file

@ -10,6 +10,37 @@ import (
"github.com/ooni/psiphon/oopsi/github.com/Psiphon-Labs/psiphon-tunnel-core/ClientLibrary/clientlib"
)
func TestPsiphonWithCancelledContext(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel() // immediately fail
sess := &mockable.Session{}
tunnel, err := psiphonStart(ctx, &Config{
Session: sess,
TunnelDir: "testdata",
})
if !errors.Is(err, context.Canceled) {
t.Fatal("not the error we expected")
}
if tunnel != nil {
t.Fatal("expected nil tunnel here")
}
}
func TestPsiphonWithEmptyTunnelDir(t *testing.T) {
ctx := context.Background()
sess := &mockable.Session{}
tunnel, err := psiphonStart(ctx, &Config{
Session: sess,
TunnelDir: "",
})
if !errors.Is(err, ErrEmptyTunnelDir) {
t.Fatal("not the error we expected")
}
if tunnel != nil {
t.Fatal("expected nil tunnel here")
}
}
func TestPsiphonFetchPsiphonConfigFailure(t *testing.T) {
expected := errors.New("mocked error")
sess := &mockable.Session{