Add CLI integration tests
Not all CLI commands are covered with unit tests and some sort of integration tests need to be added.
This might be useful: https://medium.com/swlh/unit-testing-cli-programs-in-go-6275c85af2e7
Funny enough, I recently released a tool which could solve this problem.
https://github.com/rylandg/shrun
Tests are written as bash in YAML and each one runs in it's own docker container.
---
- test: Simple passing case
foreach:
- PY_VERSION: python2
steps:
- in: echo "Hello guys {PY_VERSION}"
out: |-
Hello guys {PY_VERSION}
- test: Exit code failure (bad-path)
steps:
- in: Hello world
err: |-
bash: line 1: Hello: command not found
exit: 127
- test: Test help (good-path)
steps:
- in: testshrun help
out: |-
You will receive no help with testshrun
- test: Test run (good-path)
steps:
- in: testshrun run
out: |-
Running sucks
- test: Test no command (bad-path)
steps:
- in: testshrun
err: |-
Please provide a command to testshrun
exit: 1
- test: Test unknown command (bad-path)
steps:
- in: testshrun madeup
err: |-
madeup is not a recognized testshrun command
exit: 1
Right now it's mostly tailored for Node CLI but it works out of the box with any CLI. It's just a matter of building the image/mounting a volume with the binary and linking it. It's based on a tool I wrote at my last company for unit/e2e testing our CLI, and was running in production for 2 years or so.
Maybe can use testscript, used in go internal tests --> https://pkg.go.dev/github.com/rogpeppe/[email protected]/testscript#pkg-overview