Files
manjaro-sway-mirror-arm-patch/spec/patch-manjaro-sway-mirror-for-arm_spec.sh
2023-06-08 12:36:39 +02:00

80 lines
2.9 KiB
Bash

#!/bin/env sh
Describe "patch-manjaro-sway-mirror-for-arm.sh - Test Suite"
test_root=$(mktemp -d)
target_file="${test_root}/usr/bin/manjaro-sway-mirrors"
custom_file="${target_file}-custom"
custom_replace_pattern="replaced"
# shellcheck disable=SC2016
test_content='curl -s "https://pkg.manjaro-sway.download/$(pacman-mirrors -G)/testing"'
setup_test_data() {
export MSMAP_TARGET_ROOT="${test_root}"
mkdir -p "${test_root}/usr/bin"
echo "${test_content}" > "${target_file}"
cp -f "${target_file}" "${custom_file}"
}
teardown_test_data() {
unset MSMAP_TARGET_ROOT
rm -rf "${test_root}"
}
BeforeEach 'setup_test_data'
AfterEach 'teardown_test_data'
Describe "Help message"
It "should display the usage information"
When run src/patch-manjaro-sway-mirror-for-arm.sh --help
The output should include "Usage: patch-manjaro-sway-mirror-for-arm.sh"
The status should be success
End
End
Describe "Dry run"
It "should perform a dry run without modifying the target file"
When run src/patch-manjaro-sway-mirror-for-arm.sh --dry-run
The status should be success
The contents of file "${target_file}" should equal "${test_content}"
# shellcheck disable=SC2016
The output should equal "sed -i 's|\\\$(pacman-mirrors -G)|\\\$(pacman-mirrors -G \| sed \\\"s/^arm-//\\\")|g' '${target_file}'
curl -s \"https://pkg.manjaro-sway.download/\$(pacman-mirrors -G | sed \"s/^arm-//\")/testing\""
End
End
Describe "Default values"
It "should modify the target file with default values"
When run src/patch-manjaro-sway-mirror-for-arm.sh
The output should equal ""
The status should be success
The contents of file "${target_file}" should equal "curl -s \"https://pkg.manjaro-sway.download/\$(pacman-mirrors -G | sed \"s/^arm-//\")/testing\""
End
End
Describe "Custom target file and replace pattern"
It "should modify the custom target file with the provided replace pattern"
When run src/patch-manjaro-sway-mirror-for-arm.sh "${custom_file}" -r "${custom_replace_pattern}"
The output should equal ""
The status should be success
The contents of file "${target_file}" should equal "${test_content}"
The contents of file "$custom_file" should equal "curl -s \"https://pkg.manjaro-sway.download/replaced/testing\""
End
End
Describe "Positional arguments"
custom_search_pattern="testing"
It "should modify the target file with positional arguments"
When run src/patch-manjaro-sway-mirror-for-arm.sh "$custom_file" "${custom_search_pattern}" "${custom_replace_pattern}"
The output should equal ""
The status should be success
The contents of file "${target_file}" should equal "${test_content}"
The contents of file "$custom_file" should equal "curl -s \"https://pkg.manjaro-sway.download/\$(pacman-mirrors -G)/replaced\""
End
End
End