git » chasquid » commit 29512f7

testlib: Add tests for testlib.WaitFor

author Alberto Bertogli
2020-03-21 23:56:31 UTC
committer Alberto Bertogli
2020-03-21 23:56:31 UTC
parent fdae72f275c34ecce2a30e641d55e9e76e857863

testlib: Add tests for testlib.WaitFor

internal/testlib/testlib_test.go +13 -0

diff --git a/internal/testlib/testlib_test.go b/internal/testlib/testlib_test.go
index 10c90eb..b2da661 100644
--- a/internal/testlib/testlib_test.go
+++ b/internal/testlib/testlib_test.go
@@ -4,6 +4,7 @@ import (
 	"io/ioutil"
 	"os"
 	"testing"
+	"time"
 )
 
 func TestBasic(t *testing.T) {
@@ -83,3 +84,15 @@ func TestGetFreePort(t *testing.T) {
 		t.Errorf("failed to get free port")
 	}
 }
+
+func TestWaitFor(t *testing.T) {
+	ok := WaitFor(func() bool { return true }, 20*time.Millisecond)
+	if !ok {
+		t.Errorf("WaitFor(true) timed out")
+	}
+
+	ok = WaitFor(func() bool { return false }, 20*time.Millisecond)
+	if ok {
+		t.Errorf("WaitFor(false) worked")
+	}
+}