Skip to content

Conversation

@sanathkr
Copy link
Contributor

@sanathkr sanathkr commented Nov 22, 2019

Issue #, if available:

Description of changes:

Checklist:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sriram-mv
Copy link
Contributor

since you are writing tests, could you also add version=0.1 to the toml document? when we create it.

LOG.exception("Command failed", exc_info=result.exc_info)
self.assertIsNone(result.exception)

do_cli_mock.assert_called_with(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we make assert_called_with(a=b,c=d,e=f,g=h) instead of assert_called_with(b,d,f,h). That way its explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to verify the ordering as well, because that's how the do_cli method is called. Makes sense?

"manifest": "requirements.txt",
"docker_network": "mynetwork",
"skip_pull_image": True,
"parameter_overrides": "ParameterKey=Key,ParameterValue=Value ParameterKey=Key2,ParameterValue=Value2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add parameter overrides that are "a=b c=d" as well, that way we exercise the second regex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, some of the others have this

"event": "event",
"no_event": False,
"env_vars": "envvar.json",
"debug_port": [1, 2, 3],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 glad to know multiples work well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, I know! Do we document this case explicitly?

)

@patch("samcli.commands.deploy.command.do_cli")
def test_deploy(self, do_cli_mock):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add another series of tests, where we supply args and they override whats in the config file.

return f'(\\"(?:\\\\.|[^\\"\\\\]+)*\\"|(?:\\\\.|[^{delim}\\"\\\\]+)+)'


KEY_REGEX = '([A-Za-z0-9\\"]+)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing these regexes, will report back with results.


_pattern_1 = r"(?:ParameterKey={key},ParameterValue={value}".format(key=KEY_REGEX, value=VALUE_REGEX)
_pattern_2 = r"(?:(?: ){key}={value}".format(key=KEY_REGEX, value=VALUE_REGEX)
_pattern_1 = r"(?:ParameterKey={key},ParameterValue={value})".format(key=KEY_REGEX, value=VALUE_REGEX_SPACE_DELIM)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, did some testing.
Things we may need to make a note of:
_pattern_1 works well when the entire string that is compared with the regex is under quotes.

Works:

"ParameterKey=Key,ParameterValue=Value" Groups: Key, Value
"ParameterKey=Key,ParameterValue=Value Groups: Key, Value
ParameterKey=Key,ParameterValue=Value" Groups: Key, Value
Doesnt work:

ParameterKey=Key,ParameterValue="Value" No Groups
ParameterKey="Key",ParameterValue="Value" No Groups
"ParameterKey="Key",ParameterValue="Value"" No Groups

_pattern_1 = r"(?:ParameterKey={key},ParameterValue={value}".format(key=KEY_REGEX, value=VALUE_REGEX)
_pattern_2 = r"(?:(?: ){key}={value}".format(key=KEY_REGEX, value=VALUE_REGEX)
_pattern_1 = r"(?:ParameterKey={key},ParameterValue={value})".format(key=KEY_REGEX, value=VALUE_REGEX_SPACE_DELIM)
_pattern_2 = r"(?:(?: ){key}={value})".format(key=KEY_REGEX, value=VALUE_REGEX_SPACE_DELIM)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well, Gotchas with quotes.

Works
dd=gfbfg asdf=dadsf asdasd=qwe Groups (dd,gfbfg) (asdf,dadsf) (asdasd, qwe)
" "dd"='gfbfg'" Groups ("dd",'gfbfg')

Doesn't work

' "dd"="gfbfg" "asdf"="dadsf" "asdasd"="qwed"' No Groups

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not worried about the key not supporting quotes. that's out of scope. Also, value using single quotes is also out-of-scope.

Copy link
Contributor

@sriram-mv sriram-mv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇 💯

This is non trivial testing, for the full surface area of the cli with configuration.

⭐️ ⭐️ ⭐️ ⭐️ ⭐️

self.scratch_dir = None

@patch("samcli.commands.local.start_lambda.cli.do_cli")
def test_override_with_cli_params(self, do_cli_mock):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this!

runner = CliRunner()
result = runner.invoke(
cli,
env={
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on env overrides.

@sriram-mv sriram-mv merged commit beb0c00 into aws:release-v0.32.0 Nov 22, 2019
sriram-mv pushed a commit that referenced this pull request Nov 23, 2019
* test: Verify samconfig is accessible to all CLI commands

* fix cases where comma vs space needs to be delimiter

* adding few more unit tests

* adding unit tests for all commands

* fix linter

* Adding tests for overriding args thru config, CLI args, and envvars

* Fixing a minor UX issue when sam template is invalid

* fixing mock imports
@gdunkle
Copy link

gdunkle commented Dec 10, 2019

I believe this change broke tag values that actually contain spaces (i.e. MyKey=My\ Value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants