Skip to content
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

tests: make failure message output from bats useful #43

Merged
merged 3 commits into from
Nov 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bats-tests: | bats
PATH=.:$$PATH bats tests/

bats:
PATH=.:$$PATH bats --help >/dev/null || ( \
@PATH=.:$$PATH bats --help >/dev/null || ( \
mkdir tmp; \
git clone https://github.com/sstephenson/bats tmp/bats; \
ln -s tmp/bats/bin/bats .; \
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,13 @@ snapshot_mnt() {

rm "$TMP_DATES"
}

expected_file() {
echo "$BATS_TMPDIR/snazzer-tests/$(basename \
$BATS_TEST_FILENAME)_${BATS_TEST_NUMBER}${1}.expected"
}

actual_file() {
echo "$BATS_TMPDIR/snazzer-tests/$(basename \
$BATS_TEST_FILENAME)_${BATS_TEST_NUMBER}${1}.actual"
}
31 changes: 17 additions & 14 deletions tests/snazzer-list.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,25 @@ HERE
}

@test "snazzer in PATH" {
local THIS_SNAZZER=$(readlink -f $BATS_TEST_DIRNAME/../snazzer)
local PATH_SNAZZER=$(readlink -f $(which snazzer))

[ -n "$PATH_SNAZZER" ]
[ -n "$THIS_SNAZZER" ]
[ "$PATH_SNAZZER" = "$THIS_SNAZZER" ]
readlink -f $BATS_TEST_DIRNAME/../snazzer > $(expected_file)
readlink -f $(which snazzer) > $(actual_file)
diff -u $(expected_file) $(actual_file)
}

@test "snazzer --list-subvolumes --all [mountpoint]" {
run snazzer --list-subvolumes --all "$MNT"
expected_list_subvolumes_output > $(expected_file)
echo "$output" > $(actual_file)
diff -u $(expected_file) $(actual_file)
[ "$status" = "0" ]
echo "$output" > /tmp/output
echo "$(expected_list_subvolumes_output)" > /tmp/expected
[ "$output" = "$(expected_list_subvolumes_output)" ]
}

@test "snazzer --list-snapshots --all [mountpoint]" {
run snazzer --list-snapshots --all "$MNT"
expected_list_snapshots_output > $(expected_file)
echo "$output" > $(actual_file)
diff -u $(expected_file) $(actual_file)
[ "$status" = "0" ]
[ "$output" = "$(expected_list_snapshots_output)" ]
}

@test "snazzer --list-snapshots --all [mountpoint/subvol]" {
Expand All @@ -66,16 +65,20 @@ HERE

@test "snazzer --list-snapshots [/subvol1]" {
run snazzer --list-snapshots "$MNT/home"
expected_list_snapshots_output | grep "^$MNT/home" > $(expected_file)
echo "$output" > $(actual_file)
diff -u $(expected_file) $(actual_file)
[ "$status" = "0" ]
[ "$output" = "$(expected_list_snapshots_output | grep "^$MNT/home")" ]
}

@test "snazzer --list-snapshots [/subvol1] [/subvol2] [/subvol3]" {
run snazzer --list-snapshots "$MNT/home" "$MNT/srv" "$MNT/var/cache"
expected_list_snapshots_output | \
grep "^$MNT/\(home\|srv\|var/cache\)/\.snapshotz" | \
sort > $(expected_file)
echo "$output" > $(actual_file)
diff -u $(expected_file) $(actual_file)
[ "$status" = "0" ]
[ "$(expected_list_snapshots_output | \
grep "^$MNT/\(home\|srv\|var/cache\)/\.snapshotz" |sort)" = "$output" ]

}

teardown() {
Expand Down
33 changes: 19 additions & 14 deletions tests/snazzer-prune.bats
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ $SNAP"; else THIS=$SNAP; fi
mkfs.btrfs --help
}

@test "snazzer-prune-candidates in PATH" {
local THIS_SNAZZER=$(readlink -f $BATS_TEST_DIRNAME/../snazzer-prune-candidates)
local PATH_SNAZZER=$(readlink -f $(which snazzer-prune-candidates))

[ -n "$PATH_SNAZZER" ]
[ -n "$THIS_SNAZZER" ]
[ "$PATH_SNAZZER" = "$THIS_SNAZZER" ]
@test "snazzer in PATH" {
readlink -f $BATS_TEST_DIRNAME/../snazzer > $(expected_file)
readlink -f $(which snazzer) > $(actual_file)
diff -u $(expected_file) $(actual_file)
}

@test "snazzer --prune --all [mountpoint]" {
Expand All @@ -64,32 +61,40 @@ $SNAP"; else THIS=$SNAP; fi
@test "snazzer --prune --all --force [mountpoint]" {
BEFORE=$(gather_snapshots | sort)
run snazzer --prune --all --force "$MNT"
fake_prune "$BEFORE" > $(expected_file)
gather_snapshots | sort > $(actual_file)
diff -u $(expected_file) $(actual_file)
[ "$status" = "0" ]
[ "$(fake_prune "$BEFORE")" = "$(gather_snapshots | sort)" ]
}

@test "snazzer --prune --all --dry-run [mountpoint]" {
BEFORE=$(gather_snapshots | sort)
run snazzer --prune --all --dry-run "$MNT"
[ "$status" = "0" ]
eval "$output" >/dev/null 2>/dev/null
[ "$(fake_prune "$BEFORE")" = "$(gather_snapshots | sort)" ]
eval "$output"
fake_prune "$BEFORE" > $(expected_file)
gather_snapshots | sort > $(actual_file)
diff -u $(expected_file) $(actual_file)
[ "$status" = "0" ]
}

@test "snazzer --prune --force [subvol]" {
BEFORE=$(gather_snapshots | sort | grep "^$MNT/home/\.snapshotz")
run snazzer --prune --force "$MNT/home"
echo "$BEFORE" | snazzer-prune-candidates --invert > $(expected_file)
gather_snapshots | sort | grep "^$MNT/home/\.snapshotz" > $(actual_file)
diff -u $(expected_file) $(actual_file)
[ "$status" = "0" ]
[ "$(echo "$BEFORE" | snazzer-prune-candidates --invert)" = \
"$(gather_snapshots | sort | grep "^$MNT/home/\.snapshotz")" ]
}

@test "snazzer --prune --force [subvol1] [subvol2] [subvol3]" {
BEFORE=$(gather_snapshots | sort | grep "^$MNT/\(home\|srv\|var/cache\)/\.snapshotz")
run snazzer --prune --force "$MNT/home" "$MNT/srv" "$MNT"
fake_prune "$BEFORE" > $(expected_file)
gather_snapshots | sort | \
grep "^$MNT/\(home\|srv\|var/cache\)/\.snapshotz" > $(actual_file)
diff -u $(expected_file) $(actual_file)
[ "$status" = "0" ]
[ "$(fake_prune "$BEFORE")" = "$(gather_snapshots | sort | \
grep "^$MNT/\(home\|srv\|var/cache\)/\.snapshotz")" ]
}

teardown() {
Expand Down
Loading