feat(legacy): helpers: allow HECTIC_NAMESPACE be empty
This commit is contained in:
@@ -20,11 +20,11 @@
|
|||||||
# When you use NC to reset terminal colors inside log output,
|
# When you use NC to reset terminal colors inside log output,
|
||||||
# it resets back to the log level’s color instead of the terminal default.
|
# it resets back to the log level’s color instead of the terminal default.
|
||||||
|
|
||||||
: "${HLOG_NAMESPACE:="$(basename "$0")"}"
|
: "${HECTIC_NAMESPACE="$(basename "$0")"}"
|
||||||
: "${HLOG_LEVEL:=trace}" # e.g. "info;ns1=debug;ns2=trace"
|
: "${HECTIC_LOG:=trace}" # e.g. "info;ns1=debug;ns2=trace"
|
||||||
|
|
||||||
validate_log_level_spec() {
|
validate_log_level_spec() {
|
||||||
spec=$HLOG_LEVEL
|
spec=$HECTIC_LOG
|
||||||
|
|
||||||
levels="trace debug info notice warn error"
|
levels="trace debug info notice warn error"
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ validate_log_level_spec() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
validate_log_level_spec || { printf "%b%b\n" "${BBLACK}${HLOG_NAMESPACE}> " "${color}invalid HLOG_LEVEL syntax${NC}" "$@" >&2; exit 1; }
|
validate_log_level_spec || { printf "%b%b\n" "${BBLACK}${HECTIC_NAMESPACE}> " "${color}invalid HECTIC_LOG syntax${NC}" "$@" >&2; exit 1; }
|
||||||
|
|
||||||
log_level_num() {
|
log_level_num() {
|
||||||
case $1 in
|
case $1 in
|
||||||
@@ -74,8 +74,8 @@ log_level_num() {
|
|||||||
|
|
||||||
|
|
||||||
log_effective_level() {
|
log_effective_level() {
|
||||||
spec=$HLOG_LEVEL
|
spec=$HECTIC_LOG
|
||||||
ns=$HLOG_NAMESPACE
|
ns=$HECTIC_NAMESPACE
|
||||||
|
|
||||||
default_level=
|
default_level=
|
||||||
ns_level=
|
ns_level=
|
||||||
@@ -133,5 +133,5 @@ log() {
|
|||||||
# shellcheck disable=SC1003
|
# shellcheck disable=SC1003
|
||||||
fmt="$(printf "%s$delimetr" "$@" | sed 's/\\033\[0m/''\'"$color"'/g')"
|
fmt="$(printf "%s$delimetr" "$@" | sed 's/\\033\[0m/''\'"$color"'/g')"
|
||||||
shift
|
shift
|
||||||
printf "%b%b\n" "${BBLACK}${HLOG_NAMESPACE}> " "$color$fmt$NC" >&2
|
printf "%b%b\n" "${BBLACK}${HECTIC_NAMESPACE}> " "$color$fmt$NC" >&2
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#!/bin/dash
|
#!/bin/dash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
if ! command -v psql >/dev/null; then
|
if ! command -v psql >/dev/null; then
|
||||||
log error "Required tool (psql) are not installed."
|
log error "Required tool (psql) are not installed."
|
||||||
exit 127
|
exit 127
|
||||||
@@ -17,6 +19,8 @@ sha256sum() {
|
|||||||
cksum --algorithm=sha256 --untagged "$file" | awk '{printf $1}'
|
cksum --algorithm=sha256 --untagged "$file" | awk '{printf $1}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INHERITS_LIST=
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
log debug "$1"
|
log debug "$1"
|
||||||
case $1 in
|
case $1 in
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
# $out - nix derivation output
|
# $out - nix derivation output
|
||||||
# $test - test and assertion file
|
# $test - test and assertion file
|
||||||
|
|
||||||
|
HECTIC_NAMESPACE=test-laucher
|
||||||
|
export HECTIC_LOG=trace
|
||||||
|
|
||||||
test_derivation="$(basename "$test")"
|
test_derivation="$(basename "$test")"
|
||||||
test_name="${test_derivation#*-*-}"
|
test_name="${test_derivation#*-*-}"
|
||||||
|
|
||||||
@@ -61,6 +64,8 @@ log info "run test ${WHITE}${test_name}${NC}"
|
|||||||
# run test
|
# run test
|
||||||
. "${test}/run.sh"
|
. "${test}/run.sh"
|
||||||
|
|
||||||
|
HECTIC_NAMESPACE=test-laucher
|
||||||
|
|
||||||
log info "finish test pipeline"
|
log info "finish test pipeline"
|
||||||
|
|
||||||
# success marker for Nix
|
# success marker for Nix
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#
|
#!/bin/dash
|
||||||
# first migration
|
|
||||||
#
|
|
||||||
|
|
||||||
|
HECTIC_NAMESPACE=test-create-migration
|
||||||
|
|
||||||
|
log notice "case: ${WHITE}first migration"
|
||||||
if ! migrator create; then
|
if ! migrator create; then
|
||||||
log error "test failed: error on migration creation"
|
log error "test failed: error on migration creation"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -17,10 +18,7 @@ if [ "$(find ./migration -maxdepth 1 -type f | wc -l)" -eq 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
log notice "case: ${WHITE}next migration"
|
||||||
# next migration
|
|
||||||
#
|
|
||||||
|
|
||||||
if ! migrator create; then
|
if ! migrator create; then
|
||||||
log error "test failed: error on migration creation"
|
log error "test failed: error on migration creation"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -31,10 +29,7 @@ if [ "$(find ./migration -maxdepth 1 -type f | wc -l)" -eq 1 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
log notice "case: ${WHITE}migration with custom name"
|
||||||
# migration with custom name
|
|
||||||
#
|
|
||||||
|
|
||||||
if ! migrator create --name test; then
|
if ! migrator create --name test; then
|
||||||
log error "test failed: error on migration creation"
|
log error "test failed: error on migration creation"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -50,10 +45,7 @@ if ! find ./migration -maxdepth 1 -type f -name '*test.sql' \
|
|||||||
log eror "test failed: migration have unexpected name"
|
log eror "test failed: migration have unexpected name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
log notice "case: ${WHITE}migration with custom name that contains space"
|
||||||
# migration with custom name that contains space
|
|
||||||
#
|
|
||||||
|
|
||||||
if ! migrator create --name 'test name'; then
|
if ! migrator create --name 'test name'; then
|
||||||
log error "test failed: error on migration creation"
|
log error "test failed: error on migration creation"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#!/bin/dash
|
#!/bin/dash
|
||||||
|
|
||||||
|
HECTIC_NAMESPACE=test-init-migrator
|
||||||
|
|
||||||
log info "hectic.migration table inheritance"
|
log info "hectic.migration table inheritance"
|
||||||
if ! migration_table_sql="$(migrator --inherits tablename --inherits 'table name' init --dry-run)"; then
|
if ! migration_table_sql="$(migrator --inherits tablename --inherits 'table name' init --dry-run)"; then
|
||||||
log error "test failed: error on migration table init dry run"
|
log error "test failed: error on migration table init dry run"
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
#!/bin/dash
|
||||||
|
|
||||||
|
HECTIC_NAMESPACE=test-migration-list
|
||||||
|
|
||||||
psql "$DATABASE_URL" 'CREATE TABLE profile (
|
psql "$DATABASE_URL" 'CREATE TABLE profile (
|
||||||
id INTEGER,
|
id INTEGER,
|
||||||
username TEXT
|
username TEXT
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
|
#!/bin/dash
|
||||||
|
|
||||||
|
HECTIC_NAMESPACE=test-migration-list
|
||||||
|
|
||||||
#migrator list
|
#migrator list
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
#!/bin/dash
|
||||||
|
|
||||||
|
HECTIC_NAMESPACE=test-missing-psql
|
||||||
|
|
||||||
# remove psql from $PATH
|
# remove psql from $PATH
|
||||||
dir=$(dirname -- "$(command -v psql)")
|
dir=$(dirname -- "$(command -v psql)")
|
||||||
PATH=$(printf '%s' "$PATH" | awk -v RS=: -v ORS=: -v d="$dir" '$0!=d{print}')
|
PATH=$(printf '%s' "$PATH" | awk -v RS=: -v ORS=: -v d="$dir" '$0!=d{print}')
|
||||||
Reference in New Issue
Block a user