Skip to content
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

test: Refactor tests to use env instead of opt vars #672

Merged
merged 6 commits into from
Feb 13, 2022
Merged

test: Refactor tests to use env instead of opt vars #672

merged 6 commits into from
Feb 13, 2022

Conversation

martinezpl
Copy link
Contributor

Hey,
I wanted to work on a different feature, but to my surprise most of the tests were failing on an unmodified fork. That's because I was using latest version of Serverless and the tests are full of CLI arguments which are now deprecated. Here's a small trick that makes the tests valid again without having to modify all the functions.

I also think getting rid of the python2.7 tests is a good idea.

@pgrzesik
Copy link
Contributor

pgrzesik commented Feb 11, 2022

Hey @martinezpl, thanks for PR submission - it looks like the CI builds are failing - could you please look into that?

@martinezpl
Copy link
Contributor Author

Whoops, sorry, fixed.

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

thanks @martinezpl - I have one suggestion that could make the solution cleaner (imo), let me know what do you think

test.js Outdated
let envVars = { SLS_DEBUG: 't' };
if (cmd == 'sls') {
// convert deprecated CLI arguments to env vars
const argsCopy = [...args];
Copy link
Contributor

Choose a reason for hiding this comment

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

While this is a working solution, I think it would be better to explicitly pass these options as env to sls created with mkCommand utility. What do you think? For example, invocation could look like this:

sls(['package'], {env: {DOCKERIZE_PIP: true, SLIM: true}});

instead of

sls(['--dockerizePip=true', '--slim=true', 'package']);

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 totally agree, but I'd need to spend time on manually rewriting each function... ;/
Maybe I'll come up with a script to parse these lines for me if you insist on this - if you don't, then I think it's gonna be good to merge after I push the lint correction.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @martinezpl - I think we will need to address it anyway - if you won't have time to address it, I can give it a try, I'd rather not merge in code that needs to be changed soon. Let me know 💯

Copy link
Contributor Author

@martinezpl martinezpl Feb 12, 2022

Choose a reason for hiding this comment

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

Done, turned out to be a pretty quick task with a bit of regex.

-edit
I've run into some problems after implementing the convention you suggested - the sls command threw NOENT errors, that's why the code in my commit differs.

However now I realised I just cut out the way to pass options different than 'env'. Seems like it hasn't been used so far, but it's probably better to have it. Let me correct.

-edit2
Done!

@martinezpl martinezpl requested a review from pgrzesik February 12, 2022 13:13
Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Thanks a lot @martinezpl 🙇

@pgrzesik pgrzesik added the tests label Feb 13, 2022
@pgrzesik pgrzesik changed the title Fix for broken tests in sls^3.0 - converting deprecated CLI arguments to env vars test: Refactor tests to use env instead of opt vars Feb 13, 2022
@pgrzesik pgrzesik merged commit ec84948 into serverless:master Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants