Add bats-core unit tests

Aperta
#15 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bash, github-actions, shell
Ambito
ci-cd, testing, tooling

Direzione di ricerca

Start by reading the reusable functions in src/scripts/lib/*.sh and the existing jobs in .github/workflows/test-runner.yaml; inspect scripts/check-shellcheck.sh for the current target set. Add isolated Bats tests under tests/ with sandboxed setup and stub binaries, then add the unit test CI job and update the quality globs and README Testing section. Done means the specified library functions and shellcheck target selection have tests, bats tests/ runs locally and in CI, and the docs explain the unit and container integration split.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

tests

Context

~80 bash scripts with zero unit tests. src/scripts/lib/*.sh define sourced, reusable functions — ideal unit targets — but the only automated coverage is slow, container-based integration (test-runner.yaml cli/config/full/master jobs) plus post-run scripts/validate*.sh gates.

Spec

1. Tooling
  • Install bats-core locally (release tarball) plus bats-support / bats-assert / bats-file.
  • Layout: tests/lib/<name>.bats mirroring src/scripts/lib/, tests/helpers/setup.bash, tests/stubs/ (fake binaries), tests/fixtures/.
2. Unit-test targets (source lib, call in isolation)
  • src/scripts/lib/dnf-repo-add.sh — import_rpm_key_if_missing, install_repo_file_from_url, setup_copr_repo, setup_rpmfusion_free_repo, setup_docker_repo, setup_brave_repo, setup_nodesource_repo, setup_repo_from_manifest_line: stub rpmkeys/dnf/curl; assert repo-file and keyring outcomes and idempotency.
  • src/scripts/lib/dnf-repos.sh — enable_copr_if_available: stub dnf copr enable.
  • src/scripts/lib/dnf-packages.sh — append_packages_from_file, install_dnf_packages_individually, install_dnf_packages_from_file(s), install_collected_*: stub dnf; fixture lists; assert args and best-effort continuation.
  • src/scripts/lib/dnf-maintain.sh — dnf_maintain_update, dnf_maintain_upgrade, dnf_maintain_cleanup: stub dnf; assert subcommand order.
  • src/scripts/lib/flatpak-install.sh — install_flatpak_if_missing, install_flatpaks_from_file: stub flatpak; assert flathub remote args.
  • src/scripts/lib/dotfiles-install.sh — expand_home_path, copy_dotfile_file, link_dotfiles_xdg_config_dirs, install_dotfiles_from_manifest: sandbox HOME/XDG_CONFIG_HOME.
  • src/scripts/lib/run.sh, parallel.sh, zsh-login.sh, git-submodules.sh, gnome-session.sh — same pattern.
  • scripts/check-shellcheck.sh — assert intended target set (fixture clean/dirty script).
3. Approach
  • setup() per test: mktemp -d sandbox; export HOME, TEMP_DIR, PROJECT_ROOT into it; prepend tests/stubs/ to PATH. No network, no real system mutation.
  • Exclude leaf installers (src/scripts/install/**, incl. flatpaks.sh, bruno.sh, zoom.sh, …) — already exercised by container CI.
4. CI
  • Add a fast unit-tests job (ubuntu-latest, no docker) to .github/workflows/test-runner.yaml: checkout → setup bats → bats tests/. Use bats-core/bats-action pinned to the full-length commit SHA of its latest release (repo pinning convention), using its lib-path output as BATS_LIB_PATH.
  • Extend shellcheck/shfmt globs so tests/** is covered by the existing quality gate.
5. Docs
  • README "Testing" section: local bats install + bats tests/; unit vs. container-integration split.

Out of scope

Leaf script side effects, container integration jobs, scripts/validate*.sh gates.

Lingua principale
Shell
Stelle
1
Fork
0
Merge medio
1h 7m
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di garretpatten/fedora-setup-scripts

Tutte le issue di garretpatten/fedora-setup-scripts

Issue simili

Altre issue su Shell/Bash

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.