github.com/verrazzano/verrazzano@v1.7.0/pkg/controller/requeue_test.go (about) 1 // Copyright (c) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 package controller 4 5 import ( 6 "testing" 7 "time" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 // TestNewRequeueWithDelay tests the NewRequeueWithDelay func for the following use case 13 // GIVEN a request to NewRequeueWithDelay 14 // WHEN a min, max, time units are provided 15 // THEN a requeue result is returned with a delay within the specified bounds 16 func TestNewRequeueWithDelay(t *testing.T) { 17 asserts := assert.New(t) 18 requeueWithDelay := NewRequeueWithDelay(3, 5, time.Second) 19 t.Logf("Requeue result: %v", requeueWithDelay) 20 asserts.True(requeueWithDelay.Requeue) 21 asserts.True(ShouldRequeue(requeueWithDelay)) 22 asserts.GreaterOrEqual(requeueWithDelay.RequeueAfter.Seconds(), (time.Duration(3) * time.Second).Seconds()) 23 asserts.LessOrEqual(requeueWithDelay.RequeueAfter.Seconds(), (time.Duration(5) * time.Second).Seconds()) 24 25 requeueWithDelay = NewRequeueWithDelay(3, 5, time.Second) 26 t.Logf("Requeue result: %v", requeueWithDelay) 27 asserts.True(requeueWithDelay.Requeue) 28 asserts.True(ShouldRequeue(requeueWithDelay)) 29 asserts.GreaterOrEqual(requeueWithDelay.RequeueAfter.Seconds(), (time.Duration(3) * time.Second).Seconds()) 30 asserts.LessOrEqual(requeueWithDelay.RequeueAfter.Seconds(), (time.Duration(5) * time.Second).Seconds()) 31 32 requeueWithDelay = NewRequeueWithDelay(3, 5, time.Minute) 33 t.Logf("Requeue result: %v", requeueWithDelay) 34 asserts.True(requeueWithDelay.Requeue) 35 asserts.True(ShouldRequeue(requeueWithDelay)) 36 asserts.GreaterOrEqual(requeueWithDelay.RequeueAfter.Seconds(), (time.Duration(3) * time.Minute).Seconds()) 37 asserts.LessOrEqual(requeueWithDelay.RequeueAfter.Seconds(), (time.Duration(5) * time.Minute).Seconds()) 38 }