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 S3 Bucket API.
15
+ """
16
+
17
+ import boto3
1
18
import pytest
2
- from e2e import SERVICE_NAME
19
+ import time
20
+ import logging
21
+ from typing import Dict , Tuple
22
+
23
+ from acktest .resources import random_suffix_name
24
+ from acktest .k8s import resource as k8s
25
+ from e2e import service_marker , CRD_GROUP , CRD_VERSION , load_s3_resource
26
+ from e2e .replacement_values import REPLACEMENT_VALUES
27
+ from e2e .bootstrap_resources import TestBootstrapResources , get_bootstrap_resources
28
+
29
+ RESOURCE_PLURAL = "buckets"
30
+
31
+ CREATE_WAIT_AFTER_SECONDS = 10
32
+ DELETE_WAIT_AFTER_SECONDS = 10
3
33
34
+ @pytest .fixture (scope = "module" )
35
+ def s3_client ():
36
+ return boto3 .client ("s3" )
37
+
38
+ @service_marker
39
+ @pytest .mark .canary
4
40
class TestBucket :
5
- def test_bucket (self ):
6
- pytest .skip (f"No tests for { SERVICE_NAME } " )
41
+ def get_bucket (self , s3_client , bucket_name : str ) -> dict :
42
+ try :
43
+ resp = s3_client .list_buckets ()
44
+ except Exception as e :
45
+ logging .debug (e )
46
+ return None
47
+
48
+ buckets = resp ["Buckets" ]
49
+ for bucket in buckets :
50
+ if bucket ["Name" ] == bucket_name :
51
+ return bucket
52
+
53
+ return None
54
+
55
+ def bucket_exists (self , s3_client , bucket_name : str ) -> bool :
56
+ return self .get_bucket (s3_client , bucket_name ) is not None
57
+
58
+ def test_smoke (self , s3_client ):
59
+ resource_name = random_suffix_name ("s3-bucket" , 24 )
60
+
61
+ replacements = REPLACEMENT_VALUES .copy ()
62
+ replacements ["BUCKET_NAME" ] = resource_name
63
+
64
+ # Load Bucket CR
65
+ resource_data = load_s3_resource (
66
+ "bucket" ,
67
+ additional_replacements = replacements ,
68
+ )
69
+ logging .debug (resource_data )
70
+
71
+ # Create k8s resource
72
+ ref = k8s .CustomResourceReference (
73
+ CRD_GROUP , CRD_VERSION , RESOURCE_PLURAL ,
74
+ resource_name , namespace = "default" ,
75
+ )
76
+ k8s .create_custom_resource (ref , resource_data )
77
+ cr = k8s .wait_resource_consumed_by_controller (ref )
78
+
79
+ assert cr is not None
80
+ assert k8s .get_resource_exists (ref )
81
+
82
+ time .sleep (CREATE_WAIT_AFTER_SECONDS )
83
+
84
+ # Check S3 Bucket exists
85
+ exists = self .bucket_exists (s3_client , resource_name )
86
+ assert exists
87
+
88
+ # Delete k8s resource
89
+ _ , deleted = k8s .delete_custom_resource (ref )
90
+ assert deleted is True
91
+
92
+ time .sleep (DELETE_WAIT_AFTER_SECONDS )
93
+
94
+ # Check S3 Bucket doesn't exists
95
+ exists = self .bucket_exists (s3_client , resource_name )
96
+ assert not exists
0 commit comments