Skip to content

Commit

Permalink
feat: new helper function for 'archive' storage class
Browse files Browse the repository at this point in the history
  • Loading branch information
manish-qlogic committed Oct 13, 2019
1 parent 8ab5e51 commit 963098c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions google/cloud/storage/lifecycle_rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)};
}
Expand Down
5 changes: 5 additions & 0 deletions google/cloud/storage/lifecycle_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//@}

Expand Down Expand Up @@ -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));
Expand Down
10 changes: 10 additions & 0 deletions google/cloud/storage/lifecycle_rule_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions google/cloud/storage/storage_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions google/cloud/storage/storage_class_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 963098c

Please sign in to comment.