-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller_options_test.go
More file actions
48 lines (38 loc) · 1.34 KB
/
controller_options_test.go
File metadata and controls
48 lines (38 loc) · 1.34 KB
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
44
45
46
47
48
package launch
import (
"log/slog"
"testing"
"time"
"github.com/shoenig/test"
"github.com/spikesdivzero/launch-control/internal/controller"
"github.com/spikesdivzero/launch-control/internal/testutil"
)
func TestWithControllerLogger(t *testing.T) {
c := controller.New(t.Context())
log := slog.New(slog.Default().Handler())
WithControllerLogger(log)(c)
test.Eq(t, log, c.Log)
t.Run("panics on nil", func(t *testing.T) {
defer testutil.WantPanic(t, optionNilArgError{"WithControllerLogger", "log"}.Error())
WithControllerLogger(nil)(c)
})
}
func TestWithControllerInternalAsyncGracePeriod(t *testing.T) {
t.Run("happy", func(t *testing.T) {
c := controller.New(t.Context())
WithControllerInternalAsyncGracePeriod(744 * time.Millisecond)(c)
test.Eq(t, 744*time.Millisecond, c.AsyncGracePeriod)
})
t.Run("panic on zero", func(t *testing.T) {
defer testutil.WantPanic(t, "AsyncGracePeriod must be a positive, non-zero value")
WithControllerInternalAsyncGracePeriod(0)
})
t.Run("panic on negative", func(t *testing.T) {
defer testutil.WantPanic(t, "AsyncGracePeriod must be a positive, non-zero value")
WithControllerInternalAsyncGracePeriod(-1)
})
t.Run("panic on unreasonable", func(t *testing.T) {
defer testutil.WantPanic(t, "AsyncGracePeriod must be reasonable")
WithControllerInternalAsyncGracePeriod(time.Minute)
})
}