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

Set up automated bash tests with bats #1721

Merged
merged 23 commits into from
Jan 17, 2024

Conversation

jotaen4tinypilot
Copy link
Contributor

@jotaen4tinypilot jotaen4tinypilot commented Jan 12, 2024

Resolves #1714.
Related #1710.
Stacked onto #1720.

This PR sets up bash tests with bats, and adds a first test suite for the strip-marker-sections script.

Notes

  • Similar to how we do it with other test files, I put the .bats test file next to the script under test. The directive in .dockerignore removes it from the bundle / .deb file.
  • The build_bash dev script is called “build” for consistency with build_python and build_javascript, even though we technically don’t build something. I’ve created Consolidate naming and responsibility of dev scripts #1716 for us to potentially reconsider this overall.
  • In build_bash, it somehow felt reasonable to me to search all places that are likely to contain .bats files, even though we currently only have them in /opt/tinypilot-privileged/scripts/. I don’t feel strongly about this, though.
  • For running the tests, there theoretically would be an official bats Docker image, however that doesn’t play nicely with our bash files: the docker image doesn’t have a symlink at /bin/bash, so it fails to execute any of our bash scripts that have a #!/bin/bash shebang (which is effectively all of them). We instead would either have to change all our shebangs to the (most portable) #!/usr/bin/env bash shebang, or we just install bats manually like done here (in the Circle conf).
    Review on CodeApprove

@jotaen4tinypilot
Copy link
Contributor Author

@jdeanwallace sorry for the PR/review flood… I’m not blocked by any of them, so no pressure from my side, especially if you want to play around a bit with bats.

@jotaen4tinypilot jotaen4tinypilot changed the title Strip marker sections/2 tests Setup automated bash tests with bats Jan 12, 2024
@jotaen4tinypilot jotaen4tinypilot removed the request for review from jdeanwallace January 15, 2024 11:03
Copy link

codeapprove bot commented Jan 15, 2024

Automated comment from CodeApprove ➜

👀 @jotaen4tinypilot it's your turn, please take a look

Copy link
Contributor

@jdeanwallace jdeanwallace left a comment

Choose a reason for hiding this comment

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

Automated comment from CodeApprove ➜

Approved on CodeApprove
✔️ Approved

Nice, bats looks pretty cool.


👀 @jotaen4tinypilot it's your turn please take a look

@mtlynch mtlynch changed the title Setup automated bash tests with bats Set up automated bash tests with bats Jan 16, 2024
Base automatically changed from strip-marker-sections/1-script to master January 17, 2024 13:50
jotaen4tinypilot added a commit that referenced this pull request Jan 17, 2024
Related #1710.

This PR adds a unified script to remove TinyPilot marker sections from
files. We will [use this script in a subsequent
PR](#1722) to simplify the
corresponding instances in the
[unset-static-ip](https://github.com/tiny-pilot/tinypilot/blob/2e211199a21a2a6c285c5d1d2ff60eff6afa77d4/debian-pkg/opt/tinypilot-privileged/scripts/unset-static-ip#L64-L81)
and
[change-hostname](https://github.com/tiny-pilot/tinypilot/blob/8e99d5a666df12d851b14dd4276e8b95ab958493/debian-pkg/opt/tinypilot-privileged/scripts/change-hostname#L62-L79)
privileged scripts.

## Notes

- Unless someone feels strongly about the [originally mentioned
`remove-tinypilot-lines` script
name](https://github.com/tiny-pilot/tinypilot/issues/1710#:~:text=opt/tinypilot/scripts/-,remove%2Dtinypilot%2Dlines,-%3C%20example.conf)
(or any other name), I thought that `strip-marker-sections` sounded most
expressive.
- I added a comment to the `lib/markers.sh` file, to explain the marker
idea in a bit more detail.
- There will be automated bash tests for this in [a subsequent
PR](#1721).


<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1720"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>

---------

Co-authored-by: Jan Heuermann <[email protected]>
@jotaen4tinypilot jotaen4tinypilot merged commit a141353 into master Jan 17, 2024
13 checks passed
@jotaen4tinypilot jotaen4tinypilot deleted the strip-marker-sections/2-tests branch January 17, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spike project: unit testing for bash scripts
3 participants