From f9648d3976311073909c939ef209d5282f6fc770 Mon Sep 17 00:00:00 2001 From: findmyname666 <35902428+findmyname666@users.noreply.github.com> Date: Mon, 20 Jul 2020 22:12:50 +0200 Subject: [PATCH] add tests lifecycle rules with empty prefix (#10093) --- pkg/bucket/lifecycle/lifecycle_test.go | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/bucket/lifecycle/lifecycle_test.go b/pkg/bucket/lifecycle/lifecycle_test.go index 619912a69..7f7eaa3c0 100644 --- a/pkg/bucket/lifecycle/lifecycle_test.go +++ b/pkg/bucket/lifecycle/lifecycle_test.go @@ -282,6 +282,13 @@ func TestComputeActions(t *testing.T) { objectModTime: time.Now().UTC().Add(-10 * 24 * time.Hour), // Created 10 days ago expectedAction: NoneAction, }, + // Test rule with empty prefix e.g. for whole bucket + { + inputConfig: `Enabled5`, + objectName: "foxdir/fooobject/foo.txt", + objectModTime: time.Now().UTC().Add(-10 * 24 * time.Hour), // Created 10 days ago + expectedAction: DeleteAction, + }, // Too early to remove (test Days) { inputConfig: `foodir/Enabled5`, @@ -359,6 +366,22 @@ func TestComputeActions(t *testing.T) { objectModTime: time.Now().UTC().Add(-24 * time.Hour), // Created 1 day ago expectedAction: NoneAction, }, + // Should remove - empty prefix, tags match, date expiration kicked in + { + inputConfig: `tag1value1Enabled` + time.Now().Truncate(24*time.Hour).UTC().Add(-24*time.Hour).Format(time.RFC3339) + ``, + objectName: "foxdir/fooobject", + objectTags: "tag1=value1", + objectModTime: time.Now().UTC().Add(-24 * time.Hour), // Created 1 day ago + expectedAction: DeleteAction, + }, + // Should remove - empty prefix, tags match, object is expired based on specified Days + { + inputConfig: `tag1value1Enabled1`, + objectName: "foxdir/fooobject", + objectTags: "tag1=value1", + objectModTime: time.Now().UTC().Add(-48 * time.Hour), // Created 2 day ago + expectedAction: DeleteAction, + }, // Should remove, the second rule has expiration kicked in { inputConfig: `Enabled` + time.Now().Truncate(24*time.Hour).UTC().Add(24*time.Hour).Format(time.RFC3339) + `foxdir/Enabled` + time.Now().Truncate(24*time.Hour).UTC().Add(-24*time.Hour).Format(time.RFC3339) + ``, @@ -400,6 +423,11 @@ func TestHasActiveRules(t *testing.T) { prefix: "foodir/foobject", expectedNonRec: true, expectedRec: true, }, + { // empty prefix + inputConfig: `Enabled5`, + prefix: "foodir/foobject/foo.txt", + expectedNonRec: true, expectedRec: true, + }, { inputConfig: `foodir/Enabled5`, prefix: "zdir/foobject",