fix(package): migrator: index_of subshell issue
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
pkgs.runCommand "test-${name}" {} ''
|
||||
if ! [ -f ${./test + "/${name}" + /run.sh} ]; then
|
||||
echo no run.sh in test/${name}
|
||||
exit 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$out"
|
||||
@@ -35,7 +35,7 @@
|
||||
mkPgTest = testName: testDrv: pkgs.runCommand "migrator-test-${testName}"
|
||||
{
|
||||
nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused ];
|
||||
buildInputs = [ migrator pkgs.postgresql ];
|
||||
buildInputs = [ pkgs.which migrator pkgs.postgresql ];
|
||||
} ''
|
||||
${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log}
|
||||
test=${testDrv}
|
||||
|
||||
17
test/package/migrator/test/function-generate-word.sh
Normal file
17
test/package/migrator/test/function-generate-word.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
# shellcheck disable=SC2034
|
||||
AS_LIBRARY=
|
||||
# shellcheck disable=SC1090
|
||||
. "$(which migrator)"
|
||||
|
||||
log notice "test case: ${WHITE}generate word"
|
||||
if ! answer=$(generate_word); then
|
||||
log error "test failed: ${WHITE}error during generate_word call"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$(printf '%s' "$answer" | wc -c)" -ne 6 ]; then
|
||||
log error "test failed: ${WHITE}word length must be 6 chars"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log notice "test passed"
|
||||
47
test/package/migrator/test/function-index-of.sh
Normal file
47
test/package/migrator/test/function-index-of.sh
Normal file
@@ -0,0 +1,47 @@
|
||||
# shellcheck disable=SC2034
|
||||
AS_LIBRARY=
|
||||
# shellcheck disable=SC1090
|
||||
. "$(which migrator)"
|
||||
|
||||
array='item1
|
||||
item2
|
||||
item3
|
||||
item4
|
||||
item5
|
||||
item6
|
||||
item7'
|
||||
|
||||
log notice "test case: ${WHITE}index of"
|
||||
if ! answer=$(index_of "$array" 'item4'); then
|
||||
log error "test failed: ${WHITE}error during index_of call"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
is_number "$answer" >/dev/null || { log error "test failed: ${WHITE}answer not a number"; exit 1; }
|
||||
|
||||
if [ "$answer" -ne 4 ]; then
|
||||
log error "test failed: ${WHITE}wrong answer"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log notice "test case: ${WHITE}error: item not found"
|
||||
if answer=$(index_of "$array" 'item10'); then
|
||||
log error "test failed: ${WHITE} must return an error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log notice "test case: ${WHITE}one element"
|
||||
array='20251104192425-add-info-to-profile'
|
||||
item='20251104192425-add-info-to-profile'
|
||||
|
||||
if ! answer=$(index_of "$array" "$item"); then
|
||||
log error "test failed: ${WHITE}error during index_of call"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$answer" -ne 1 ]; then
|
||||
log error "test failed: ${WHITE}wrong answer"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log notice "test passed"
|
||||
17
test/package/migrator/test/function-migration-list/run.sh
Normal file
17
test/package/migrator/test/function-migration-list/run.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
# shellcheck disable=SC2034
|
||||
AS_LIBRARY=
|
||||
# shellcheck disable=SC1090
|
||||
. "$(which migrator)"
|
||||
|
||||
log notice "test case: ${WHITE}migration list"
|
||||
if ! answer=$(migration_list); then
|
||||
log error "test failed: ${WHITE}error during migration_list call"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$answer" != "20251104192425-add-info-to-profile" ]; then
|
||||
log error "test failed: ${WHITE}unexpected \`migration list\` answer"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log notice "test passed"
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE profile ADD COLUMN info TEXT;
|
||||
@@ -6,3 +6,15 @@ columns() {
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = '"${1};"
|
||||
}
|
||||
|
||||
# is_number(var)
|
||||
is_number() {
|
||||
case "$1" in
|
||||
*[!0-9]*)
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user