@@ -3,6 +3,7 @@ package api
3
3
import (
4
4
"reflect"
5
5
"testing"
6
+ "time"
6
7
7
8
"github.com/hashicorp/nomad/helper"
8
9
"github.com/stretchr/testify/assert"
@@ -266,3 +267,51 @@ func TestTaskGroup_Canonicalize_Update(t *testing.T) {
266
267
tg .Canonicalize (job )
267
268
assert .Nil (t , tg .Update )
268
269
}
270
+
271
+ // TestService_CheckRestart asserts Service.CheckRestart settings are properly
272
+ // inherited by Checks.
273
+ func TestService_CheckRestart (t * testing.T ) {
274
+ job := & Job {Name : helper .StringToPtr ("job" )}
275
+ tg := & TaskGroup {Name : helper .StringToPtr ("group" )}
276
+ task := & Task {Name : "task" }
277
+ service := & Service {
278
+ CheckRestart : & CheckRestart {
279
+ Limit : 11 ,
280
+ Grace : helper .TimeToPtr (11 * time .Second ),
281
+ IgnoreWarnings : true ,
282
+ },
283
+ Checks : []ServiceCheck {
284
+ {
285
+ Name : "all-set" ,
286
+ CheckRestart : & CheckRestart {
287
+ Limit : 22 ,
288
+ Grace : helper .TimeToPtr (22 * time .Second ),
289
+ IgnoreWarnings : true ,
290
+ },
291
+ },
292
+ {
293
+ Name : "some-set" ,
294
+ CheckRestart : & CheckRestart {
295
+ Limit : 33 ,
296
+ Grace : helper .TimeToPtr (33 * time .Second ),
297
+ },
298
+ },
299
+ {
300
+ Name : "unset" ,
301
+ },
302
+ },
303
+ }
304
+
305
+ service .Canonicalize (task , tg , job )
306
+ assert .Equal (t , service .Checks [0 ].CheckRestart .Limit , 22 )
307
+ assert .Equal (t , * service .Checks [0 ].CheckRestart .Grace , 22 * time .Second )
308
+ assert .True (t , service .Checks [0 ].CheckRestart .IgnoreWarnings )
309
+
310
+ assert .Equal (t , service .Checks [1 ].CheckRestart .Limit , 33 )
311
+ assert .Equal (t , * service .Checks [1 ].CheckRestart .Grace , 33 * time .Second )
312
+ assert .True (t , service .Checks [1 ].CheckRestart .IgnoreWarnings )
313
+
314
+ assert .Equal (t , service .Checks [2 ].CheckRestart .Limit , 11 )
315
+ assert .Equal (t , * service .Checks [2 ].CheckRestart .Grace , 11 * time .Second )
316
+ assert .True (t , service .Checks [2 ].CheckRestart .IgnoreWarnings )
317
+ }
0 commit comments