test(ingest): add tests for index-append.py --remove
This commit is contained in:
parent
990118de71
commit
8082bc3003
1 changed files with 44 additions and 0 deletions
44
tests/index-remove.bats
Normal file
44
tests/index-remove.bats
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
# tests/index-remove.bats — index-append.py --remove mode.
|
||||||
|
setup() {
|
||||||
|
load 'helpers'
|
||||||
|
export GENOMES_ROOT="${BATS_TEST_TMPDIR}"
|
||||||
|
g_src="$(make_fixture_genome)"; export g="$g_src"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "index --remove: deletes the matching entry, keeps the others" {
|
||||||
|
cd "$g"
|
||||||
|
python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/a]] — A. `maturity: draft`'
|
||||||
|
python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/b]] — B. `maturity: draft`'
|
||||||
|
grep -q 'sources/a' wiki/index.md
|
||||||
|
grep -q 'sources/b' wiki/index.md
|
||||||
|
|
||||||
|
run python3 "$SKILL_SCRIPTS/index-append.py" --remove 'sources/a'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
! grep -q '\[\[sources/a\]\]' wiki/index.md
|
||||||
|
grep -q 'sources/b' wiki/index.md
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "index --remove: idempotent when the entry is absent" {
|
||||||
|
cd "$g"
|
||||||
|
run python3 "$SKILL_SCRIPTS/index-append.py" --remove 'sources/does-not-exist'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *'nothing to remove'* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "index --remove: bumps last_updated" {
|
||||||
|
cd "$g"
|
||||||
|
python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/a]] — A. `maturity: draft`'
|
||||||
|
# set last_updated to an old date, then remove and check it moved
|
||||||
|
sed -i 's/^last_updated:.*/last_updated: 2000-01-01/' wiki/index.md
|
||||||
|
run python3 "$SKILL_SCRIPTS/index-append.py" --remove 'sources/a'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
! grep -q '2000-01-01' wiki/index.md
|
||||||
|
grep -q "last_updated: $(date +%F)" wiki/index.md
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "index --remove: rejects passing both --entry and --remove" {
|
||||||
|
cd "$g"
|
||||||
|
run python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/a]] — x' --remove 'sources/a'
|
||||||
|
[ "$status" -eq 2 ]
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue