Skip to content

Commit ecdd7b7

Browse files
author
Nicholas Thomson
committed
e2e tests with acktest
1 parent dbb7017 commit ecdd7b7

File tree

10 files changed

+340
-0
lines changed

10 files changed

+340
-0
lines changed

.github/workflows/e2e-test.yaml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: e2e-test
2+
on:
3+
# Allow manual trigger of e2e tests
4+
workflow_dispatch:
5+
inputs:
6+
communityRepo:
7+
description: 'Git repository for checking out the community repo'
8+
required: false
9+
default: 'aws-controllers-k8s/community'
10+
communityRef:
11+
description: 'Git ref for checking out the community repo. Default is main'
12+
required: false
13+
default: ''
14+
codeGeneratorRepo:
15+
description: 'Git repository for checking out the code-generator repo'
16+
required: false
17+
default: 'aws-controllers-k8s/code-generator'
18+
codeGeneratorRef:
19+
description: 'Git ref for checking out the code-generator repo. Default is main'
20+
required: false
21+
default: ''
22+
testInfraRepo:
23+
description: 'Git repository for checking out the test-infra repo'
24+
required: false
25+
default: 'aws-controllers-k8s/test-infra'
26+
testInfraRef:
27+
description: 'Git ref for checking out the test-infra repo. Default is main'
28+
required: false
29+
default: ''
30+
31+
jobs:
32+
e2e-test:
33+
name: controller e2e test
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
service:
38+
- s3
39+
runs-on: [aws-controllers-k8s]
40+
steps:
41+
- name: Set up Go 1.15
42+
uses: actions/setup-go@v2
43+
with:
44+
go-version: ^1.15
45+
id: go
46+
47+
- name: checkout service
48+
uses: actions/checkout@v2
49+
with:
50+
path: './src/github.com/aws-controllers-k8s/${{ matrix.service }}-controller'
51+
52+
- name: checkout community
53+
uses: actions/checkout@v2
54+
with:
55+
repository: ${{ github.event.inputs.communityRepo }}
56+
ref: ${{ github.event.inputs.communityRef }}
57+
path: './src/github.com/aws-controllers-k8s/community'
58+
59+
- name: checkout code-generator
60+
uses: actions/checkout@v2
61+
with:
62+
repository: ${{ github.event.inputs.codeGeneratorRepo }}
63+
ref: ${{ github.event.inputs.codeGeneratorRef }}
64+
path: './src/github.com/aws-controllers-k8s/code-generator'
65+
66+
- name: checkout test-infra
67+
uses: actions/checkout@v2
68+
with:
69+
repository: ${{ github.event.inputs.testInfraRepo }}
70+
ref: ${{ github.event.inputs.testInfraRef }}
71+
path: './src/github.com/aws-controllers-k8s/test-infra'
72+
73+
- name: build controller
74+
working-directory: './src/github.com/aws-controllers-k8s/community'
75+
run: ./scripts/build-controller.sh $SERVICE
76+
env:
77+
SERVICE: ${{ matrix.service }}
78+
GOPATH: ${{ github.workspace }}
79+
80+
- name: execute e2e tests
81+
working-directory: './src/github.com/aws-controllers-k8s/community'
82+
run: |
83+
export AWS_ROLE_ARN=$(aws ssm get-parameter --name ACK_ROLE_ARN --query "Parameter.Value" --output text)
84+
export AWS_ROLE_ARN_ALT=$(aws ssm get-parameter --name ACK_ROLE_ARN_ALT --query "Parameter.Value" --output text)
85+
./scripts/kind-build-test.sh $SERVICE
86+
env:
87+
SERVICE: ${{ matrix.service }}
88+
GOPATH: ${{ github.workspace }}
89+
PRESERVE: 'false'

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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 pathlib import Path
16+
from acktest.k8s import resource
17+
18+
SERVICE_NAME = "s3"
19+
CRD_GROUP = "s3.services.k8s.aws"
20+
CRD_VERSION = "v1alpha1"
21+
22+
# PyTest marker for the current service
23+
service_marker = pytest.mark.service(arg=SERVICE_NAME)
24+
25+
resource_directory = Path(__file__).parent / "resources"
26+
27+
def create_s3_resource(
28+
resource_plural, resource_name, spec_file, replacements, namespace="default"
29+
):
30+
"""
31+
Wrapper around k8s.load_and_create_resource to create an S3 resource
32+
"""
33+
34+
reference, spec, resource = resource.load_and_create_resource(
35+
SERVICE_NAME,
36+
CRD_GROUP,
37+
CRD_VERSION,
38+
resource_plural,
39+
resource_name,
40+
spec_file,
41+
replacements,
42+
namespace,
43+
)
44+
45+
return reference, spec, resource

