-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Tests for samconfig use with all commands #1575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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\\"]+)' |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
sriram-mv
left a comment
There was a problem hiding this 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): |
There was a problem hiding this comment.
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={ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on env overrides.
* 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
|
I believe this change broke tag values that actually contain spaces (i.e. MyKey=My\ Value) |
Issue #, if available:
Description of changes:
Checklist:
make prpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.