-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_loop_detection.py
More file actions
115 lines (109 loc) · 3.34 KB
/
test_loop_detection.py
File metadata and controls
115 lines (109 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from s3_cross_region_compressor.utils.config_utils import detect_replication_loops
# Test case 1: Different prefixes - should NOT detect a loop
no_loop_config = {
"replication_configuration": [
{
"source": {
"region": "us-west-2",
"bucket": "s3-crc-oregon",
"prefix_filter": "historic"
},
"destinations": [
{
"region": "ca-central-1",
"bucket": "s3-crc-canada",
"storage_class": "GLACIER"
}
]
},
{
"source": {
"region": "ca-central-1",
"bucket": "s3-crc-canada",
"prefix_filter": "CanadaBackup"
},
"destinations": [
{
"region": "us-west-2",
"bucket": "s3-crc-oregon",
"storage_class": "STANDARD"
}
]
}
]
}
# Test case 2: Same prefixes - should detect a loop
loop_config = {
"replication_configuration": [
{
"source": {
"region": "us-west-2",
"bucket": "s3-crc-oregon",
"prefix_filter": "shared"
},
"destinations": [
{
"region": "ca-central-1",
"bucket": "s3-crc-canada",
"storage_class": "GLACIER"
}
]
},
{
"source": {
"region": "ca-central-1",
"bucket": "s3-crc-canada",
"prefix_filter": "shared"
},
"destinations": [
{
"region": "us-west-2",
"bucket": "s3-crc-oregon",
"storage_class": "STANDARD"
}
]
}
]
}
# Test case 3: Empty prefix and specific prefix - should NOT detect a loop
mixed_prefix_config = {
"replication_configuration": [
{
"source": {
"region": "us-west-2",
"bucket": "s3-crc-oregon",
# No prefix_filter specified
},
"destinations": [
{
"region": "ca-central-1",
"bucket": "s3-crc-canada",
"storage_class": "GLACIER"
}
]
},
{
"source": {
"region": "ca-central-1",
"bucket": "s3-crc-canada",
"prefix_filter": "CanadaBackup"
},
"destinations": [
{
"region": "us-west-2",
"bucket": "s3-crc-oregon",
"storage_class": "STANDARD"
}
]
}
]
}
print("Testing different prefixes (should NOT detect a loop):")
has_loop = detect_replication_loops(no_loop_config)
print(f"Loop detected: {has_loop} (Expected: False)")
print("\nTesting same prefixes (should detect a loop):")
has_loop = detect_replication_loops(loop_config)
print(f"Loop detected: {has_loop} (Expected: True)")
print("\nTesting empty prefix vs specific prefix (should detect a loop):")
has_loop = detect_replication_loops(mixed_prefix_config)
print(f"Loop detected: {has_loop} (Expected: True)")