Skip to content

Commit

Permalink
fix: config env cannot be anything other than default (#1769)
Browse files Browse the repository at this point in the history
  • Loading branch information
sriram-mv committed Feb 11, 2020
1 parent 546d06e commit b422f0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions samcli/cli/cli_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ def configuration_callback(cmd_name, option_name, config_env_name, saved_callbac
ctx.default_map = ctx.default_map or {}
cmd_name = cmd_name or ctx.info_name
param.default = None
config_env_name = value or config_env_name
# explicitly ignore values passed to --config-env, can be opened up in the future.
config_env_name = DEFAULT_ENV
config = get_ctx_defaults(cmd_name, provider, ctx, config_env_name=config_env_name)
ctx.default_map.update(config)

return saved_callback(ctx, param, value) if saved_callback else value
return saved_callback(ctx, param, config_env_name) if saved_callback else config_env_name


def get_ctx_defaults(cmd_name, provider, ctx, config_env_name):
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/cli/test_cli_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from samcli.commands.exceptions import ConfigException
from samcli.cli.cli_config_file import TomlProvider, configuration_option, configuration_callback, get_ctx_defaults
from samcli.lib.config.samconfig import SamConfig
from samcli.lib.config.samconfig import SamConfig, DEFAULT_ENV


class MockContext:
Expand Down Expand Up @@ -58,6 +58,7 @@ class TestCliConfiguration(TestCase):
def setUp(self):
self.cmd_name = "test_cmd"
self.option_name = "test_option"
# No matter what config-env is passed in, default is chosen.
self.config_env = "test_config_env"
self.saved_callback = MagicMock()
self.provider = MagicMock()
Expand Down Expand Up @@ -85,8 +86,9 @@ def test_callback_with_valid_config_env(self):
value=self.value,
)
self.assertEqual(self.saved_callback.call_count, 1)
for arg in [self.ctx, self.param, self.value]:
for arg in [self.ctx, self.param, DEFAULT_ENV]:
self.assertIn(arg, self.saved_callback.call_args[0])
self.assertNotIn(self.value, self.saved_callback.call_args[0])

def test_configuration_option(self):
toml_provider = TomlProvider()
Expand Down

0 comments on commit b422f0a

Please sign in to comment.