-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add isolated bats test suite for main.sh #37
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f7d0f84
feat: make main.sh sourceable with overridable paths for tests
hllvc 9440d3d
feat: vendor bats-core as test framework
hllvc 23ef47c
feat: add bats test suite for main.sh
hllvc bf62488
feat: add test Makefile and CI workflow
hllvc 8774d00
fix: resolve sonarcloud findings in test suite
hllvc 93373da
feat: remove integration test tier, keep unit and smoke
hllvc 9b61133
feat: modernize bash idioms and add shellcheck idiom gate
hllvc bfd83d8
docs: refresh README and scope CI to PRs against main
hllvc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: test | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # bats lives in test/lib as a submodule; lint itself does not need it, but | ||
| # checking out submodules keeps every job consistent and cheap. | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| submodules: recursive | ||
| - name: Install shellcheck | ||
| run: sudo apt-get update && sudo apt-get install -y shellcheck | ||
| - name: Lint | ||
| run: make lint | ||
|
|
||
| unit-smoke: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # REQUIRED: bats-core/support/assert are git submodules under test/lib. | ||
| # Without submodules: recursive the runner binary is absent and the suite | ||
| # cannot start. | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| submodules: recursive | ||
| # ubuntu-latest ships GNU bash 5 as the default shell, which is all the | ||
| # unit + smoke tiers require. No systemd, no docker, no bats install | ||
| # (it is vendored). | ||
| - name: Unit + smoke tiers | ||
| run: make test-unit test-smoke |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [submodule "test/lib/bats-core"] | ||
| path = test/lib/bats-core | ||
| url = https://github.com/bats-core/bats-core.git | ||
| [submodule "test/lib/bats-support"] | ||
| path = test/lib/bats-support | ||
| url = https://github.com/bats-core/bats-support.git | ||
| [submodule "test/lib/bats-assert"] | ||
| path = test/lib/bats-assert | ||
| url = https://github.com/bats-core/bats-assert.git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Shared shellcheck config for main.sh and the test suite. | ||
| # Picked up automatically by `make lint`, CI, and editor integrations. | ||
|
|
||
| # Modern Bash idioms — keep the codebase on the current conventions: | ||
| enable=require-double-brackets # prefer [[ ]] over [ ] (SC2292) | ||
| enable=deprecate-which # prefer `command -v` over `which` | ||
|
|
||
| # `data` (api_call) and `SSM_BIN_NAME` (detect_ssm_service) are globals set for | ||
| # other functions / external readers, not unused assignments. | ||
| disable=SC2034 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # main.sh test harness — see test/README.md for the contract. | ||
| # bats-core and its helper libs are vendored as git submodules under test/lib/; | ||
| # nothing is installed at runtime. Run `git submodule update --init --recursive` | ||
| # after a fresh clone. | ||
|
|
||
| BATS := ./test/lib/bats-core/bin/bats | ||
| TIERS := test/unit test/smoke | ||
|
|
||
| .DEFAULT_GOAL := help | ||
|
|
||
| .PHONY: help test test-unit test-smoke lint | ||
|
|
||
| help: ## List the available targets | ||
| @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ | ||
| | awk 'BEGIN {FS = ":.*?## "} {printf " \033[36m%-16s\033[0m %s\n", $$1, $$2}' | ||
|
|
||
| test: ## Run every tier (unit + smoke), scoped to the tier dirs | ||
| $(BATS) --recursive $(TIERS) | ||
|
|
||
| test-unit: ## Run the unit tier (pure functions, no I/O) | ||
| $(BATS) --recursive test/unit | ||
|
|
||
| test-smoke: ## Run the smoke tier (subprocess CLI-contract) | ||
| $(BATS) --recursive test/smoke | ||
|
|
||
| SHELL_SOURCES := main.sh test/mocks/bin/* test/helpers/*.bash | ||
|
|
||
| lint: ## shellcheck correctness + modern-idiom gate (config in .shellcheckrc) | ||
| # General correctness (warnings and up); SC2034 is disabled in .shellcheckrc. | ||
| shellcheck --severity=warning main.sh | ||
| shellcheck test/mocks/bin/* | ||
| shellcheck test/helpers/*.bash | ||
| # Idiom gate: enforce [[ ]] over [ ] (SC2292) and command substitution over | ||
| # backticks (SC2006) across every shell source, regardless of severity. | ||
| shellcheck --include=SC2292,SC2006 $(SHELL_SOURCES) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.