mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
b36151d992
In addition to those commands already supported: * build * check * eval * fmt * test support has been added to the following commands: * `bench` * `deps` * `exec` * `inspect` * `parse` * `run` (command `server` and `REPL`) Fixes: #6520 Signed-off-by: Johan Fylling <johan.dev@fylling.se>
48 lines
839 B
Go
48 lines
839 B
Go
// 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 (
|
|
"bytes"
|
|
"sync"
|
|
"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
|
|
}
|
|
|
|
type BlockingWriter struct {
|
|
m sync.Mutex
|
|
buf bytes.Buffer
|
|
}
|
|
|
|
func (w *BlockingWriter) Write(p []byte) (n int, err error) {
|
|
w.m.Lock()
|
|
defer w.m.Unlock()
|
|
return w.buf.Write(p)
|
|
}
|
|
|
|
func (w *BlockingWriter) String() string {
|
|
w.m.Lock()
|
|
defer w.m.Unlock()
|
|
return w.buf.String()
|
|
}
|
|
|
|
func (w *BlockingWriter) Reset() {
|
|
w.m.Lock()
|
|
defer w.m.Unlock()
|
|
w.buf.Reset()
|
|
}
|