Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:new helper function for 'archive' storage class #3197

Merged
merged 1 commit into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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