2021-06-08 19:40:17 +02:00
|
|
|
package dialer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2021-06-08 21:56:57 +02:00
|
|
|
"time"
|
2021-06-08 19:40:17 +02:00
|
|
|
|
|
|
|
"github.com/ooni/psiphon/oopsi/golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2021-06-08 21:56:57 +02:00
|
|
|
func TestSystemDialerWorks(t *testing.T) {
|
2021-06-08 19:40:17 +02:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel() // fail immediately
|
2021-06-09 09:42:31 +02:00
|
|
|
conn, err := systemDialer.DialContext(ctx, "tcp", "8.8.8.8:853")
|
2021-06-08 19:40:17 +02:00
|
|
|
if err == nil || !strings.HasSuffix(err.Error(), "operation was canceled") {
|
|
|
|
t.Fatal("not the error we expected", err)
|
|
|
|
}
|
|
|
|
if conn != nil {
|
|
|
|
t.Fatal("expected nil conn here")
|
|
|
|
}
|
|
|
|
}
|
2021-06-08 21:56:57 +02:00
|
|
|
|
2021-06-09 09:42:31 +02:00
|
|
|
func TestSystemDialerHasTimeout(t *testing.T) {
|
2021-06-08 21:56:57 +02:00
|
|
|
expected := 15 * time.Second
|
2021-06-09 09:42:31 +02:00
|
|
|
if systemDialer.Timeout != expected {
|
2021-06-08 21:56:57 +02:00
|
|
|
t.Fatal("unexpected timeout value")
|
|
|
|
}
|
|
|
|
}
|