Skip to content

Commit 284f2fa

Browse files
committed
Add ECR e2e tests
1 parent 851ab49 commit 284f2fa

11 files changed

+323
-0
lines changed

test/e2e/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__pycache__/
2+
*.py[cod]
3+
**/bootstrap.yaml

test/e2e/__init__.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
import pytest
15+
from typing import Dict, Any
16+
from pathlib import Path
17+
18+
from acktest.resources import load_resource_file
19+
20+
SERVICE_NAME = "ecr"
21+
CRD_GROUP = "ecr.services.k8s.aws"
22+
CRD_VERSION = "v1alpha1"
23+
24+
# PyTest marker for the current service
25+
service_marker = pytest.mark.service(arg=SERVICE_NAME)
26+
27+
bootstrap_directory = Path(__file__).parent
28+
resource_directory = Path(__file__).parent / "resources"
29+
def load_ecr_resource(resource_name: str, additional_replacements: Dict[str, Any] = {}):
30+
""" Overrides the default `load_resource_file` to access the specific resources
31+
directory for the current service.
32+
"""
33+
return load_resource_file(resource_directory, resource_name, additional_replacements=additional_replacements)

test/e2e/bootstrap_resources.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
"""Declares the structure of the bootstrapped resources and provides a loader
15+
for them.
16+
"""
17+
18+
from dataclasses import dataclass
19+
from acktest.resources import read_bootstrap_config
20+
from e2e import bootstrap_directory
21+
22+
@dataclass
23+
class TestBootstrapResources:
24+
pass
25+
26+
_bootstrap_resources = None
27+
28+
def get_bootstrap_resources(bootstrap_file_name: str = "bootstrap.yaml"):
29+
global _bootstrap_resources
30+
if _bootstrap_resources is None:
31+
_bootstrap_resources = TestBootstrapResources(
32+
**read_bootstrap_config(bootstrap_directory, bootstrap_file_name=bootstrap_file_name),
33+
)
34+
return _bootstrap_resources

test/e2e/conftest.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
import os
15+
import pytest
16+
17+
from acktest import k8s
18+
19+
20+
def pytest_addoption(parser):
21+
parser.addoption("--runslow", action="store_true", default=False, help="run slow tests")
22+
23+
24+
def pytest_configure(config):
25+
config.addinivalue_line(
26+
"markers", "canary: mark test to also run in canary tests"
27+
)
28+
config.addinivalue_line(
29+
"markers", "service(arg): mark test associated with a given service"
30+
)
31+
config.addinivalue_line(
32+
"markers", "slow: mark test as slow to run"
33+
)
34+
35+
def pytest_collection_modifyitems(config, items):
36+
if config.getoption("--runslow"):
37+
return
38+
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
39+
for item in items:
40+
if "slow" in item.keywords:
41+
item.add_marker(skip_slow)
42+
43+
# Provide a k8s client to interact with the integration test cluster
44+
@pytest.fixture(scope='class')
45+
def k8s_client():
46+
return k8s._get_k8s_api_client()

test/e2e/replacement_values.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
"""Stores the values used by each of the integration tests for replacing the
15+
ECR-specific test variables.
16+
"""
17+
18+
REPLACEMENT_VALUES = {
19+
20+
}

test/e2e/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
acktest @ git+https://github.com/aws-controllers-k8s/test-infra.git@5ed60a505afa953096e53c9d3d6779830250915b

test/e2e/resources/repository.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: ecr.services.k8s.aws/v1alpha1
2+
kind: Repository
3+
metadata:
4+
name: $REPOSITORY_NAME
5+
spec:
6+
repositoryName: $REPOSITORY_NAME
7+
imageScanningConfiguration:
8+
scanOnPush: false
9+
imageTagMutability: MUTABLE

test/e2e/service_bootstrap.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
"""Bootstraps the resources required to run the ECR integration tests.
14+
"""
15+
16+
import boto3
17+
import logging
18+
from time import sleep
19+
20+
from acktest import resources
21+
from acktest.aws.identity import get_region, get_account_id
22+
from e2e import bootstrap_directory
23+
from e2e.bootstrap_resources import TestBootstrapResources
24+
25+
def service_bootstrap() -> dict:
26+
logging.getLogger().setLevel(logging.INFO)
27+
28+
return TestBootstrapResources().__dict__
29+
30+
if __name__ == "__main__":
31+
config = service_bootstrap()
32+
# Write config to current directory by default
33+
resources.write_bootstrap_config(config, bootstrap_directory)

test/e2e/service_cleanup.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
"""Cleans up the resources created by the Application Auto Scaling bootstrapping process.
14+
"""
15+
16+
import boto3
17+
import logging
18+
19+
from acktest import resources
20+
from acktest.aws.identity import get_region
21+
22+
from e2e import bootstrap_directory
23+
from e2e.bootstrap_resources import TestBootstrapResources
24+
25+
26+
def service_cleanup(config: dict):
27+
logging.getLogger().setLevel(logging.INFO)
28+
29+
resources = TestBootstrapResources(
30+
**config
31+
)
32+
33+
if __name__ == "__main__":
34+
bootstrap_config = resources.read_bootstrap_config(bootstrap_directory)
35+
service_cleanup(bootstrap_config)

test/e2e/tests/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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.

0 commit comments

Comments
 (0)