forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait_test.go
43 lines (38 loc) · 1.04 KB
/
wait_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2020 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 util
import (
"testing"
"time"
)
func TestWaitFunc(t *testing.T) {
trueAfter := func(after time.Duration) func() bool {
t := time.Now().Add(after)
return func() bool {
return time.Now().After(t)
}
}
cases := []struct {
trueAfter time.Duration
interval time.Duration
timeout time.Duration
shouldFail bool
}{
{0, 1 * time.Millisecond, 100 * time.Millisecond, false},
{1 * time.Millisecond, 1 * time.Millisecond, 100 * time.Millisecond, false},
{100 * time.Millisecond, 1 * time.Millisecond, 1 * time.Millisecond, true},
{100 * time.Millisecond, 1000 * time.Millisecond, 1 * time.Millisecond, true},
}
for _, c := range cases {
err := WaitFunc(trueAfter(c.trueAfter), c.interval, c.timeout)
if err != nil && c.shouldFail {
continue
}
if err != nil {
t.Error(err)
} else if c.shouldFail {
t.Errorf("Expected error for case: %+v", c)
}
}
}