From fa137aa50b6c907e2baea7a64d8d170d6d0331df Mon Sep 17 00:00:00 2001 From: manish Date: Sun, 13 Oct 2019 19:16:27 +0530 Subject: [PATCH] feat:new helper function for 'archive' storage class --- google/cloud/storage/lifecycle_rule.cc | 4 ++++ google/cloud/storage/lifecycle_rule.h | 5 +++++ google/cloud/storage/lifecycle_rule_test.cc | 10 ++++++++++ google/cloud/storage/storage_class.h | 5 +++++ google/cloud/storage/storage_class_test.cc | 1 + 5 files changed, 25 insertions(+) diff --git a/google/cloud/storage/lifecycle_rule.cc b/google/cloud/storage/lifecycle_rule.cc index 8d5b735d05675..2495284efee52 100644 --- a/google/cloud/storage/lifecycle_rule.cc +++ b/google/cloud/storage/lifecycle_rule.cc @@ -54,6 +54,10 @@ LifecycleRuleAction LifecycleRule::SetStorageClassDurableReducedAvailability() { return SetStorageClass(storage_class::DurableReducedAvailability()); } +LifecycleRuleAction LifecycleRule::SetStorageClassArchive() { + return SetStorageClass(storage_class::Archive()); +} + LifecycleRuleAction LifecycleRule::SetStorageClass(std::string storage_class) { return LifecycleRuleAction{"SetStorageClass", std::move(storage_class)}; } diff --git a/google/cloud/storage/lifecycle_rule.h b/google/cloud/storage/lifecycle_rule.h index afe95a3898390..52c9ae8ca4b11 100644 --- a/google/cloud/storage/lifecycle_rule.h +++ b/google/cloud/storage/lifecycle_rule.h @@ -149,6 +149,7 @@ class LifecycleRule { static LifecycleRuleAction SetStorageClassNearline(); static LifecycleRuleAction SetStorageClassColdline(); static LifecycleRuleAction SetStorageClassDurableReducedAvailability(); + static LifecycleRuleAction SetStorageClassArchive(); static LifecycleRuleAction SetStorageClass(std::string storage_class); //@} @@ -232,6 +233,10 @@ class LifecycleRule { return MatchesStorageClass(storage_class::DurableReducedAvailability()); } + static LifecycleRuleCondition MatchesStorageClassArchive() { + return MatchesStorageClass(storage_class::Archive()); + } + static LifecycleRuleCondition NumNewerVersions(std::int32_t days) { LifecycleRuleCondition result; result.num_newer_versions.emplace(std::move(days)); diff --git a/google/cloud/storage/lifecycle_rule_test.cc b/google/cloud/storage/lifecycle_rule_test.cc index 13afc8bc8362a..90db70e2cab4c 100644 --- a/google/cloud/storage/lifecycle_rule_test.cc +++ b/google/cloud/storage/lifecycle_rule_test.cc @@ -72,6 +72,8 @@ TEST(LifecycleRuleTest, SetStorageClass) { EXPECT_EQ(LifecycleRule::SetStorageClass( storage_class::DurableReducedAvailability()), LifecycleRule::SetStorageClassDurableReducedAvailability()); + EXPECT_EQ(LifecycleRule::SetStorageClass(storage_class::Archive()), + LifecycleRule::SetStorageClassArchive()); } /// @test Verify that LifecycleRuleCondition comparisons work as expected. @@ -230,6 +232,14 @@ TEST(LifecycleRuleTest, MatchesStorageClassDurableReducedAvailability) { condition.matches_storage_class->front()); } +/// @test LifecycleRule::MatchesStorageClassArchive. +TEST(LifecycleRuleTest, MatchesStorageClassArchive) { + auto condition = LifecycleRule::MatchesStorageClassArchive(); + ASSERT_TRUE(condition.matches_storage_class.has_value()); + ASSERT_FALSE(condition.matches_storage_class->empty()); + EXPECT_EQ(storage_class::Archive(), condition.matches_storage_class->front()); +} + /// @test Verify that LifecycleRule::NumNewerVersions() works as expected. TEST(LifecycleRuleTest, NumNewerVersions) { auto condition = LifecycleRule::NumNewerVersions(7); diff --git a/google/cloud/storage/storage_class.h b/google/cloud/storage/storage_class.h index fd57a4141a590..17aea70848e9d 100644 --- a/google/cloud/storage/storage_class.h +++ b/google/cloud/storage/storage_class.h @@ -53,6 +53,11 @@ inline char const* DurableReducedAvailability() { return kStorageClass; } +inline char const* Archive() { + static constexpr char kStorageClass[] = "ARCHIVE"; + return kStorageClass; +} + } // namespace storage_class } // namespace STORAGE_CLIENT_NS } // namespace storage diff --git a/google/cloud/storage/storage_class_test.cc b/google/cloud/storage/storage_class_test.cc index 6512535225a73..4de4d5d7ba0a7 100644 --- a/google/cloud/storage/storage_class_test.cc +++ b/google/cloud/storage/storage_class_test.cc @@ -31,6 +31,7 @@ TEST(StorageClassTest, Values) { EXPECT_EQ(std::string("COLDLINE"), Coldline()); EXPECT_EQ(std::string("DURABLE_REDUCED_AVAILABILITY"), DurableReducedAvailability()); + EXPECT_EQ(std::string("ARCHIVE"), Archive()); } } // namespace