Skip to content

Commit 3345ac9

Browse files
authored
test: add test to verify lifecycle.rule.condition.age_days = 0 (#1846)
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.
1 parent 45dc983 commit 3345ac9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,12 @@ private BucketInfo.LifecycleRule lifecycleRuleDecode(Bucket.Lifecycle.Rule from)
714714
.collect(ImmutableList.toImmutableList());
715715
conditionBuilder.setMatchesStorageClass(collect);
716716
}
717-
conditionBuilder.setMatchesPrefix(condition.getMatchesPrefixList());
718-
conditionBuilder.setMatchesSuffix(condition.getMatchesSuffixList());
717+
if (!condition.getMatchesPrefixList().isEmpty()) {
718+
conditionBuilder.setMatchesPrefix(condition.getMatchesPrefixList());
719+
}
720+
if (!condition.getMatchesSuffixList().isEmpty()) {
721+
conditionBuilder.setMatchesSuffix(condition.getMatchesSuffixList());
722+
}
719723
return new BucketInfo.LifecycleRule(lifecycleAction, conditionBuilder.build());
720724
}
721725

google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBucketLifecycleRulesTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ public void deleteRule_addingALabelToABucketWithASingleDeleteRuleOnlyModifiesThe
7272
}
7373
}
7474

75+
@Test
76+
public void condition_ageDays_0_shouldWork() throws Exception {
77+
LifecycleRule d1 =
78+
new LifecycleRule(
79+
LifecycleAction.newAbortIncompleteMPUploadAction(),
80+
LifecycleCondition.newBuilder().setAge(0).build());
81+
BucketInfo info = baseInfo().setLifecycleRules(ImmutableList.of(d1)).build();
82+
83+
try (TemporaryBucket tmp =
84+
TemporaryBucket.newBuilder().setBucketInfo(info).setStorage(storage).build()) {
85+
BucketInfo bucket = tmp.getBucket();
86+
Bucket update = storage.get(bucket.getName());
87+
assertThat(update.getLifecycleRules()).isEqualTo(ImmutableList.of(d1));
88+
}
89+
}
90+
7591
@Test
7692
public void deleteRule_modifyingLifecycleRulesMatchesLastOperation() throws Exception {
7793
BucketInfo info;

0 commit comments

Comments
 (0)