@@ -119,8 +119,26 @@ func TestScheduledGate_Check_errors(t *testing.T) {
119119}
120120
121121func TestScheduledGate_Interval (t * testing.T ) {
122- // 9am on the 14th May 2023
123- now := time .Date (2023 , time .May , 14 , 9 , 0 , 0 , 0 , time .UTC )
122+ intervalTests := []struct {
123+ now time.Time
124+ want time.Duration
125+ }{
126+ {
127+ // 09:00 on the 14th May 2023
128+ now : time .Date (2023 , time .May , 14 , 9 , 0 , 0 , 0 , time .UTC ),
129+ want : time .Hour * 8 ,
130+ },
131+ {
132+ // 18:00 on the 14th May 2023
133+ now : time .Date (2023 , time .May , 14 , 18 , 0 , 0 , 0 , time .UTC ),
134+ want : time .Hour * 1 ,
135+ },
136+ {
137+ // 20:00 on the 14th May 2023
138+ now : time .Date (2023 , time .May , 14 , 20 , 0 , 0 , 0 , time .UTC ),
139+ want : time .Hour * 21 , // 20:00 -> 00:00 + 17:00 = 21h
140+ },
141+ }
124142
125143 gate := & deployerv1.KustomizationGate {
126144 Name : "testing" ,
@@ -130,13 +148,22 @@ func TestScheduledGate_Interval(t *testing.T) {
130148 },
131149 }
132150
133- gen := New (logr .Discard (), func (s * ScheduledGate ) {
134- s .Clock = func () time.Time {
135- return now
136- }
137- })
151+ for _ , tt := range intervalTests {
152+ t .Run (fmt .Sprintf ("%v" , tt .now ), func (t * testing.T ) {
153+ gen := New (logr .Discard (), func (s * ScheduledGate ) {
154+ s .Clock = func () time.Time {
155+ return tt .now
156+ }
157+ })
158+
159+ i , err := gen .Interval (gate )
160+ if err != nil {
161+ t .Fatal (err )
162+ }
138163
139- if i := gen .Interval (gate ); i != time .Minute * 5 {
140- t .Fatalf ("Interval() got %v, want %v" , i , time .Minute * 5 )
164+ if i != tt .want {
165+ t .Fatalf ("Interval() got %v, want %v" , i , tt .want )
166+ }
167+ })
141168 }
142169}
0 commit comments