Skip to content

Commit 4c26500

Browse files
author
Nicholas Thomson
committed
Migrate community e2e tests
1 parent ef8242f commit 4c26500

18 files changed

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

test/e2e/bootstrap_resources.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 pathlib import Path
20+
from acktest.resources import read_bootstrap_config
21+
from e2e import bootstrap_directory
22+
23+
@dataclass
24+
class TestBootstrapResources:
25+
AuthorizerRoleName: str
26+
AuthorizerPolicyArn: str
27+
AuthorizerRoleArn: str
28+
AuthorizerFunctionName: str
29+
AuthorizerFunctionArn: str
30+
31+
32+
_bootstrap_resources = None
33+
34+
35+
def get_bootstrap_resources(bootstrap_file_name: str = "bootstrap.yaml"):
36+
global _bootstrap_resources
37+
if _bootstrap_resources is None:
38+
_bootstrap_resources = TestBootstrapResources(
39+
**read_bootstrap_config(bootstrap_directory, bootstrap_file_name=bootstrap_file_name),
40+
)
41+
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: 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+
14+
"""Stores the values used by each of the integration tests for replacing the
15+
APIGatewayV2-specific test variables.
16+
"""
17+
18+
REPLACEMENT_VALUES = {
19+
"API_NAME": "ack-test-api",
20+
"API_TITLE": "ack-test-api",
21+
"API_ID": "api_id",
22+
"INTEGRATION_NAME": "ack-test-integration",
23+
"INTEGRATION_URI": "https://httpbin.org/get",
24+
"AUTHORIZER_NAME": "ack-test-authorizer",
25+
"AUTHORIZER_TITLE": "ack-test-authorizer",
26+
"IDENTITY_SOURCE": "$request.header.Authorization",
27+
"AUTHORIZER_URI": "authorizer_uri",
28+
"ROUTE_NAME": "ack-test-route",
29+
"ROUTE_PATH": "httpbin",
30+
"ROUTE_KEY": "GET /httpbin",
31+
"INTEGRATION_ID": "integration_id",
32+
"AUTHORIZER_ID": "authorizer_id",
33+
"STAGE_NAME": "test",
34+
"STAGE_DESCRIPTION": "ack-test-stage"
35+
}

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/RedbackThomson/ack-test-infra.git@b2ceaf3f28dca196dbd0c80ffdb57719096bead1
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/resources/authorizer.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: apigatewayv2.services.k8s.aws/v1alpha1
2+
kind: Authorizer
3+
metadata:
4+
name: $AUTHORIZER_NAME
5+
spec:
6+
apiID: $API_ID
7+
authorizerType: REQUEST
8+
identitySource:
9+
- $IDENTITY_SOURCE
10+
name: $AUTHORIZER_TITLE
11+
authorizerURI: $AUTHORIZER_URI
12+
authorizerPayloadFormatVersion: '2.0'
13+
enableSimpleResponses: true

test/e2e/resources/httpapi.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: apigatewayv2.services.k8s.aws/v1alpha1
2+
kind: API
3+
metadata:
4+
name: "$API_NAME"
5+
spec:
6+
name: "$API_TITLE"
7+
protocolType: HTTP

test/e2e/resources/import_api.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: apigatewayv2.services.k8s.aws/v1alpha1
2+
kind: API
3+
metadata:
4+
name: "$API_NAME"
5+
spec:
6+
body: '{
7+
"openapi": "3.0.1",
8+
"info": {
9+
"title": "$API_TITLE",
10+
"version": "v1"
11+
},
12+
"paths": {
13+
"/": {
14+
"get": {
15+
"x-amazon-apigateway-integration": {
16+
"uri": "http://example.com",
17+
"httpMethod": "GET",
18+
"type": "HTTP_PROXY",
19+
"payloadFormatVersion": "1.0"
20+
}
21+
}
22+
}
23+
},
24+
"components": {}
25+
}'

test/e2e/resources/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// function code for apigateway lambda authorizer
2+
exports.handler = async(event) => {
3+
let response = {
4+
"isAuthorized": false,
5+
"context": {
6+
"stringKey": "value",
7+
"numberKey": 1,
8+
"booleanKey": true,
9+
"arrayKey": ["value1", "value2"],
10+
"mapKey": {"value1": "value2"}
11+
}
12+
};
13+
14+
if (event.headers.authorization === "SecretToken") {
15+
response = {
16+
"isAuthorized": true,
17+
"context": {
18+
"stringKey": "value",
19+
"numberKey": 1,
20+
"booleanKey": true,
21+
"arrayKey": ["value1", "value2"],
22+
"mapKey": {"value1": "value2"}
23+
}
24+
};
25+
}
26+
return response;
27+
};

0 commit comments

Comments
 (0)