Implement postgres:import command
This commit is contained in:
12
commands
12
commands
@@ -117,9 +117,15 @@ case "$1" in
|
|||||||
$PLUGIN_COMMAND_PREFIX:import)
|
$PLUGIN_COMMAND_PREFIX:import)
|
||||||
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
|
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
|
||||||
verify_service_name "$2"
|
verify_service_name "$2"
|
||||||
SERVICE="$2"
|
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||||
|
SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||||
|
DATABASE_NAME="$(get_database_name $SERVICE)"
|
||||||
|
PASSWORD=$(cat "$SERVICE_ROOT/PASSWORD")
|
||||||
|
|
||||||
dokku_log_fail "Not yet implemented"
|
if [[ -t 0 ]]; then
|
||||||
|
dokku_log_fail "No data provided on stdin."
|
||||||
|
fi
|
||||||
|
docker exec -i "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_restore -h localhost -cO -d "$DATABASE_NAME" -U postgres -w
|
||||||
;;
|
;;
|
||||||
|
|
||||||
$PLUGIN_COMMAND_PREFIX:logs)
|
$PLUGIN_COMMAND_PREFIX:logs)
|
||||||
@@ -196,7 +202,7 @@ case "$1" in
|
|||||||
$PLUGIN_COMMAND_PREFIX:link <name> <app>, Link the $PLUGIN_SERVICE service to the app
|
$PLUGIN_COMMAND_PREFIX:link <name> <app>, Link the $PLUGIN_SERVICE service to the app
|
||||||
$PLUGIN_COMMAND_PREFIX:unlink <name> <app>, Unlink the $PLUGIN_SERVICE service from the app
|
$PLUGIN_COMMAND_PREFIX:unlink <name> <app>, Unlink the $PLUGIN_SERVICE service from the app
|
||||||
$PLUGIN_COMMAND_PREFIX:export <name>, Export a dump of the $PLUGIN_SERVICE service database
|
$PLUGIN_COMMAND_PREFIX:export <name>, Export a dump of the $PLUGIN_SERVICE service database
|
||||||
$PLUGIN_COMMAND_PREFIX:import <name> <file>, NOT IMPLEMENTED
|
$PLUGIN_COMMAND_PREFIX:import <name> < <file>, Import a dump into the $PLUGIN_SERVICE service database
|
||||||
$PLUGIN_COMMAND_PREFIX:connect <name>, Connect via psql to a $PLUGIN_SERVICE service
|
$PLUGIN_COMMAND_PREFIX:connect <name>, Connect via psql to a $PLUGIN_SERVICE service
|
||||||
$PLUGIN_COMMAND_PREFIX:logs <name> [-t], Print the most recent log(s) for this service
|
$PLUGIN_COMMAND_PREFIX:logs <name> [-t], Print the most recent log(s) for this service
|
||||||
$PLUGIN_COMMAND_PREFIX:restart <name>, Graceful shutdown and restart of the $PLUGIN_SERVICE service container
|
$PLUGIN_COMMAND_PREFIX:restart <name>, Graceful shutdown and restart of the $PLUGIN_SERVICE service container
|
||||||
|
|||||||
37
tests/service_import.bats
Executable file
37
tests/service_import.bats
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
load test_helper
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
export ECHO_DOCKER_COMMAND="false"
|
||||||
|
dokku "$PLUGIN_COMMAND_PREFIX:create" l >&2
|
||||||
|
echo "data" > "$PLUGIN_DATA_ROOT/fake.dump"
|
||||||
|
}
|
||||||
|
|
||||||
|
teardown() {
|
||||||
|
export ECHO_DOCKER_COMMAND="false"
|
||||||
|
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l >&2
|
||||||
|
rm -f "$PLUGIN_DATA_ROOT/fake.dump"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "($PLUGIN_COMMAND_PREFIX:import) error when there are no arguments" {
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:import"
|
||||||
|
assert_contains "${lines[*]}" "Please specify a name for the service"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "($PLUGIN_COMMAND_PREFIX:import) error when service does not exist" {
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:import" not_existing_service
|
||||||
|
assert_contains "${lines[*]}" "service not_existing_service does not exist"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "($PLUGIN_COMMAND_PREFIX:import) error when data is not provided" {
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:import" l
|
||||||
|
assert_contains "${lines[*]}" "No data provided on stdin"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "($PLUGIN_COMMAND_PREFIX:import) success" {
|
||||||
|
export ECHO_DOCKER_COMMAND="true"
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:import" l < "$PLUGIN_DATA_ROOT/fake.dump"
|
||||||
|
password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
|
||||||
|
assert_output "docker exec -i dokku.postgres.l env PGPASSWORD=$password pg_restore -h localhost -cO -d l -U postgres -w"
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user