@@ -30,7 +30,11 @@ LifecycleRule CreateLifecycleRuleForTest() {
3030 "createdBefore": "2018-07-23",
3131 "isLive": true,
3232 "matchesStorageClass": [ "STANDARD" ],
33- "numNewerVersions": 7
33+ "numNewerVersions": 7,
34+ "daysSinceNoncurrentTime": 3,
35+ "noncurrentTimeBefore": "2020-07-22",
36+ "daysSinceCustomTime": 30,
37+ "customTimeBefore": "2020-07-23"
3438 },
3539 "action": {
3640 "type": "SetStorageClass",
@@ -239,6 +243,66 @@ TEST(LifecycleRuleTest, NumNewerVersions) {
239243 EXPECT_EQ (7 , condition.num_newer_versions .value ());
240244}
241245
246+ // / @test Verify that LifecycleRule::DaysSinceNoncurrent() works as expected.
247+ TEST (LifecycleRuleTest, DaysSinceNoncurrentTime) {
248+ auto const c1 = LifecycleRule::DaysSinceNoncurrentTime (3 );
249+ ASSERT_TRUE (c1.days_since_noncurrent_time .has_value ());
250+ EXPECT_EQ (3 , c1.days_since_noncurrent_time .value ());
251+ EXPECT_EQ (c1, c1);
252+ auto const c2 = LifecycleRule::DaysSinceNoncurrentTime (4 );
253+ EXPECT_NE (c1, c2);
254+ EXPECT_LT (c1, c2);
255+ auto const empty = LifecycleRuleCondition{};
256+ EXPECT_NE (c1, empty);
257+ }
258+
259+ // / @test Verify that LifecycleRule::NoncurrentTimeBefore() works as expected.
260+ TEST (LifecycleRuleTest, NoncurrentTimeBefore) {
261+ auto const c1 =
262+ LifecycleRule::NoncurrentTimeBefore (absl::CivilDay (2020 , 7 , 22 ));
263+ ASSERT_TRUE (c1.noncurrent_time_before .has_value ());
264+ EXPECT_EQ (c1, c1);
265+ auto const c2 =
266+ LifecycleRule::NoncurrentTimeBefore (absl::CivilDay (2020 , 7 , 23 ));
267+ ASSERT_TRUE (c2.noncurrent_time_before .has_value ());
268+ EXPECT_EQ (c2, c2);
269+
270+ EXPECT_NE (c1, c2);
271+ EXPECT_LT (c1, c2);
272+
273+ auto const empty = LifecycleRuleCondition{};
274+ EXPECT_NE (c1, empty);
275+ }
276+
277+ // / @test Verify that LifecycleRule::DaysSinceCustomTime() works as expected.
278+ TEST (LifecycleRuleTest, DaysSinceCustomTime) {
279+ auto const c1 = LifecycleRule::DaysSinceCustomTime (3 );
280+ ASSERT_TRUE (c1.days_since_custom_time .has_value ());
281+ EXPECT_EQ (3 , c1.days_since_custom_time .value ());
282+ EXPECT_EQ (c1, c1);
283+ auto const c2 = LifecycleRule::DaysSinceCustomTime (4 );
284+ EXPECT_NE (c1, c2);
285+ EXPECT_LT (c1, c2);
286+ auto const empty = LifecycleRuleCondition{};
287+ EXPECT_NE (c1, empty);
288+ }
289+
290+ // / @test Verify that LifecycleRule::NoncurrentTimeBefore() works as expected.
291+ TEST (LifecycleRuleTest, CustomTimeBefore) {
292+ auto const c1 = LifecycleRule::CustomTimeBefore (absl::CivilDay (2020 , 7 , 23 ));
293+ ASSERT_TRUE (c1.custom_time_before .has_value ());
294+ EXPECT_EQ (c1, c1);
295+ auto const c2 = LifecycleRule::CustomTimeBefore (absl::CivilDay (2020 , 7 , 24 ));
296+ ASSERT_TRUE (c2.custom_time_before .has_value ());
297+ EXPECT_EQ (c2, c2);
298+
299+ EXPECT_NE (c1, c2);
300+ EXPECT_LT (c1, c2);
301+
302+ auto const empty = LifecycleRuleCondition{};
303+ EXPECT_NE (c1, empty);
304+ }
305+
242306// / @test Verify that LifecycleRule::ConditionConjunction() works as expected.
243307TEST (LifecycleRuleTest, ConditionConjunctionAge) {
244308 auto c1 = LifecycleRule::MaxAge (7 );
@@ -317,6 +381,44 @@ TEST(LifecycleRuleTest, ConditionConjunctionNumNewerVersions) {
317381 EXPECT_EQ (42 , *condition.num_newer_versions );
318382}
319383
384+ // / @test Verify that LifecycleRule::ConditionConjunction() works as expected.
385+ TEST (LifecycleRuleTest, ConditionConjunctionDaysSinceNoncurrentTime) {
386+ auto const c1 = LifecycleRule::DaysSinceNoncurrentTime (7 );
387+ auto const c2 = LifecycleRule::DaysSinceNoncurrentTime (42 );
388+ auto const condition = LifecycleRule::ConditionConjunction (c1, c2);
389+ ASSERT_TRUE (condition.days_since_noncurrent_time .has_value ());
390+ EXPECT_EQ (42 , *condition.days_since_noncurrent_time );
391+ }
392+
393+ // / @test Verify that LifecycleRule::ConditionConjunction() works as expected.
394+ TEST (LifecycleRuleTest, ConditionConjunctionNoncurrentTimeBefore) {
395+ auto const c1 =
396+ LifecycleRule::NoncurrentTimeBefore (absl::CivilDay (2020 , 7 , 22 ));
397+ auto const c2 =
398+ LifecycleRule::NoncurrentTimeBefore (absl::CivilDay (2020 , 7 , 23 ));
399+ auto const condition = LifecycleRule::ConditionConjunction (c1, c2);
400+ ASSERT_TRUE (condition.noncurrent_time_before .has_value ());
401+ EXPECT_EQ (absl::CivilDay (2020 , 7 , 22 ), *condition.noncurrent_time_before );
402+ }
403+
404+ // / @test Verify that LifecycleRule::ConditionConjunction() works as expected.
405+ TEST (LifecycleRuleTest, ConditionConjunctionDaysSinceCustomTime) {
406+ auto const c1 = LifecycleRule::DaysSinceCustomTime (7 );
407+ auto const c2 = LifecycleRule::DaysSinceCustomTime (42 );
408+ auto const condition = LifecycleRule::ConditionConjunction (c1, c2);
409+ ASSERT_TRUE (condition.days_since_custom_time .has_value ());
410+ EXPECT_EQ (42 , *condition.days_since_custom_time );
411+ }
412+
413+ // / @test Verify that LifecycleRule::ConditionConjunction() works as expected.
414+ TEST (LifecycleRuleTest, ConditionConjunctionCustomTimeBefore) {
415+ auto const c1 = LifecycleRule::CustomTimeBefore (absl::CivilDay (2020 , 7 , 23 ));
416+ auto const c2 = LifecycleRule::CustomTimeBefore (absl::CivilDay (2020 , 7 , 24 ));
417+ auto const condition = LifecycleRule::ConditionConjunction (c1, c2);
418+ ASSERT_TRUE (condition.custom_time_before .has_value ());
419+ EXPECT_EQ (absl::CivilDay (2020 , 7 , 23 ), *condition.custom_time_before );
420+ }
421+
320422// / @test Verify that LifecycleRule::ConditionConjunction() works as expected.
321423TEST (LifecycleRuleTest, ConditionConjunctionMultiple) {
322424 auto c1 = LifecycleRule::NumNewerVersions (7 );
@@ -348,7 +450,11 @@ TEST(LifecycleRuleTest, Parsing) {
348450 LifecycleRule::CreatedBefore (absl::CivilDay (2018 , 7 , 23 )),
349451 LifecycleRule::IsLive (true ),
350452 LifecycleRule::MatchesStorageClassStandard (),
351- LifecycleRule::NumNewerVersions (7 ));
453+ LifecycleRule::NumNewerVersions (7 ),
454+ LifecycleRule::DaysSinceNoncurrentTime (3 ),
455+ LifecycleRule::NoncurrentTimeBefore (absl::CivilDay (2020 , 7 , 22 )),
456+ LifecycleRule::DaysSinceCustomTime (30 ),
457+ LifecycleRule::CustomTimeBefore (absl::CivilDay (2020 , 7 , 23 )));
352458 EXPECT_EQ (expected_condition, actual.condition ());
353459
354460 LifecycleRuleAction expected_action =
@@ -364,6 +470,8 @@ TEST(LifecycleRuleTest, LifecycleRuleStream) {
364470 auto actual = os.str ();
365471 EXPECT_THAT (actual, ::testing::HasSubstr (" age=42" ));
366472 EXPECT_THAT (actual, ::testing::HasSubstr (" NEARLINE" ));
473+ EXPECT_THAT (actual, ::testing::HasSubstr (" days_since_custom_time=" ));
474+ EXPECT_THAT (actual, ::testing::HasSubstr (" custom_time_before=" ));
367475}
368476
369477} // namespace
0 commit comments