cmd: Making test watch-mode tests more robust (#6019)

* Waiting for output buffer to contain expected data rather than making exact matches on the entire content.
* Not aborting watcher on encountered errors

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
This commit is contained in:
Johan Fylling
2023-06-19 10:51:28 +02:00
committed by GitHub
parent 8243359538
commit 304be03e98
4 changed files with 267 additions and 87 deletions
+22
View File
@@ -0,0 +1,22 @@
// Copyright 2023 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package test
import (
"testing"
"time"
)
func Eventually(t *testing.T, timeout time.Duration, f func() bool) bool {
t.Helper()
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
if f() {
return true
}
time.Sleep(10 * time.Millisecond)
}
return false
}