@@ -1118,22 +1118,26 @@ func TestShouldEvaluatePolicy(t *testing.T) {
11181118
11191119 // Add a 60 second buffer to avoid race conditions
11201120 inFuture := time .Now ().UTC ().Add (60 * time .Second ).Format (time .RFC3339 )
1121+ futureResourceVersion := "900000" // 900_000
11211122 lastEvaluatedInFuture := & sync.Map {}
1122- lastEvaluatedInFuture .Store (policy .UID , inFuture )
1123+ lastEvaluatedInFuture .Store (policy .UID , futureResourceVersion )
11231124
11241125 lastEvaluatedInvalid := & sync.Map {}
11251126 lastEvaluatedInvalid .Store (policy .UID , "Do or do not. There is no try." )
11261127
11271128 twelveSecsAgo := time .Now ().UTC ().Add (- 12 * time .Second ).Format (time .RFC3339 )
1129+ recentResourceVersion := "700000" // 700_000
11281130 lastEvaluatedTwelveSecsAgo := & sync.Map {}
1129- lastEvaluatedTwelveSecsAgo .Store (policy .UID , twelveSecsAgo )
1131+ lastEvaluatedTwelveSecsAgo .Store (policy .UID , recentResourceVersion )
11301132
11311133 twelveHoursAgo := time .Now ().UTC ().Add (- 12 * time .Hour ).Format (time .RFC3339 )
1134+ oldResourceVersion := "20000" // 20_000
11321135 lastEvaluatedTwelveHoursAgo := & sync.Map {}
1133- lastEvaluatedTwelveHoursAgo .Store (policy .UID , twelveHoursAgo )
1136+ lastEvaluatedTwelveHoursAgo .Store (policy .UID , oldResourceVersion )
11341137
11351138 tests := []struct {
11361139 testDescription string
1140+ resourceVersion string
11371141 lastEvaluated string
11381142 lastEvaluatedGeneration int64
11391143 evaluationInterval policyv1.EvaluationInterval
@@ -1147,6 +1151,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
11471151 }{
11481152 {
11491153 "Just evaluated and the generation is unchanged" ,
1154+ futureResourceVersion ,
11501155 inFuture ,
11511156 2 ,
11521157 policyv1.EvaluationInterval {Compliant : "10s" , NonCompliant : "10s" },
@@ -1160,6 +1165,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
11601165 },
11611166 {
11621167 "The generation has changed" ,
1168+ futureResourceVersion ,
11631169 inFuture ,
11641170 1 ,
11651171 policyv1.EvaluationInterval {Compliant : "10s" , NonCompliant : "10s" },
@@ -1173,6 +1179,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
11731179 },
11741180 {
11751181 "lastEvaluated not set" ,
1182+ futureResourceVersion ,
11761183 "" ,
11771184 2 ,
11781185 policyv1.EvaluationInterval {Compliant : "10s" , NonCompliant : "10s" },
@@ -1186,6 +1193,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
11861193 },
11871194 {
11881195 "Invalid lastEvaluated" ,
1196+ futureResourceVersion ,
11891197 "Do or do not. There is no try." ,
11901198 2 ,
11911199 policyv1.EvaluationInterval {Compliant : "10s" , NonCompliant : "10s" },
@@ -1199,6 +1207,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
11991207 },
12001208 {
12011209 "Unknown compliance state" ,
1210+ futureResourceVersion ,
12021211 inFuture ,
12031212 2 ,
12041213 policyv1.EvaluationInterval {Compliant : "10s" , NonCompliant : "10s" },
@@ -1212,6 +1221,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
12121221 },
12131222 {
12141223 "Default evaluation interval with a past lastEvaluated when compliant" ,
1224+ futureResourceVersion ,
12151225 twelveSecsAgo ,
12161226 2 ,
12171227 policyv1.EvaluationInterval {Compliant : "10s" , NonCompliant : "10s" },
@@ -1225,6 +1235,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
12251235 },
12261236 {
12271237 "Default evaluation interval with a past lastEvaluated when noncompliant" ,
1238+ futureResourceVersion ,
12281239 twelveSecsAgo ,
12291240 2 ,
12301241 policyv1.EvaluationInterval {Compliant : "10s" , NonCompliant : "10s" },
@@ -1238,6 +1249,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
12381249 },
12391250 {
12401251 "Never evaluation interval with past lastEvaluated when compliant" ,
1252+ futureResourceVersion ,
12411253 twelveHoursAgo ,
12421254 2 ,
12431255 policyv1.EvaluationInterval {Compliant : "never" },
@@ -1251,6 +1263,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
12511263 },
12521264 {
12531265 "Never evaluation interval with past lastEvaluated when noncompliant" ,
1266+ futureResourceVersion ,
12541267 twelveHoursAgo ,
12551268 2 ,
12561269 policyv1.EvaluationInterval {Compliant : "10s" , NonCompliant : "never" },
@@ -1264,6 +1277,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
12641277 },
12651278 {
12661279 "Unset evaluation interval with past lastEvaluated when compliant" ,
1280+ futureResourceVersion ,
12671281 twelveHoursAgo ,
12681282 2 ,
12691283 policyv1.EvaluationInterval {},
@@ -1277,6 +1291,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
12771291 },
12781292 {
12791293 "Watch evaluation interval with past lastEvaluated when compliant" ,
1294+ futureResourceVersion ,
12801295 twelveHoursAgo ,
12811296 2 ,
12821297 policyv1.EvaluationInterval {Compliant : "watch" , NonCompliant : "watch" },
@@ -1290,6 +1305,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
12901305 },
12911306 {
12921307 "Unset evaluation interval with past lastEvaluated when noncompliant" ,
1308+ futureResourceVersion ,
12931309 twelveHoursAgo ,
12941310 2 ,
12951311 policyv1.EvaluationInterval {},
@@ -1303,6 +1319,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
13031319 },
13041320 {
13051321 "Watch evaluation interval with past lastEvaluated when noncompliant" ,
1322+ futureResourceVersion ,
13061323 twelveHoursAgo ,
13071324 2 ,
13081325 policyv1.EvaluationInterval {NonCompliant : "watch" },
@@ -1316,6 +1333,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
13161333 },
13171334 {
13181335 "Invalid evaluation interval when compliant" ,
1336+ futureResourceVersion ,
13191337 inFuture ,
13201338 2 ,
13211339 policyv1.EvaluationInterval {Compliant : "Do or do not. There is no try." },
@@ -1329,6 +1347,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
13291347 },
13301348 {
13311349 "Invalid evaluation interval when noncompliant" ,
1350+ futureResourceVersion ,
13321351 inFuture ,
13331352 2 ,
13341353 policyv1.EvaluationInterval {NonCompliant : "Do or do not. There is no try." },
@@ -1342,6 +1361,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
13421361 },
13431362 {
13441363 "Custom evaluation interval that hasn't past yet when compliant" ,
1364+ futureResourceVersion ,
13451365 twelveSecsAgo ,
13461366 2 ,
13471367 policyv1.EvaluationInterval {Compliant : "12h" },
@@ -1355,6 +1375,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
13551375 },
13561376 {
13571377 "Custom evaluation interval that hasn't past yet when noncompliant" ,
1378+ futureResourceVersion ,
13581379 twelveSecsAgo ,
13591380 2 ,
13601381 policyv1.EvaluationInterval {NonCompliant : "12h" },
@@ -1368,6 +1389,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
13681389 },
13691390 {
13701391 "Deletion timestamp is non nil" ,
1392+ futureResourceVersion ,
13711393 inFuture ,
13721394 2 ,
13731395 policyv1.EvaluationInterval {NonCompliant : "12h" },
@@ -1381,6 +1403,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
13811403 },
13821404 {
13831405 "Finalizer and the controller is being deleted" ,
1406+ futureResourceVersion ,
13841407 inFuture ,
13851408 2 ,
13861409 policyv1.EvaluationInterval {NonCompliant : "12h" },
@@ -1394,6 +1417,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
13941417 },
13951418 {
13961419 "No finalizer and the controller is being deleted" ,
1420+ futureResourceVersion ,
13971421 inFuture ,
13981422 2 ,
13991423 policyv1.EvaluationInterval {NonCompliant : "12h" },
@@ -1407,6 +1431,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
14071431 },
14081432 {
14091433 "controller-runtime cache not yet synced" ,
1434+ recentResourceVersion ,
14101435 twelveHoursAgo ,
14111436 2 ,
14121437 policyv1.EvaluationInterval {NonCompliant : "12h" },
@@ -1416,7 +1441,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
14161441 nil ,
14171442 false ,
14181443 []string {},
1419- lastEvaluatedTwelveSecsAgo ,
1444+ lastEvaluatedInFuture ,
14201445 },
14211446 }
14221447
@@ -1429,6 +1454,7 @@ func TestShouldEvaluatePolicy(t *testing.T) {
14291454 policyCopy := policy .DeepCopy ()
14301455
14311456 policyCopy .Status .LastEvaluated = test .lastEvaluated
1457+ policyCopy .SetResourceVersion (test .resourceVersion )
14321458 policyCopy .Status .LastEvaluatedGeneration = test .lastEvaluatedGeneration
14331459 policyCopy .Spec .EvaluationInterval = test .evaluationInterval
14341460 policyCopy .Status .ComplianceState = test .complianceState
0 commit comments