forked from hinterland/hearth
0ec8e910a0
Move postgres-init-hectic-inheritance test (13 cases) to migrator/init-hectic-bundle since the bundle is now applied by `migrator init` instead of `postgres-init`. Drop init-migrator-with-inherits since `--inherits` is now a deprecation warning, not an error. Add db-tool hydrate-hook test (5 cases) covering --no-hook skip, default apply, idempotency, and HECTIC_DOTENV_FILE. Augment init-migrator with hectic.version and hectic.secret table assertions.
65 lines
1.6 KiB
Bash
65 lines
1.6 KiB
Bash
#!/bin/dash
|
|
|
|
HECTIC_NAMESPACE=test-init-migrator
|
|
|
|
### CASE 1
|
|
log notice "test case: ${WHITE}dry run"
|
|
|
|
if ! migration_table_sql="$(migrator init --dry-run)"; then
|
|
log error "test failed: ${WHITE}error on migration table init dry run"
|
|
exit 1
|
|
fi
|
|
|
|
### CASE 3
|
|
log notice "test case: ${WHITE}error: not provided --db-url"
|
|
set +e
|
|
migrator init
|
|
error_code=$?
|
|
set -e
|
|
|
|
if [ "$error_code" = 0 ]; then
|
|
log error "test failed: ${WHITE}no error handler"
|
|
exit 1
|
|
elif [ "$error_code" != 3 ]; then
|
|
log error "test failed: ${WHITE}unexpected error code"
|
|
exit 1
|
|
fi
|
|
|
|
### CASE 4
|
|
log notice "test case: ${WHITE}normal"
|
|
|
|
if ! migrator --db-url "$DATABASE_URL" init; then
|
|
log error "test failed: ${WHITE}error on init sql"
|
|
exit 1
|
|
fi
|
|
|
|
if ! psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -c 'SELECT * FROM hectic.migration'; then
|
|
log error "test failed: ${WHITE} tabe hectic.migration was not created"
|
|
exit 1
|
|
fi
|
|
|
|
if ! psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -c 'SELECT * FROM hectic.version'; then
|
|
log error "test failed: ${WHITE} table hectic.version was not created"
|
|
exit 1
|
|
fi
|
|
|
|
if ! psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -c 'SELECT * FROM hectic.secret'; then
|
|
log error "test failed: ${WHITE} table hectic.secret was not created"
|
|
exit 1
|
|
fi
|
|
|
|
### CASE 5
|
|
log notice "test case: ${WHITE}reinit (must just be ignored)"
|
|
|
|
if ! migrator init --db-url "$DATABASE_URL"; then
|
|
log error "test failed: ${WHITE}error on init sql"
|
|
exit 1
|
|
fi
|
|
|
|
if ! psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -c 'SELECT * FROM hectic.migration'; then
|
|
log error "test failed: ${WHITE} tabe hectic.migration was not created"
|
|
exit 1
|
|
fi
|
|
|
|
log notice "test passed"
|