github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/helper/cluster_test.go (about) 1 package helper 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/shoenig/test/must" 8 ) 9 10 func TestCluster_RandomStagger(t *testing.T) { 11 cases := []struct { 12 name string 13 input time.Duration 14 }{ 15 {name: "positive", input: 1 * time.Second}, 16 {name: "negative", input: -1 * time.Second}, 17 {name: "zero", input: 0}, 18 } 19 20 abs := func(d time.Duration) time.Duration { 21 return Max(d, -d) 22 } 23 24 for _, tc := range cases { 25 result := RandomStagger(tc.input) 26 must.GreaterEq(t, 0, result) 27 must.LessEq(t, abs(tc.input), result) 28 } 29 }