Skip to content

Commit 4eb8370

Browse files
test: use relative timestamps for purge age filtering (#741)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7867b1ae-ffba-4907-9579-d236b8ec2c01
1 parent 012526f commit 4eb8370

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎cmd/acr/purge_untagged_only_test.go‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,9 @@ func TestPurgeDanglingManifestsWithAgoAndKeep(t *testing.T) {
560560
assert := assert.New(t)
561561
mockClient := &mocks.AcrCLIClientInterface{}
562562

563-
// Create manifests with different timestamps
564-
// old manifest: more than 300 days ago from now (2026), recent: less than 300 days
565-
oldManifest := createManifestWithTime("sha256:old123", "2025-01-01T00:00:00Z")
566-
recentManifest := createManifestWithTime("sha256:recent123", "2026-01-15T00:00:00Z")
563+
now := time.Now().UTC()
564+
oldManifest := createManifestWithTime("sha256:old123", now.Add(-400*24*time.Hour).Format(time.RFC3339Nano))
565+
recentManifest := createManifestWithTime("sha256:recent123", now.Add(-100*24*time.Hour).Format(time.RFC3339Nano))
567566

568567
manifestsResult := &acr.Manifests{
569568
Response: autorest.Response{
@@ -586,7 +585,7 @@ func TestPurgeDanglingManifestsWithAgoAndKeep(t *testing.T) {
586585
mockClient.On("GetAcrManifests", mock.Anything, testRepo, "", "sha256:recent123").Return(emptyResult, nil).Once()
587586
mockClient.On("DeleteManifest", mock.Anything, testRepo, "sha256:old123").Return(nil, nil).Once()
588587

589-
// Call with 300 days ago (should only delete the old manifest from 2023)
588+
// Call with 300 days ago (should only delete the old manifest)
590589
agoDuration := mustParseDuration("300d")
591590
opts := retentionOptions{agoDuration: &agoDuration, keep: 0, minTags: -1, maxTags: -1, minManifests: -1, maxManifests: -1, dryRun: false, includeLocked: false}
592591
deletedCount, err := purgeDanglingManifests(testCtx, mockClient, defaultPoolSize, testLoginURL, testRepo, opts, nil, false)
@@ -694,9 +693,9 @@ func TestPurgeDanglingManifestsWithAgoAndKeep(t *testing.T) {
694693
assert := assert.New(t)
695694
mockClient := &mocks.AcrCLIClientInterface{}
696695

697-
// old manifest: more than 300 days ago, recent: less than 300 days
698-
oldManifest := createManifestWithTime("sha256:old123", "2025-01-01T00:00:00Z")
699-
recentManifest := createManifestWithTime("sha256:recent123", "2026-01-15T00:00:00Z")
696+
now := time.Now().UTC()
697+
oldManifest := createManifestWithTime("sha256:old123", now.Add(-400*24*time.Hour).Format(time.RFC3339Nano))
698+
recentManifest := createManifestWithTime("sha256:recent123", now.Add(-100*24*time.Hour).Format(time.RFC3339Nano))
700699

701700
manifestsResult := &acr.Manifests{
702701
Response: autorest.Response{

0 commit comments

Comments
 (0)