From 153b1b826eee3c616ae84e1fb20ca1d616e5cc73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Fri, 11 Sep 2015 02:09:17 +0200 Subject: [PATCH] Implement `postgres:clone` command --- commands | 10 +++++++--- tests/service_clone.bats | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100755 tests/service_clone.bats diff --git a/commands b/commands index eb82394..5561c27 100755 --- a/commands +++ b/commands @@ -176,10 +176,14 @@ case "$1" in $PLUGIN_COMMAND_PREFIX:clone) [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service" + [[ -z $3 ]] && dokku_log_fail "Please specify a name for the new service" verify_service_name "$2" SERVICE="$2" - - dokku_log_fail "Not yet implemented" + NEW_SERVICE="$3" + dokku "$PLUGIN_COMMAND_PREFIX:create" "$NEW_SERVICE" + dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE" + dokku "$PLUGIN_COMMAND_PREFIX:export" "$SERVICE" | dokku "$PLUGIN_COMMAND_PREFIX:import" "$NEW_SERVICE" > /dev/null 2>&1 || true + dokku_log_info1 "Done" ;; $PLUGIN_COMMAND_PREFIX:expose) @@ -208,7 +212,7 @@ case "$1" in $PLUGIN_COMMAND_PREFIX:restart , Graceful shutdown and restart of the $PLUGIN_SERVICE service container $PLUGIN_COMMAND_PREFIX:info , Print the connection information $PLUGIN_COMMAND_PREFIX:list, List all $PLUGIN_SERVICE services - $PLUGIN_COMMAND_PREFIX:clone , NOT IMPLEMENTED + $PLUGIN_COMMAND_PREFIX:clone , Create container then copy data from into $PLUGIN_COMMAND_PREFIX:expose [port], Expose a $PLUGIN_SERVICE service on custom port if provided (random port otherwise) $PLUGIN_COMMAND_PREFIX:unexpose , Unexpose a previously exposed $PLUGIN_SERVICE service $PLUGIN_COMMAND_PREFIX:start , Start a previously stopped $PLUGIN_SERVICE service diff --git a/tests/service_clone.bats b/tests/service_clone.bats new file mode 100755 index 0000000..658eb24 --- /dev/null +++ b/tests/service_clone.bats @@ -0,0 +1,42 @@ +#!/usr/bin/env bats +load test_helper + +setup() { + export ECHO_DOCKER_COMMAND="false" + dokku "$PLUGIN_COMMAND_PREFIX:create" l >&2 +} + +teardown() { + export ECHO_DOCKER_COMMAND="false" + dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l >&2 +} + +@test "($PLUGIN_COMMAND_PREFIX:clone) error when there are no arguments" { + run dokku "$PLUGIN_COMMAND_PREFIX:clone" + assert_contains "${lines[*]}" "Please specify a name for the service" +} + +@test "($PLUGIN_COMMAND_PREFIX:clone) error when service does not exist" { + run dokku "$PLUGIN_COMMAND_PREFIX:clone" not_existing_service new_service + assert_contains "${lines[*]}" "service not_existing_service does not exist" +} + +@test "($PLUGIN_COMMAND_PREFIX:clone) error when new service isn't provided" { + run dokku "$PLUGIN_COMMAND_PREFIX:clone" l + assert_contains "${lines[*]}" "Please specify a name for the new service" +} + +@test "($PLUGIN_COMMAND_PREFIX:clone) error when new service already exists" { + dokku "$PLUGIN_COMMAND_PREFIX:create" new_service + run dokku "$PLUGIN_COMMAND_PREFIX:clone" l new_service + assert_contains "${lines[*]}" "service new_service already exists" + dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" new_service +} + +@test "($PLUGIN_COMMAND_PREFIX:clone) success" { + run dokku "$PLUGIN_COMMAND_PREFIX:clone" l new_service + [[ -f $PLUGIN_DATA_ROOT/new_service/ID ]] + assert_contains "${lines[*]}" "Copying data from l to new_service" + assert_contains "${lines[*]}" "Done" +} +