Wire up "rm" subcommand
This commit is contained in:
parent
9c7492bed5
commit
61188b6453
|
@ -0,0 +1,44 @@
|
|||
#!/bin/bash
|
||||
TMP_ZETTELKASTEN=""
|
||||
|
||||
setup() {
|
||||
source ../zk
|
||||
|
||||
TMP_ZETTELKASTEN="$(mktemp -d)"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf "$TMP_ZETTELKASTEN"
|
||||
}
|
||||
|
||||
test__zk_rm_gives_error_when_no_zettel_id_given() {
|
||||
# shellcheck disable=SC2016
|
||||
#fake rm 'echo'
|
||||
|
||||
assert_status_code 1 '_zk_rm'
|
||||
}
|
||||
|
||||
test__zk_rm_gives_error_when_nonexistent_zettel_id_given() {
|
||||
export ZKDIR="$TMP_ZETTELKASTEN"
|
||||
zettel_id="11111111111111"
|
||||
|
||||
assert_status_code 2 '_zk_rm $zettel_id'
|
||||
}
|
||||
|
||||
test__zk_rm_succeeds_when_existent_zettel_id_given() {
|
||||
export ZKDIR="$TMP_ZETTELKASTEN"
|
||||
zettel_id="11111111111111"
|
||||
touch "$ZKDIR/$zettel_id"
|
||||
|
||||
assert_status_code 0 '_zk_rm 11111111111111'
|
||||
}
|
||||
|
||||
test__zk_rm_removes_file_when_existent_zettel_id_given() {
|
||||
export ZKDIR="$TMP_ZETTELKASTEN"
|
||||
zettel_id="11111111111111"
|
||||
echo testing >> "$ZKDIR/$zettel_id"
|
||||
|
||||
_zk_rm "$zettel_id"
|
||||
|
||||
assert_fails 'test -f "$ZKDIR/$zettel_id"'
|
||||
}
|
|
@ -52,6 +52,15 @@ test_get_command_returns_edit_for_substring() {
|
|||
done
|
||||
}
|
||||
|
||||
test_get_command_returns_edit_for_substring() {
|
||||
expected="rm"
|
||||
|
||||
for arg in r rm; do
|
||||
result="$(get_command "$ZKCOMMANDS" "$arg")"
|
||||
assert_equals "$expected" "$result"
|
||||
done
|
||||
}
|
||||
|
||||
test_get_command_does_not_return_match_unless_at_start_of_command_string() {
|
||||
commands="delete"
|
||||
expected=""
|
||||
|
|
|
@ -48,6 +48,18 @@ test_main_calls_edit_when_edit_command_passed() {
|
|||
assert_equals "$expected" "$result"
|
||||
}
|
||||
|
||||
test_main_calls_rm_when_rm_command_passed() {
|
||||
fake check_zkdir test
|
||||
expected="_zk_rm"
|
||||
fake get_command 'echo rm'
|
||||
fake _zk_rm "echo $expected"
|
||||
|
||||
result="$(main)"
|
||||
|
||||
assert_equals "$expected" "$result"
|
||||
}
|
||||
|
||||
|
||||
test_main_errors_if_unrecognized_command_given() {
|
||||
fake check_zkdir test
|
||||
fake get_command echo ""
|
||||
|
|
Loading…
Reference in New Issue