Skip to content

Commit

Permalink
Address review comments and add more tests
Browse files Browse the repository at this point in the history
Update the test data file with the same contents as botocore. This means
that tests with `ignore_configured_endpoint_urls` parameter for client
args need to be skipped since this is not supported as a command line
parameter.
  • Loading branch information
kdaily committed Jul 5, 2023
1 parent 426ea6b commit 3bc6ea5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/functional/configured_endpoint_urls/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
Expand Down
27 changes: 27 additions & 0 deletions tests/functional/configured_endpoint_urls/profile-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
"default": {},
"endpoint_url_provided":{
"endpoint_url": "https://client-config.endpoint.aws"
},
"ignore_configured_endpoint_urls": {
"ignore_configured_endpoint_urls": "true"
},
"provide_and_ignore_configured_endpoint_urls": {
"ignore_configured_endpoint_urls": "true",
"endpoint_url": "https://client-config.endpoint.aws"
}
},

Expand Down Expand Up @@ -431,6 +438,16 @@
"endpointUrl": "https://s3.fake-region-10.amazonaws.com"
}
},
{
"name": "All configured endpoints ignored due to ignore shared config variable.",
"profile": "global_and_service_specific_s3",
"client_config": "ignore_configured_endpoint_urls",
"environment": "global_and_service_specific_s3",
"service": "s3",
"output": {
"endpointUrl": "https://s3.fake-region-10.amazonaws.com"
}
},
{
"name": "Environment variable and shared config file configured endpoints ignored due to ignore shared config variable and client configured endpoint is used.",
"profile": "ignore_global_and_service_specific_s3",
Expand All @@ -451,6 +468,16 @@
"endpointUrl": "https://client-config.endpoint.aws"
}
},
{
"name": "Environment variable and shared config file configured endpoints ignored due to ignore client config variable and client configured endpoint is used.",
"profile": "global_and_service_specific_s3",
"client_config": "provide_and_ignore_configured_endpoint_urls",
"environment": "global_and_service_specific_s3",
"service": "s3",
"output": {
"endpointUrl": "https://client-config.endpoint.aws"
}
},
{
"name": "DynamoDB service-specific endpoint url shared config variable is used when service-specific S3 shared config variable is also present.",
"profile": "service_specific_dynamodb_and_s3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import json
import os
from pathlib import Path

import pytest

from tests import CLIRunner, SessionStubber
from tests import CLIRunner
from awscli.compat import urlparse
from awscli.testutils import FileCreator


ENDPOINT_TESTDATA_FILE = Path(__file__).parent / "profile-tests.json"
Expand Down Expand Up @@ -58,6 +56,13 @@ def create_cases():
test_case_data['environment'], {}
),
},
marks=pytest.mark.skipif(
'ignore_configured_endpoint_urls' in (
test_suite['client_configs']
.get(test_case_data['client_config'], {})
),
reason="Parameter not supported on the command line"
),
id=test_case_data['name']
)

Expand Down Expand Up @@ -100,7 +105,8 @@ def assert_endpoint_used(
):

aws_request = cli_runner_result.aws_requests[0]
assert test_case['expected_endpoint_url'] == _normalize_endpoint(aws_request.http_requests[0].url), test_case
assert test_case['expected_endpoint_url'] == \
_normalize_endpoint(aws_request.http_requests[0].url)

def _create_command(self, test_case):
service = test_case['service']
Expand All @@ -113,7 +119,8 @@ def _create_command(self, test_case):
'--profile',
f'{test_case["profile"]}'
]
if test_case['client_args']:

if test_case['client_args'].get('endpoint_url', None):
cmd.extend([
'--endpoint-url',
f'{test_case["client_args"]["endpoint_url"]}'
Expand All @@ -123,24 +130,19 @@ def _create_command(self, test_case):
return cmd

@pytest.mark.parametrize('test_case', create_cases())
def test_resolve_configured_endpoint_url(self, test_case):
session_stubber = SessionStubber()

cli_runner = CLIRunner(session_stubber=session_stubber)
def test_resolve_configured_endpoint_url(self, tmp_path, test_case):
cli_runner = CLIRunner()

config_files = FileCreator()
config_filename = os.path.join(
config_files.rootdir, 'config')
config_filename = tmp_path / 'config'

with open(config_filename, 'w') as f:
f.write(test_case['config_file_contents'])
f.flush()

cli_runner.env['AWS_CONFIG_FILE'] = config_filename
cli_runner.env.update(test_case['environment'])
_ = cli_runner.env.pop('AWS_DEFAULT_REGION')
cli_runner.env.pop('AWS_DEFAULT_REGION')

print(self._create_command(test_case))
result = cli_runner.run(self._create_command(test_case))

self.assert_endpoint_used(result, test_case)

0 comments on commit 3bc6ea5

Please sign in to comment.