1+ # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License"). You may
4+ # not use this file except in compliance with the License. A copy of the
5+ # License is located at
6+ #
7+ # http://aws.amazon.com/apache2.0/
8+ #
9+ # or in the "license" file accompanying this file. This file is distributed
10+ # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+ # express or implied. See the License for the specific language governing
12+ # permissions and limitations under the License.
13+
14+ """Integration tests for the EventBridge Archive API.
15+ """
16+
17+ import pytest
18+ import time
19+ import logging
20+
21+ from acktest .resources import random_suffix_name
22+ from acktest .k8s import resource as k8s
23+ from acktest .k8s import condition as condition
24+ from acktest import tags
25+ from e2e import service_marker , CRD_GROUP , CRD_VERSION , load_eventbridge_resource
26+ from e2e .replacement_values import REPLACEMENT_VALUES
27+ from e2e .tests .helper import EventBridgeValidator
28+
29+ RESOURCE_PLURAL = "archives"
30+
31+ CREATE_WAIT_AFTER_SECONDS = 10
32+ UPDATE_WAIT_AFTER_SECONDS = 10
33+ DELETE_WAIT_AFTER_SECONDS = 10
34+
35+ @pytest .fixture (scope = "module" )
36+ def event_bus ():
37+ resource_name = random_suffix_name ("ack-test-bus" , 24 )
38+
39+ replacements = REPLACEMENT_VALUES .copy ()
40+ replacements ["BUS_NAME" ] = resource_name
41+
42+ # Load EventBus CR
43+ resource_data = load_eventbridge_resource (
44+ "eventbus" ,
45+ additional_replacements = replacements ,
46+ )
47+ logging .debug (resource_data )
48+
49+ # Create k8s resource
50+ ref = k8s .CustomResourceReference (
51+ CRD_GROUP , CRD_VERSION , "eventbuses" ,
52+ resource_name , namespace = "default" ,
53+ )
54+ k8s .create_custom_resource (ref , resource_data )
55+ cr = k8s .wait_resource_consumed_by_controller (ref )
56+
57+ assert cr is not None
58+ assert k8s .get_resource_exists (ref )
59+
60+ time .sleep (CREATE_WAIT_AFTER_SECONDS )
61+
62+ cr = k8s .wait_resource_consumed_by_controller (ref )
63+
64+ yield (ref , cr )
65+
66+ try :
67+ _ , deleted = k8s .delete_custom_resource (ref , 3 , 10 )
68+ assert deleted
69+ except :
70+ pass
71+
72+ @pytest .fixture (scope = "module" )
73+ def archive (event_bus ):
74+ resource_name = random_suffix_name ("ack-test-archive" , 24 )
75+ _ , eb_cr = event_bus
76+
77+ replacements = REPLACEMENT_VALUES .copy ()
78+ replacements ["ARCHIVE_NAME" ] = resource_name
79+ replacements ["EVENT_SOURCE_ARN" ] = eb_cr ["status" ]["ackResourceMetadata" ]["arn" ]
80+
81+ # Load EventBus CR
82+ resource_data = load_eventbridge_resource (
83+ "archive" ,
84+ additional_replacements = replacements ,
85+ )
86+ logging .debug (resource_data )
87+
88+ # Create k8s resource
89+ ref = k8s .CustomResourceReference (
90+ CRD_GROUP , CRD_VERSION , RESOURCE_PLURAL ,
91+ resource_name , namespace = "default" ,
92+ )
93+ k8s .create_custom_resource (ref , resource_data )
94+ cr = k8s .wait_resource_consumed_by_controller (ref )
95+
96+ assert cr is not None
97+ assert k8s .get_resource_exists (ref )
98+
99+ time .sleep (CREATE_WAIT_AFTER_SECONDS )
100+
101+ cr = k8s .wait_resource_consumed_by_controller (ref )
102+
103+ yield (ref , cr )
104+
105+ try :
106+ _ , deleted = k8s .delete_custom_resource (ref , 3 , 10 )
107+ assert deleted
108+ except :
109+ pass
110+
111+
112+ @service_marker
113+ @pytest .mark .canary
114+ class TestEventBus :
115+ def test_crud (self , eventbridge_client , archive ):
116+ (ref , cr ) = archive
117+ archive_name = cr ["spec" ]["archiveName" ]
118+
119+ # Check archive exists
120+ eventbridge_validator = EventBridgeValidator (eventbridge_client )
121+ assert eventbridge_validator .archive_exists (archive_name )
122+
123+ new_description = "new archive description"
124+ cr ["spec" ]["description" ] = new_description
125+
126+ # Patch k8s resource
127+ k8s .patch_custom_resource (ref , cr )
128+ time .sleep (UPDATE_WAIT_AFTER_SECONDS )
129+
130+ # Check description new value
131+ archive = eventbridge_validator .get_archive (archive_name )
132+ assert archive ["Description" ] == new_description
133+
134+ # Delete k8s resource
135+ _ , deleted = k8s .delete_custom_resource (ref )
136+ assert deleted
137+
138+ time .sleep (DELETE_WAIT_AFTER_SECONDS )
139+
140+ # Check archive doesn't exist
141+ assert not eventbridge_validator .archive_exists (archive_name )
0 commit comments