feat: add bats unit tests for lib/github-common.sh#41
Merged
Conversation
15 tests covering the shared library's pure-logic functions and gh_api sentinel returns — all testable without a real GitHub token. - validate_slug: valid (alphanumeric/hyphen/underscore) and invalid (space/slash/dot/metachar) inputs - require_env_var: unset, empty, and set variable cases - require_command: found and not-found cases - gh_api: __404__, __422__ sentinels and 200 body pass-through (curl is mocked per-test via a temporary PATH-prepended binary) Also adds a 'test' job to ci.yml that installs bats and runs the suite. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tions test_common.bats (29 tests): - Add err, configure_gh_auth, validate_token, validate_github_token URL warning, get_repo_page_count (with/without Link header), gh_api_paginate (404, 422, single-page) - Upgrade _mock_curl to use universal mock_curl.sh (handles both gh_api stdout mode and gh_api_paginate/validate_token -o/-D file mode) tests/mock_curl.sh: - Universal drop-in curl mock; response data via env vars (MOCK_CURL_CODE, MOCK_CURL_BODY, MOCK_CURL_LINK) — no quoting issues with JSON bodies test_script_validation.bats (62 tests): - Every script: missing required env vars exit 1 in the correct order - Arg parsing: --help exits 0, unknown args exit 1, recognised flags (--dry-run, --type) don't trigger Unknown argument errors - Invalid enum values: --type, DEPENDABOT_REASON, SECRET_SCANNING_RESOLUTION - github-import-repo: non-GitHub GIT_URL_PREFIX exits 1 (security guard) - github-repo-permissions-report: missing -r exits 1 ci.yml: run bats tests/ (all bats files) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-instructions.md - Replaced the placeholder Testing section in AGENTS.md with full bats suite documentation: test files table, what to test per script, and the mock_curl.sh pattern with a code example - Added step 7 (write tests) to the Adding a New Script checklist in AGENTS.md; renumbered subsequent steps - Updated CI/CD bullet to mention the bats test job - Updated Maintenance Matrix 'Add a new script' row to include tests/test_script_validation.bats - Mirrored all changes in .github/copilot-instructions.md: expanded Adding New Scripts checklist with mandatory test step, replaced single-line Testing Approach with table + requirement prose Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add Unit Tests subsection after Pre-commit Hooks: install instructions for macOS/Ubuntu, bats tests/ run command, test-file table, note that CI runs bats on every PR - Update Contributing checklist: add 'add test section to test_script_validation.bats' to step 3, add step 6 'bats tests/' before the test-on-non-prod-org step Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds 15 unit tests for the shared library functions in
lib/github-common.sh— the highest-leverage target since it's sourced by every script.Tests added (
tests/test_common.bats)validate_slugrequire_env_varrequire_commandgh_api__404__on 404,__422__on 422, body on 200No real network calls —
curlis mocked per-test via a temporary binary prepended to PATH.CI
Adds a
testjob to.github/workflows/ci.ymlthat installs bats and runs the suite on every PR.