Skip to content

Commit

Permalink
Add test to verify no shadowed builtins
Browse files Browse the repository at this point in the history
This test was actually failing because of an operation
hiding the query argument for the cloudsearchdomain suggest
operation.
  • Loading branch information
jamesls committed Dec 19, 2014
1 parent cdb7c11 commit bcb4bf7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions awscli/customizations/argrename.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'emr.*.job-flow-ids': 'cluster-ids',
'emr.*.job-flow-id': 'cluster-id',
'cloudsearchdomain.search.query': 'search-query',
'cloudsearchdomain.suggest.query': 'suggest-query',
'sns.subscribe.endpoint': 'notification-endpoint',
'deploy.*.s-3-location': 's3-location',
'deploy.*.ec-2-tag-filters': 'ec2-tag-filters',
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,49 @@

import botocore.session
from awscli.testutils import unittest, aws
from awscli.clidriver import create_clidriver


def test_no_shadowed_builtins():
"""Verify no command params are shadowed by the built in param.
The CLI parses all command line options into a single namespace.
This means that option names must be unique and cannot conflict
with the top level params.
For example, there's a top level param ``--version``. If an
operation for a service also provides a ``--version`` option,
it can never be called because we'll assume the user meant
the top level ``--version`` param.
In order to ensure this doesn't happen, this test will go
through every command table and ensure we're not shadowing
any builtins.
Also, rather than being a test generator, we're going to just
aggregate all the failures in one pass and surface them as
a single test failure.
"""
driver = create_clidriver()
help_command = driver.create_help_command()
top_level_params = set(driver.create_help_command().arg_table)
errors = []
for command_name, command_obj in help_command.command_table.items():
sub_help = command_obj.create_help_command()
if hasattr(sub_help, 'command_table'):
for sub_name, sub_command in sub_help.command_table.items():
op_help = sub_command.create_help_command()
arg_table = op_help.arg_table
for arg_name in arg_table:
if arg_name in top_level_params:
# Then we're shadowing a built in argument.
errors.append(
'Shadowing a top level option: %s.%s.%s' % (
command_name, sub_name, arg_name))

if errors:
raise AssertionError('\n' + '\n'.join(errors))


class TestBasicCommandFunctionality(unittest.TestCase):
Expand Down

0 comments on commit bcb4bf7

Please sign in to comment.