@@ -87,6 +87,9 @@ func TestPrune(t *testing.T) {
8787 {"2 days" , PruneOptions {Retention : "2d" , Now : now }, filenames , filenames [0 :6 ], nil },
8888 // 3 weeks - file[13] is 504h+30m = 504.5h, so it should be pruned
8989 {"3 weeks" , PruneOptions {Retention : "3w" , Now : now }, filenames , filenames [0 :13 ], nil },
90+ // 2 most recent files
91+ {"2 most recent" , PruneOptions {Retention : "2c" , Now : now }, filenames , filenames [0 :2 ], nil },
92+
9093 // repeat for safe file names
9194 {"1 hour safe names" , PruneOptions {Retention : "1h" , Now : now }, safefilenames , safefilenames [0 :1 ], nil },
9295 // 2 hours - file[2] is 2h+30m = 2.5h, so it should be pruned
@@ -95,6 +98,8 @@ func TestPrune(t *testing.T) {
9598 {"2 days safe names" , PruneOptions {Retention : "2d" , Now : now }, safefilenames , safefilenames [0 :6 ], nil },
9699 // 3 weeks - file[13] is 504h+30m = 504.5h, so it should be pruned
97100 {"3 weeks safe names" , PruneOptions {Retention : "3w" , Now : now }, safefilenames , safefilenames [0 :13 ], nil },
101+ // 2 most recent files
102+ {"2 most recent safe names" , PruneOptions {Retention : "2c" , Now : now }, safefilenames , safefilenames [0 :2 ], nil },
98103 }
99104 for _ , tt := range tests {
100105 t .Run (tt .name , func (t * testing.T ) {
@@ -146,9 +151,10 @@ func TestPrune(t *testing.T) {
146151 for _ , file := range files {
147152 afterFiles = append (afterFiles , file .Name ())
148153 }
149- slices .Sort (afterFiles )
150- slices .Sort (tt .afterFiles )
151- assert .ElementsMatch (t , tt .afterFiles , afterFiles )
154+ afterFilesSorted , ttAfterFilesSorted := slices .Clone (afterFiles ), slices .Clone (tt .afterFiles )
155+ slices .Sort (afterFilesSorted )
156+ slices .Sort (ttAfterFilesSorted )
157+ assert .ElementsMatch (t , ttAfterFilesSorted , afterFilesSorted )
152158 })
153159 }
154160}
0 commit comments