Skip to content

Commit b9bdff7

Browse files
authored
Merge pull request #2 from A-Hilaly/test
Add e2e tests using `acktest` and Github actions workflow
2 parents 851ab49 + 4cccfd6 commit b9bdff7

13 files changed

+415
-0
lines changed

.github/workflows/e2e-test.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
testInfraRepo:
15+
description: 'Git repository for checking out the test-infra repo'
16+
required: false
17+
default: 'aws-controllers-k8s/test-infra'
18+
testInfraRef:
19+
description: 'Git ref for checking out the test-infra repo. Default is main'
20+
required: false
21+
default: ''
22+
23+
jobs:
24+
e2e-test:
25+
name: controller e2e test
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
service:
30+
- ecr
31+
runs-on: [aws-controllers-k8s]
32+
steps:
33+
- name: Set up Go 1.15
34+
uses: actions/setup-go@v2
35+
with:
36+
go-version: ^1.15
37+
id: go
38+
39+
- name: checkout service
40+
uses: actions/checkout@v2
41+
with:
42+
path: './src/github.com/aws-controllers-k8s/${{ matrix.service }}-controller'
43+
44+
- name: checkout community
45+
uses: actions/checkout@v2
46+
with:
47+
repository: ${{ github.event.inputs.communityRepo }}
48+
ref: ${{ github.event.inputs.communityRef }}
49+
path: './src/github.com/aws-controllers-k8s/community'
50+
51+
- name: checkout test-infra
52+
uses: actions/checkout@v2
53+
with:
54+
repository: ${{ github.event.inputs.testInfraRepo }}
55+
ref: ${{ github.event.inputs.testInfraRef }}
56+
path: './src/github.com/aws-controllers-k8s/test-infra'
57+
58+
- name: execute e2e tests
59+
working-directory: './src/github.com/aws-controllers-k8s/community'
60+
run: |
61+
export AWS_ROLE_ARN=$(aws ssm get-parameter --name ACK_ROLE_ARN --query "Parameter.Value" --output text)
62+
export AWS_ROLE_ARN_ALT=$(aws ssm get-parameter --name ACK_ROLE_ARN_ALT --query "Parameter.Value" --output text)
63+
./scripts/kind-build-test.sh $SERVICE
64+
env:
65+
SERVICE: ${{ matrix.service }}
66+
GOPATH: ${{ github.workspace }}
67+
PRESERVE: 'false'

.github/workflows/unit-test.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: unit-test
2+
on:
3+
# Allow manual trigger
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
paths:
9+
- '**.go'
10+
- Makefile
11+
- go.mod
12+
- go.sum
13+
14+
jobs:
15+
build:
16+
name: make test
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: checkout code
20+
uses: actions/checkout@v2
21+
- uses: actions/setup-go@v2
22+
with:
23+
go-version: '1.15'
24+
- name: make test
25+
run: make test

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)

0 commit comments

Comments
 (0)