From 5115dbee40cd995bfc15b0b586b5cd18d6733970 Mon Sep 17 00:00:00 2001 From: BenWhitehead Date: Wed, 11 Jan 2023 18:13:49 -0500 Subject: [PATCH] test: add test to verify `lifecycle.rule.condition.age_days = 0` Zero (0) is a special value for some serialization configurations. Add a test to ensure it is properly passed to the backend, and is effective. --- .../google/cloud/storage/GrpcConversions.java | 8 ++++++-- .../storage/it/ITBucketLifecycleRulesTest.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java index 7e5e8c7e32..f2923a064f 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java @@ -714,8 +714,12 @@ private BucketInfo.LifecycleRule lifecycleRuleDecode(Bucket.Lifecycle.Rule from) .collect(ImmutableList.toImmutableList()); conditionBuilder.setMatchesStorageClass(collect); } - conditionBuilder.setMatchesPrefix(condition.getMatchesPrefixList()); - conditionBuilder.setMatchesSuffix(condition.getMatchesSuffixList()); + if (!condition.getMatchesPrefixList().isEmpty()) { + conditionBuilder.setMatchesPrefix(condition.getMatchesPrefixList()); + } + if (!condition.getMatchesSuffixList().isEmpty()) { + conditionBuilder.setMatchesSuffix(condition.getMatchesSuffixList()); + } return new BucketInfo.LifecycleRule(lifecycleAction, conditionBuilder.build()); } diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBucketLifecycleRulesTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBucketLifecycleRulesTest.java index 6e7eeadf56..d7f14d8282 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBucketLifecycleRulesTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBucketLifecycleRulesTest.java @@ -72,6 +72,22 @@ public void deleteRule_addingALabelToABucketWithASingleDeleteRuleOnlyModifiesThe } } + @Test + public void condition_ageDays_0_shouldWork() throws Exception { + LifecycleRule d1 = + new LifecycleRule( + LifecycleAction.newAbortIncompleteMPUploadAction(), + LifecycleCondition.newBuilder().setAge(0).build()); + BucketInfo info = baseInfo().setLifecycleRules(ImmutableList.of(d1)).build(); + + try (TemporaryBucket tmp = + TemporaryBucket.newBuilder().setBucketInfo(info).setStorage(storage).build()) { + BucketInfo bucket = tmp.getBucket(); + Bucket update = storage.get(bucket.getName()); + assertThat(update.getLifecycleRules()).isEqualTo(ImmutableList.of(d1)); + } + } + @Test public void deleteRule_modifyingLifecycleRulesMatchesLastOperation() throws Exception { BucketInfo info;