refactor(`cmdRun`): move server serving into separate function
What?
Refactor cmdRun.run() server spawning based on comments in #5227 reviews
Why?
cmdRun.run() involves many updates and has a high LOC. There is a TODO item on refactoring this function, and this PR aims to address this concern.
Checklist
- [x] I have performed a self-review of my code.
- [ ] I have commented on my code, particularly in hard-to-understand areas.
- [x] I have added tests for my changes.
- [x] I have run linter and tests locally (
make check) and all pass.
Checklist: Documentation (only for k6 maintainers and if relevant)
Please do not merge this PR until the following items are filled out.
- [ ] I have added the correct milestone and labels to the PR.
- [ ] I have updated the release notes: link
- [ ] I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
- [ ] I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable
Related PR(s)/Issue(s)
relate to #5227's comment on moving refactor into a separate PR
@codebien The function doesn't have much to test on, only thing that I can think of would be the difference between addrSetByUser. If there are other things that you think we should include, please let me know!
@codebien Thank you for your review! Sorry for the late follow up since it's the Thanksgiving week here😅. I agree using httptest would be a better approach here. The primary reason that I didn't use one is that httptest.Server is not same as http.Server. In addition, the current testcase shouldn't actually start due to conflicting port address. (Added some comments in the unit test).