2023-02-22 09:26:04 +00:00
|
|
|
load "${REPOSITORY_ROOT}/test/helper/setup"
|
|
|
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
2022-01-10 00:12:07 +00:00
|
|
|
|
2022-05-05 10:58:00 +00:00
|
|
|
TEST_FILE='/tmp/sedfile-test.txt'
|
2023-02-22 09:26:04 +00:00
|
|
|
BATS_TEST_NAME_PREFIX='[sedfile] '
|
|
|
|
CONTAINER_NAME='dms-test_sedfile'
|
2022-05-05 10:58:00 +00:00
|
|
|
|
2022-01-10 00:12:07 +00:00
|
|
|
# prepare tests
|
|
|
|
function setup_file() {
|
2023-02-22 09:26:04 +00:00
|
|
|
_init_with_defaults
|
|
|
|
_common_container_setup
|
2022-05-05 10:58:00 +00:00
|
|
|
}
|
2022-01-10 00:12:07 +00:00
|
|
|
|
2023-02-22 09:26:04 +00:00
|
|
|
function teardown_file() { _default_teardown ; }
|
|
|
|
|
2022-05-05 10:58:00 +00:00
|
|
|
function setup() {
|
2022-01-10 00:12:07 +00:00
|
|
|
# create test file
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container_bash "echo 'foo bar' >'${TEST_FILE}'"
|
2022-01-10 00:12:07 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 09:26:04 +00:00
|
|
|
@test 'checking parameter count' {
|
|
|
|
_run_in_container sedfile
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_failure
|
2022-04-02 13:52:30 +00:00
|
|
|
assert_output --partial 'At least three parameters must be given'
|
2022-01-10 00:12:07 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 09:26:04 +00:00
|
|
|
@test 'checking substitute success' {
|
2022-01-10 00:12:07 +00:00
|
|
|
# change 'bar' to 'baz'
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container sedfile -i 's|bar|baz|' "${TEST_FILE}"
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_success
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_output ''
|
2022-01-10 00:12:07 +00:00
|
|
|
|
|
|
|
# file modified?
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container cat "${TEST_FILE}"
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_success
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_output 'foo baz'
|
2022-01-10 00:12:07 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 09:26:04 +00:00
|
|
|
@test 'checking sedfile substitute failure (on first container start)' {
|
2022-05-05 10:58:00 +00:00
|
|
|
# delete marker
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container rm '/CONTAINER_START'
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_success
|
|
|
|
|
|
|
|
# try to change 'baz' to 'something' and fail
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container sedfile -i 's|baz|something|' "${TEST_FILE}"
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_failure
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_output --partial "No difference after call to 'sed' in 'sedfile' (sed -i s|baz|something| /tmp/sedfile-test.txt)"
|
2022-01-10 00:12:07 +00:00
|
|
|
|
|
|
|
# file unchanged?
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container cat "${TEST_FILE}"
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_success
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_output 'foo bar'
|
2022-01-10 00:12:07 +00:00
|
|
|
|
2022-05-05 10:58:00 +00:00
|
|
|
# recreate marker
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container touch '/CONTAINER_START'
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_success
|
|
|
|
}
|
2022-01-10 00:12:07 +00:00
|
|
|
|
2023-02-22 09:26:04 +00:00
|
|
|
@test 'checking sedfile silent failure on substitute (when DMS was restarted)' {
|
2022-05-05 10:58:00 +00:00
|
|
|
# try to change 'baz' to 'something' and fail silently
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container sedfile -i 's|baz|something|' "${TEST_FILE}"
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_success
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_output ''
|
2022-01-10 00:12:07 +00:00
|
|
|
|
|
|
|
# file unchanged?
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container cat "${TEST_FILE}"
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_success
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_output 'foo bar'
|
2022-01-10 00:12:07 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 09:26:04 +00:00
|
|
|
@test 'checking sedfile substitude failure (strict)' {
|
2022-05-05 10:58:00 +00:00
|
|
|
# try to change 'baz' to 'something' and fail
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container sedfile --strict -i 's|baz|something|' "${TEST_FILE}"
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_failure
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_output --partial "No difference after call to 'sed' in 'sedfile' (sed -i s|baz|something| /tmp/sedfile-test.txt)"
|
2022-01-10 00:12:07 +00:00
|
|
|
|
|
|
|
# file unchanged?
|
2023-02-22 09:26:04 +00:00
|
|
|
_run_in_container cat "${TEST_FILE}"
|
2022-01-10 00:12:07 +00:00
|
|
|
assert_success
|
2022-05-05 10:58:00 +00:00
|
|
|
assert_output 'foo bar'
|
2022-01-10 00:12:07 +00:00
|
|
|
}
|