Resolve / #244
Resolve #244
What Added/Updated
It now supports the --function and -f switches. If either switch is used in the command sls wsgi manage --function <function_name> or -f <function_name>, it will take that function name. If the specified function is not found, it will throw an error, which is handled in invokeHandler. If neither switch is present, it will return the first function with the condition handler: wsgi_handler.handler, as it did before. Let me know if you need any more changes/help!
Codecov Report
Attention: Patch coverage is 63.63636% with 4 lines in your changes missing coverage. Please review.
Project coverage is 97.55%. Comparing base (
f6eee36) to head (cf4b544).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| index.js | 63.63% | 4 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #261 +/- ##
==========================================
- Coverage 98.18% 97.55% -0.63%
==========================================
Files 5 5
Lines 605 613 +8
Branches 72 75 +3
==========================================
+ Hits 594 598 +4
- Misses 11 15 +4
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hi @ayaan-qadri, Thanks for the PR, great work! Would you be able to add a test case for this feature?
Hello @logandk, I’d be happy to add a test case for this feature, but I need some guidance on how to do it.
You could create a new test case by copying this one: https://github.com/logandk/serverless-wsgi/blob/f6eee3671e84b0c1f790fd5ac0615a68b40c2bc3/index.test.js#L2051
If you change the plugin configuration to contain multiple functions and add your new argument to the invocation, you can verify that the right function is being called (this line: https://github.com/logandk/serverless-wsgi/blob/f6eee3671e84b0c1f790fd5ac0615a68b40c2bc3/index.test.js#L2079)
@logandk , I have never written test cases before. If you could tell me more or provide some resources on how to write them, I might be able to do it.
@ayaan-qadri Essentially, you'll need to write a piece of code that uses the new feature that you've implemented and assert that it does the right thing. Since we're not testing the Serverless framework or AWS, we simply verify that the right Serverless command is going to be issued.
You can run the existing test suite using npm test. Try starting out with copying the existing test case so you'll be adding another test to the suite. You can then modify the inputs to provide two handler functions and the command to include the -f argument. Finally, assert that the right function is being called. I think if you read through the test case I linked, it will make sense to you what is set up, invoked and asserted at the end.
Hey @logandk, I have added Test cases for newly feature where it is checking for below conditions:
- uses the function specified by --function
- uses the function specified by -f
- throws an error when specified function is not found
- falls back to finding wsgi handler when no function is specified
- rejects when no wsgi handler is found and no function is specified
I have added cases for rejection too, Let me know if there are any changes that need to be made.
@ayaan-qadri Awesome, thanks for your effort. It looks like something else is messing up the CI pipeline at the moment (probably an update in ESLint that broke the build). I will look into that soon and get your PR merged.
@logandk Thanks for the update, Let me know if you need anything from my side to get it sorted.