mirror of
https://github.com/Ravinou/borgwarehouse
synced 2026-03-14 14:25:46 +01:00
test: ✅ bats versus getStorageUsed.sh
This commit is contained in:
parent
027ccd7c28
commit
893c86dc75
2 changed files with 85 additions and 1 deletions
|
|
@ -1,12 +1,18 @@
|
|||
FROM bash:latest
|
||||
|
||||
RUN apk add --no-cache bash bats git openssl borgbackup jq coreutils
|
||||
RUN apk add --no-cache \
|
||||
bats \
|
||||
openssl \
|
||||
borgbackup \
|
||||
jq \
|
||||
coreutils
|
||||
|
||||
COPY helpers/shells/ /test/scripts/
|
||||
COPY tests/bats/createRepo.bats /test/tests/createRepo.bats
|
||||
COPY tests/bats/deleteRepo.bats /test/tests/deleteRepo.bats
|
||||
COPY tests/bats/updateRepo.bats /test/tests/updateRepo.bats
|
||||
COPY tests/bats/getLastSave.bats /test/tests/getLastSave.bats
|
||||
COPY tests/bats/getStorageUsed.bats /test/tests/getStorageUsed.bats
|
||||
|
||||
RUN chmod +x /test/scripts/*.sh
|
||||
|
||||
|
|
|
|||
78
tests/bats/getStorageUsed.bats
Normal file
78
tests/bats/getStorageUsed.bats
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
setup() {
|
||||
export home="/tmp/borgwarehouse"
|
||||
mkdir -p "${home}/repos/repo1"
|
||||
mkdir -p "${home}/repos/repo2"
|
||||
mkdir -p "${home}/repos/repo3"
|
||||
|
||||
# Create files with different sizes
|
||||
dd if=/dev/zero of="${home}/repos/repo1/file1" bs=1K count=32
|
||||
dd if=/dev/zero of="${home}/repos/repo2/file1" bs=1K count=1156
|
||||
dd if=/dev/zero of="${home}/repos/repo3/file1" bs=1K count=112
|
||||
|
||||
echo "home=${home}" > "${home}/.env"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf /tmp/borgwarehouse
|
||||
}
|
||||
|
||||
@test "Test getStorageUsed.sh returns the size of all repositories in JSON format" {
|
||||
run bash /test/scripts/getStorageUsed.sh
|
||||
|
||||
# Expected output in JSON format with my fake files
|
||||
expected_output='[
|
||||
{
|
||||
"size": 36,
|
||||
"name": "repo1"
|
||||
},
|
||||
{
|
||||
"size": 1160,
|
||||
"name": "repo2"
|
||||
},
|
||||
{
|
||||
"size": 116,
|
||||
"name": "repo3"
|
||||
}
|
||||
]'
|
||||
|
||||
normalized_output=$(echo "$output" | jq .)
|
||||
normalized_expected_output=$(echo "$expected_output" | jq .)
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$normalized_output" == "$normalized_expected_output" ]
|
||||
}
|
||||
|
||||
|
||||
@test "Test getStorageUsed.sh when no repositories exist" {
|
||||
# Delete all repositories
|
||||
rm -rf "${home}/repos"
|
||||
mkdir -p "${home}/repos"
|
||||
|
||||
run bash /test/scripts/getStorageUsed.sh
|
||||
|
||||
normalized_expected_output='[]'
|
||||
normalized_output=$(echo "$output" | jq .)
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$normalized_output" == "$normalized_expected_output" ]
|
||||
}
|
||||
|
||||
@test "Test getStorageUsed.sh with only one repository" {
|
||||
# Keep only one repository
|
||||
rm -rf "${home}/repos/repo2" "${home}/repos/repo3"
|
||||
|
||||
run bash /test/scripts/getStorageUsed.sh
|
||||
|
||||
expected_output='[{"size": 36, "name": "repo1"}]'
|
||||
|
||||
normalized_output=$(echo "$output" | jq .)
|
||||
normalized_expected_output=$(echo "$expected_output" | jq .)
|
||||
|
||||
echo "$normalized_output"
|
||||
echo "$normalized_expected_output"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$normalized_output" == "$normalized_expected_output" ]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue