feat(oonirun): improve tests (#915)

See https://github.com/ooni/probe/issues/2184

While there, rename `runtimex.PanicIfFalse` to `runtimex.Assert` (it was about time...)
This commit is contained in:
Simone Basso
2022-08-31 18:40:27 +02:00
committed by GitHub
parent a8a29cc0dd
commit d0da224a2a
32 changed files with 1837 additions and 112 deletions
+3 -3
View File
@@ -11,8 +11,8 @@ func PanicOnError(err error, message string) {
}
}
// PanicIfFalse calls panic if assertion is false.
func PanicIfFalse(assertion bool, message string) {
// Assert calls panic if assertion is false.
func Assert(assertion bool, message string) {
if !assertion {
panic(message)
}
@@ -20,7 +20,7 @@ func PanicIfFalse(assertion bool, message string) {
// PanicIfTrue calls panic if assertion is true.
func PanicIfTrue(assertion bool, message string) {
PanicIfFalse(!assertion, message)
Assert(!assertion, message)
}
// PanicIfNil calls panic if the given interface is nil.
+3 -3
View File
@@ -28,17 +28,17 @@ func TestPanicOnError(t *testing.T) {
})
}
func TestPanicIfFalse(t *testing.T) {
func TestAssert(t *testing.T) {
badfunc := func(in bool, message string) (out error) {
defer func() {
out = errors.New(recover().(string))
}()
runtimex.PanicIfFalse(in, message)
runtimex.Assert(in, message)
return
}
t.Run("assertion is true", func(t *testing.T) {
runtimex.PanicIfFalse(true, "this assertion should not fail")
runtimex.Assert(true, "this assertion should not fail")
})
t.Run("assertion is false", func(t *testing.T) {