From ddf01ab5c2f3c65dc05da4cfabc0c539784d0be9 Mon Sep 17 00:00:00 2001 From: sundarrajanraman <106651904+sundarrajanraman@users.noreply.github.com> Date: Fri, 21 Oct 2022 01:55:24 +0530 Subject: [PATCH] test: add tests to cover the MatchesPrefix and MatchesSuffix in LifeCyleRules (#1724) --- .../google/cloud/storage/BucketInfoTest.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java index e05d9747c..6a2ca2316 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java @@ -328,12 +328,31 @@ public void testLifecycleRules() { Rule deleteLifecycleRule = new LifecycleRule( LifecycleAction.newDeleteAction(), - LifecycleCondition.newBuilder().setAge(10).build()) + LifecycleCondition.newBuilder() + .setAge(10) + .setMatchesPrefix(Arrays.asList("abc", "ijk")) + .setMatchesSuffix(Arrays.asList("xyz")) + .build()) .toPb(); assertEquals( LifecycleRule.DeleteLifecycleAction.TYPE, deleteLifecycleRule.getAction().getType()); assertEquals(10, deleteLifecycleRule.getCondition().getAge().intValue()); + assertEquals(2, deleteLifecycleRule.getCondition().getMatchesPrefix().size()); + assertEquals("abc", (String) deleteLifecycleRule.getCondition().getMatchesPrefix().get(0)); + assertEquals("ijk", (String) deleteLifecycleRule.getCondition().getMatchesPrefix().get(1)); + assertEquals(1, deleteLifecycleRule.getCondition().getMatchesSuffix().size()); + assertEquals("xyz", deleteLifecycleRule.getCondition().getMatchesSuffix().get(0)); + + LifecycleRule lcr = LifecycleRule.fromPb(deleteLifecycleRule); + assertEquals(LifecycleRule.DeleteLifecycleAction.TYPE, lcr.getAction().getActionType()); + assertEquals(10, lcr.getCondition().getAge().intValue()); + assertEquals(2, lcr.getCondition().getMatchesPrefix().size()); + assertEquals("abc", (String) lcr.getCondition().getMatchesPrefix().get(0)); + assertEquals("ijk", (String) lcr.getCondition().getMatchesPrefix().get(1)); + assertEquals(1, lcr.getCondition().getMatchesSuffix().size()); + assertEquals("xyz", lcr.getCondition().getMatchesSuffix().get(0)); + assertTrue( LifecycleRule.fromPb(deleteLifecycleRule).getAction() instanceof DeleteLifecycleAction);