fix(session): make sure tunnel code is tested (#301)
* fix(session): make sure tunnel code is tested Part of https://github.com/ooni/probe/issues/985 * fix: add missing TunnelDir for correctness
This commit is contained in:
parent
8b92037ae3
commit
7172e750dd
4 changed files with 69 additions and 4 deletions
|
|
@ -3,9 +3,11 @@ package engine
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/url"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/geolocate"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
||||
|
|
@ -247,3 +249,45 @@ func TestSessionFetchPsiphonConfigWithCancelledContext(t *testing.T) {
|
|||
t.Fatal("expected nil response here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewSessionWithFakeTunnel(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
sess, err := NewSession(ctx, SessionConfig{
|
||||
Logger: log.Log,
|
||||
ProxyURL: &url.URL{Scheme: "fake"},
|
||||
SoftwareName: "miniooni",
|
||||
SoftwareVersion: "0.1.0-dev",
|
||||
TunnelDir: "testdata",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if sess == nil {
|
||||
t.Fatal("expected non-nil session here")
|
||||
}
|
||||
if sess.ProxyURL() == nil {
|
||||
t.Fatal("expected non-nil proxyURL here")
|
||||
}
|
||||
if sess.tunnel == nil {
|
||||
t.Fatal("expected non-nil tunnel here")
|
||||
}
|
||||
sess.Close() // ensure we don't crash
|
||||
}
|
||||
|
||||
func TestNewSessionWithFakeTunnelAndCancelledContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // fail immediately
|
||||
sess, err := NewSession(ctx, SessionConfig{
|
||||
Logger: log.Log,
|
||||
ProxyURL: &url.URL{Scheme: "fake"},
|
||||
SoftwareName: "miniooni",
|
||||
SoftwareVersion: "0.1.0-dev",
|
||||
TunnelDir: "testdata",
|
||||
})
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
if sess != nil {
|
||||
t.Fatal("expected nil session here")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue