forked from hashicorp/nomad-autoscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler_test.go
49 lines (41 loc) · 1.2 KB
/
handler_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
44
45
46
47
48
49
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package policy
import (
"testing"
"time"
hclog "github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/assert"
)
func TestHandler_calculateRemainingCooldown(t *testing.T) {
baseTime := time.Now().UTC().UnixNano()
testCases := []struct {
inputCooldown time.Duration
inputTimestamp int64
inputLastEvent int64
expectedOutput time.Duration
name string
}{
{
inputCooldown: 20 * time.Minute,
inputTimestamp: baseTime,
inputLastEvent: baseTime - 10*time.Minute.Nanoseconds(),
expectedOutput: 10 * time.Minute,
name: "resulting cooldown of 10 minutes",
},
{
inputCooldown: 20 * time.Minute,
inputTimestamp: baseTime,
inputLastEvent: baseTime - 25*time.Minute.Nanoseconds(),
expectedOutput: -5 * time.Minute,
name: "negative cooldown period; ie. no cooldown",
},
}
h := NewHandler("", hclog.NewNullLogger(), nil, nil)
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actualOutput := h.calculateRemainingCooldown(tc.inputCooldown, tc.inputTimestamp, tc.inputLastEvent)
assert.Equal(t, tc.expectedOutput, actualOutput, tc.name)
})
}
}