Skip to content

Commit 1857a0c

Browse files
committed
add e2e tests for point in time recovery (#1790)
1 parent b425e70 commit 1857a0c

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

Diff for: test/e2e/table.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ def __call__(self, record: dict) -> bool:
7272
def ttl_on_attribute_matches(attr_name: str) -> TableMatchFunc:
7373
return TTLAttributeMatcher(attr_name)
7474

75+
class PITRMatcher:
76+
def __init__(self, enabled: bool):
77+
self.enabled = enabled
78+
79+
def __call__(self, record: dict) -> bool:
80+
pitr_enabled = get_point_in_time_recovery_enabled(record['TableName'])
81+
if pitr_enabled is None:
82+
return False
83+
return pitr_enabled == self.enabled
84+
85+
def point_in_time_recovery_matches(enabled: bool) -> TableMatchFunc:
86+
return PITRMatcher(enabled)
7587

7688
class StreamSpecificationMatcher:
7789
def __init__(self, enabled: bool):
@@ -230,4 +242,16 @@ def get_time_to_live(table_name):
230242
resp = c.describe_time_to_live(TableName=table_name)
231243
return resp['TimeToLiveDescription']
232244
except c.exceptions.ResourceNotFoundException:
233-
return None
245+
return None
246+
247+
def get_point_in_time_recovery_enabled(table_name):
248+
"""Returns whether point in time recovery is enabled for the table with a supplied name.
249+
250+
If no such Table exists, returns None.
251+
"""
252+
c = boto3.client('dynamodb', region_name=get_region())
253+
try:
254+
resp = c.describe_continuous_backups(TableName=table_name)
255+
return resp['ContinuousBackupsDescription']['PointInTimeRecoveryDescription']['PointInTimeRecoveryStatus'] == 'ENABLED'
256+
except c.exceptions.ResourceNotFoundException:
257+
return None

Diff for: test/e2e/tests/test_table.py

+54-1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,59 @@ def test_enable_ttl(self, table_lsi):
265265
ttl_status = ttl["TimeToLiveStatus"]
266266
assert ttl_status in ("ENABLED", "ENABLING")
267267

268+
def test_enable_point_in_time_recovery(self, table_lsi):
269+
(ref, res) = table_lsi
270+
271+
table_name = res["spec"]["tableName"]
272+
273+
# Check DynamoDB Table exists
274+
assert self.table_exists(table_name)
275+
276+
# Get CR latest revision
277+
cr = k8s.wait_resource_consumed_by_controller(ref)
278+
279+
# Update PITR
280+
updates = {
281+
"spec": {
282+
"continuousBackups": {
283+
"pointInTimeRecoveryEnabled": True
284+
}
285+
}
286+
}
287+
288+
# Patch k8s resource
289+
k8s.patch_custom_resource(ref, updates)
290+
291+
table.wait_until(
292+
table_name,
293+
table.point_in_time_recovery_matches(True),
294+
)
295+
296+
pitr_enabled = table.get_point_in_time_recovery_enabled(table_name)
297+
assert pitr_enabled is not None
298+
assert pitr_enabled
299+
300+
# turn off pitr again and ensure it is disabled
301+
updates = {
302+
"spec": {
303+
"continuousBackups": {
304+
"pointInTimeRecoveryEnabled": False
305+
}
306+
}
307+
}
308+
309+
# Patch k8s resource
310+
k8s.patch_custom_resource(ref, updates)
311+
312+
table.wait_until(
313+
table_name,
314+
table.point_in_time_recovery_matches(False),
315+
)
316+
317+
pitr_enabled = table.get_point_in_time_recovery_enabled(table_name)
318+
assert pitr_enabled is not None
319+
assert not pitr_enabled
320+
268321
def test_enable_stream_specification(self, table_lsi):
269322
(ref, res) = table_lsi
270323

@@ -706,4 +759,4 @@ def test_multi_updates(self, table_gsi):
706759

707760
assert latestTable["ProvisionedThroughput"] is not None
708761
assert latestTable["ProvisionedThroughput"]["ReadCapacityUnits"] == 10
709-
assert latestTable["ProvisionedThroughput"]["WriteCapacityUnits"] == 10
762+
assert latestTable["ProvisionedThroughput"]["WriteCapacityUnits"] == 10

0 commit comments

Comments
 (0)