Merge pull request #226 from rustic-rs/bats

Add bats tests
This commit is contained in:
aawsome 2022-09-22 23:32:26 +02:00 committed by GitHub
commit dcaf3e0921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 17 deletions

View File

@ -7,9 +7,15 @@ on:
name: Tests
jobs:
test_linux:
name: Test on Linux
runs-on: ubuntu-latest
test:
name: Test
runs-on: ${{ matrix.job.os }}
strategy:
matrix:
rust: [stable]
job:
- os: macos-latest
- os: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
@ -21,19 +27,13 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
test_macos:
name: Test on MacOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- name: Cargo build
uses: actions-rs/cargo@v1
with:
profile: minimal
command: build
toolchain: stable
override: true
target: x86_64-apple-darwin
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/cargo@v1
with:
command: test
args: --release
- name: Running bats tests
shell: bash
run: |
./test-bats/run-tests.sh

14
test-bats/run-tests.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# install bats
git clone https://github.com/bats-core/bats-core.git $dir/bats
git clone https://github.com/bats-core/bats-support.git $dir/bats-support
git clone https://github.com/bats-core/bats-assert.git $dir/bats-assert
PATH=$PATH:$dir/bats/bin
# run tests
bats $dir
# clean up
rm -rf $dir/bats
rm -rf $dir/bats-support
rm -rf $dir/bats-assert

68
test-bats/simple.bats Normal file
View File

@ -0,0 +1,68 @@
# Be extra careful to not mess with a user repository
unset RUSTIC_REPOSITORY
unset RUSTIC_PASSWORD
unset RUSTIC_PASSWORD_FILE
unset RUSTIC_PASSWORD_COMMAND
export REPO_DIR="${BATS_TMPDIR%/}/repo"
export RESTORE_DIR="${BATS_TMPDIR%/}/restore"
export RUSTIC_REPOSITORY=$REPO_DIR
export RUSTIC_PASSWORD=test
setup() {
# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
BASEDIR="$( cd $DIR/.. >/dev/null 2>&1 && pwd )"
load "$DIR/bats-support/load"
load "$DIR/bats-assert/load"
# make executables in src/ visible to PATH
RUSTIC="$DIR/../target/release/rustic"
echo $RUSTIC
rm -rf "$REPO_DIR"
run $RUSTIC init
assert_success
assert_output -p "successfully created"
}
teardown () {
chmod -R 700 "$REPO_DIR"
rm -rf "$REPO_DIR"
}
@test "backup and check" {
run $RUSTIC backup $BASEDIR/src
assert_success
assert_output -p "successfully saved"
run $RUSTIC snapshots
assert_success
assert_output -p "1 snapshot(s)"
run $RUSTIC backup $BASEDIR/src
assert_success
assert_output -p "Added to the repo: 0 B"
assert_output -p "successfully saved"
run $RUSTIC snapshots
assert_success
assert_output -p "2 snapshot(s)"
run $RUSTIC check
assert_success
}
@test "backup and restore" {
run $RUSTIC backup $BASEDIR/src
assert_success
assert_output -p "successfully saved"
run $RUSTIC restore latest:$BASEDIR/src $RESTORE_DIR
assert_success
assert_output -p "restore done"
run diff -r $BASEDIR/src $RESTORE_DIR
assert_output ""
}