feat: run ~always netxlite integration tests (#522)
* feat: run ~always netxlite integration tests This diff ensures that we check on windows, linux, macos that our fundamental networking library (netxlite) works. We combine unit and integration tests. This work is part of https://github.com/ooni/probe/issues/1733, where I want to have more strong guarantees about the foundations. * fix(filtering/tls_test.go): make portable on Windows The trick here is to use the wrapped error so to normalize the different errors messages we see on Windows. * fix(netxlite/quic_test.go): make portable on windows Rather than using the zero port, use the `x` port which fails when the stdlib is parsing the address. The zero port seems to work on Windows while it does not on Unix. * fix(serialresolver_test.go): make error more timeout than before This seems enough to convince Go on Windows about this error being really a timeout timeouty timeouted thingie.
This commit is contained in:
@@ -10,3 +10,15 @@ func PanicOnError(err error, message string) {
|
||||
panic(fmt.Errorf("%s: %w", message, err))
|
||||
}
|
||||
}
|
||||
|
||||
// PanicIfFalse calls panic if assertion is false.
|
||||
func PanicIfFalse(assertion bool, message string) {
|
||||
if !assertion {
|
||||
panic(message)
|
||||
}
|
||||
}
|
||||
|
||||
// PanicIfTrue calls panic if assertion is true.
|
||||
func PanicIfTrue(assertion bool, message string) {
|
||||
PanicIfFalse(!assertion, message)
|
||||
}
|
||||
|
||||
@@ -7,21 +7,67 @@ import (
|
||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||
)
|
||||
|
||||
func TestGood(t *testing.T) {
|
||||
runtimex.PanicOnError(nil, "antani failed")
|
||||
}
|
||||
|
||||
func TestBad(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
if !errors.Is(badfunc(expected), expected) {
|
||||
t.Fatal("not the error we expected")
|
||||
func TestPanicOnError(t *testing.T) {
|
||||
badfunc := func(in error) (out error) {
|
||||
defer func() {
|
||||
out = recover().(error)
|
||||
}()
|
||||
runtimex.PanicOnError(in, "antani failed")
|
||||
return
|
||||
}
|
||||
|
||||
t.Run("error is nil", func(t *testing.T) {
|
||||
runtimex.PanicOnError(nil, "antani failed")
|
||||
})
|
||||
|
||||
t.Run("error is not nil", func(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
if !errors.Is(badfunc(expected), expected) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func badfunc(in error) (out error) {
|
||||
defer func() {
|
||||
out = recover().(error)
|
||||
}()
|
||||
runtimex.PanicOnError(in, "antani failed")
|
||||
return
|
||||
func TestPanicIfFalse(t *testing.T) {
|
||||
badfunc := func(in bool, message string) (out error) {
|
||||
defer func() {
|
||||
out = errors.New(recover().(string))
|
||||
}()
|
||||
runtimex.PanicIfFalse(in, message)
|
||||
return
|
||||
}
|
||||
|
||||
t.Run("assertion is true", func(t *testing.T) {
|
||||
runtimex.PanicIfFalse(true, "antani failed")
|
||||
})
|
||||
|
||||
t.Run("assertion is false", func(t *testing.T) {
|
||||
message := "mocked error"
|
||||
err := badfunc(false, message)
|
||||
if err == nil || err.Error() != message {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestPanicIfTrue(t *testing.T) {
|
||||
badfunc := func(in bool, message string) (out error) {
|
||||
defer func() {
|
||||
out = errors.New(recover().(string))
|
||||
}()
|
||||
runtimex.PanicIfTrue(in, message)
|
||||
return
|
||||
}
|
||||
|
||||
t.Run("assertion is false", func(t *testing.T) {
|
||||
runtimex.PanicIfTrue(false, "antani failed")
|
||||
})
|
||||
|
||||
t.Run("assertion is true", func(t *testing.T) {
|
||||
message := "mocked error"
|
||||
err := badfunc(true, message)
|
||||
if err == nil || err.Error() != message {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user