@@ -273,6 +273,28 @@ func TestLifecycleJSONRoundtrip(t *testing.T) {
273
273
ID : "rule-7" ,
274
274
Status : "Enabled" ,
275
275
},
276
+ {
277
+ AllVersionsExpiration : AllVersionsExpiration {
278
+ Days : 10 ,
279
+ },
280
+ ID : "rule-8" ,
281
+ Status : "Enabled" ,
282
+ },
283
+ {
284
+ AllVersionsExpiration : AllVersionsExpiration {
285
+ Days : 0 ,
286
+ },
287
+ ID : "rule-9" ,
288
+ Status : "Enabled" ,
289
+ },
290
+ {
291
+ AllVersionsExpiration : AllVersionsExpiration {
292
+ Days : 7 ,
293
+ DeleteMarker : ExpireDeleteMarker (true ),
294
+ },
295
+ ID : "rule-10" ,
296
+ Status : "Enabled" ,
297
+ },
276
298
},
277
299
}
278
300
@@ -291,6 +313,10 @@ func TestLifecycleJSONRoundtrip(t *testing.T) {
291
313
t .Fatalf ("expected %#v got %#v" , lc .Rules [i ].NoncurrentVersionTransition , got .Rules [i ].NoncurrentVersionTransition )
292
314
}
293
315
316
+ if ! lc .Rules [i ].NoncurrentVersionExpiration .equals (got .Rules [i ].NoncurrentVersionExpiration ) {
317
+ t .Fatalf ("expected %#v got %#v" , lc .Rules [i ].NoncurrentVersionExpiration , got .Rules [i ].NoncurrentVersionExpiration )
318
+ }
319
+
294
320
if ! lc .Rules [i ].Transition .equals (got .Rules [i ].Transition ) {
295
321
t .Fatalf ("expected %#v got %#v" , lc .Rules [i ].Transition , got .Rules [i ].Transition )
296
322
}
@@ -300,6 +326,9 @@ func TestLifecycleJSONRoundtrip(t *testing.T) {
300
326
if ! lc .Rules [i ].DelMarkerExpiration .equals (got .Rules [i ].DelMarkerExpiration ) {
301
327
t .Fatalf ("expected %#v got %#v" , lc .Rules [i ].DelMarkerExpiration , got .Rules [i ].DelMarkerExpiration )
302
328
}
329
+ if ! lc .Rules [i ].AllVersionsExpiration .equals (got .Rules [i ].AllVersionsExpiration ) {
330
+ t .Fatalf ("expected %#v got %#v" , lc .Rules [i ].AllVersionsExpiration , got .Rules [i ].AllVersionsExpiration )
331
+ }
303
332
}
304
333
}
305
334
@@ -352,6 +381,27 @@ func TestLifecycleXMLRoundtrip(t *testing.T) {
352
381
Days : 5 ,
353
382
},
354
383
},
384
+ {
385
+ ID : "all-versions-expiration-1" ,
386
+ Status : "Enabled" ,
387
+ AllVersionsExpiration : AllVersionsExpiration {
388
+ Days : 5 ,
389
+ },
390
+ },
391
+ {
392
+ ID : "all-versions-expiration-2" ,
393
+ Status : "Enabled" ,
394
+ AllVersionsExpiration : AllVersionsExpiration {
395
+ Days : 10 ,
396
+ DeleteMarker : ExpireDeleteMarker (true ),
397
+ },
398
+ RuleFilter : Filter {
399
+ Tag : Tag {
400
+ Key : "key-1" ,
401
+ Value : "value-1" ,
402
+ },
403
+ },
404
+ },
355
405
},
356
406
}
357
407
@@ -374,13 +424,29 @@ func TestLifecycleXMLRoundtrip(t *testing.T) {
374
424
if ! lc .Rules [i ].Transition .equals (got .Rules [i ].Transition ) {
375
425
t .Fatalf ("%d: expected %#v got %#v" , i + 1 , lc .Rules [i ].Transition , got .Rules [i ].Transition )
376
426
}
427
+
428
+ if ! lc .Rules [i ].NoncurrentVersionExpiration .equals (got .Rules [i ].NoncurrentVersionExpiration ) {
429
+ t .Fatalf ("%d: expected %#v got %#v" , i + 1 , lc .Rules [i ].NoncurrentVersionExpiration , got .Rules [i ].NoncurrentVersionExpiration )
430
+ }
431
+
432
+ if ! lc .Rules [i ].DelMarkerExpiration .equals (got .Rules [i ].DelMarkerExpiration ) {
433
+ t .Fatalf ("%d: expected %#v got %#v" , i + 1 , lc .Rules [i ].DelMarkerExpiration , got .Rules [i ].DelMarkerExpiration )
434
+ }
435
+
436
+ if ! lc .Rules [i ].AllVersionsExpiration .equals (got .Rules [i ].AllVersionsExpiration ) {
437
+ t .Fatalf ("%d: expected %#v got %#v" , i + 1 , lc .Rules [i ].AllVersionsExpiration , got .Rules [i ].AllVersionsExpiration )
438
+ }
377
439
}
378
440
}
379
441
380
442
func (n NoncurrentVersionTransition ) equals (m NoncurrentVersionTransition ) bool {
381
443
return n .NoncurrentDays == m .NoncurrentDays && n .StorageClass == m .StorageClass
382
444
}
383
445
446
+ func (n NoncurrentVersionExpiration ) equals (m NoncurrentVersionExpiration ) bool {
447
+ return n .NoncurrentDays == m .NoncurrentDays && n .NewerNoncurrentVersions == m .NewerNoncurrentVersions
448
+ }
449
+
384
450
func (t Transition ) equals (u Transition ) bool {
385
451
return t .Days == u .Days && t .Date .Equal (u .Date .Time ) && t .StorageClass == u .StorageClass
386
452
}
@@ -389,6 +455,10 @@ func (a DelMarkerExpiration) equals(b DelMarkerExpiration) bool {
389
455
return a .Days == b .Days
390
456
}
391
457
458
+ func (a AllVersionsExpiration ) equals (b AllVersionsExpiration ) bool {
459
+ return a .Days == b .Days && a .DeleteMarker == b .DeleteMarker
460
+ }
461
+
392
462
func TestExpiredObjectDeleteMarker (t * testing.T ) {
393
463
expected := []byte (`{"Rules":[{"Expiration":{"ExpiredObjectDeleteMarker":true},"ID":"expired-object-delete-marker","Status":"Enabled"}]}` )
394
464
lc := Configuration {
@@ -411,3 +481,27 @@ func TestExpiredObjectDeleteMarker(t *testing.T) {
411
481
t .Fatalf ("Expected %s but got %s" , expected , got )
412
482
}
413
483
}
484
+
485
+ func TestAllVersionsExpiration (t * testing.T ) {
486
+ expected := []byte (`{"Rules":[{"AllVersionsExpiration":{"Days":2,"DeleteMarker":true},"ID":"all-versions-expiration","Status":"Enabled"}]}` )
487
+ lc := Configuration {
488
+ Rules : []Rule {
489
+ {
490
+ AllVersionsExpiration : AllVersionsExpiration {
491
+ Days : 2 ,
492
+ DeleteMarker : ExpireDeleteMarker (true ),
493
+ },
494
+ ID : "all-versions-expiration" ,
495
+ Status : "Enabled" ,
496
+ },
497
+ },
498
+ }
499
+
500
+ got , err := json .Marshal (lc )
501
+ if err != nil {
502
+ t .Fatalf ("Failed to marshal due to %v" , err )
503
+ }
504
+ if ! bytes .Equal (expected , got ) {
505
+ t .Fatalf ("Expected %s but got %s" , expected , got )
506
+ }
507
+ }
0 commit comments