test/e2e/bootstrap_resources.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
"""Declares the structure of the bootstrapped resources and provides a loader
14+
for them.
15+
"""
16+
from dataclasses import dataclass
17+
18+
from acktest.resources import read_bootstrap_config
19+
from e2e import SERVICE_NAME
20+
21+
@dataclass
22+
class TestBootstrapResources:
23+
pass
24+
25+
_bootstrap_resources = None
26+
27+
def get_bootstrap_resources():
28+
global _bootstrap_resources
29+
if _bootstrap_resources is None:
30+
_bootstrap_resources = TestBootstrapResources(**read_bootstrap_config(SERVICE_NAME))
31+
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
"""Stores the values used by each of the integration tests for replacing the
14+
S3-specific test variables.
15+
"""
16+
17+
REPLACEMENT_VALUES = {
18+
19+
}

test/e2e/requirements.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
acktest @ git+https://github.com/aws-controllers-k8s/test-infra.git@f9216390ff69b7defe2925dd65990364b37636f7
2+
apipkg==1.5
3+
attrs==20.3.0
4+
boto3==1.16.40
5+
botocore==1.19.63
6+
cachetools==4.2.1
7+
certifi==2020.12.5
8+
chardet==4.0.0
9+
execnet==1.8.0
10+
google-auth==1.28.0
11+
idna==2.10
12+
iniconfig==1.1.1
13+
jmespath==0.10.0
14+
kubernetes==12.0.1
15+
oauthlib==3.1.0
16+
packaging==20.9
17+
pluggy==0.13.1
18+
py==1.10.0
19+
pyasn1==0.4.8
20+
pyasn1-modules==0.2.8
21+
pyparsing==2.4.7
22+
pytest==6.2.3
23+
pytest-forked==1.3.0
24+
pytest-xdist==2.2.0
25+
python-dateutil==2.8.1
26+
PyYAML==5.4
27+
requests==2.25.1
28+
requests-oauthlib==1.3.0
29+
rsa==4.7.2
30+
s3transfer==0.3.6
31+
six==1.15.0
32+
toml==0.10.2
33+
urllib3==1.26.4
34+
websocket-client==0.58.0

test/e2e/service_bootstrap.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+
"""Bootstraps the resources required to run the S3 integration tests.
14+
"""
15+
16+
import logging
17+
from pathlib import Path
18+
19+
from acktest import resources
20+
from e2e.bootstrap_resources import TestBootstrapResources
21+
22+
23+
def service_bootstrap() -> dict:
24+
logging.getLogger().setLevel(logging.INFO)
25+
26+
return TestBootstrapResources(
27+
).__dict__
28+
29+
if __name__ == "__main__":
30+
root_test_path = Path(__file__).parent
31+
32+
config = service_bootstrap()
33+
# Write config to current directory by default
34+
resources.write_bootstrap_config(config, root_test_path)

test/e2e/service_cleanup.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+
"""Cleans up the resources created by the S3 bootstrapping process.
14+
"""
15+
16+
import logging
17+
from pathlib import Path
18+
19+
from acktest import resources
20+
from e2e.bootstrap_resources import TestBootstrapResources
21+
22+
def service_cleanup(config: dict):
23+
logging.getLogger().setLevel(logging.INFO)
24+
25+
resources = TestBootstrapResources(
26+
**config
27+
)
28+
29+
if __name__ == "__main__":
30+
root_test_path = Path(__file__).parent
31+
32+
bootstrap_config = resources.read_bootstrap_config(root_test_path)
33+
service_cleanup(bootstrap_config)

test/e2e/tests/test_bucket.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
from e2e import SERVICE_NAME
3+
4+
class TestBucket:
5+
def test_bucket(self):
6+
pytest.skip(f"No tests for {SERVICE_NAME}")

0 commit comments

Comments
 (0)