Skip to content

Commit

Permalink
Fix dir with trailing '/' (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
fishi0x01 authored Jun 14, 2020
1 parent 7bd10b2 commit b0f78f9
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v0.6.1 (June 15, 2020)

BUG FIXES:

* Properly handle suffix '/' in source path ([#39](https://github.com/fishi0x01/vsh/pull/39))


## v0.6.0 (June 13, 2020)

ENHANCEMENTS:
Expand Down
4 changes: 3 additions & 1 deletion cli/command.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cli

import (
"github.com/fishi0x01/vsh/client"
"path/filepath"
"strings"

"github.com/fishi0x01/vsh/client"
)

// Command interface to describe a command structure
Expand Down Expand Up @@ -31,6 +32,7 @@ func cmdPath(pwd string, arg string) (result string) {
}

func runCommandWithTraverseTwoPaths(client *client.Client, source string, target string, f func(string, string) error) {
source = filepath.Clean(source) // remove potential trailing '/'
for _, path := range client.Traverse(source) {
target := strings.Replace(path, source, target, 1)
err := f(path, target)
Expand Down
3 changes: 2 additions & 1 deletion cli/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package cli

import (
"fmt"
"github.com/fishi0x01/vsh/client"
"io"

"github.com/fishi0x01/vsh/client"
)

// CopyCommand container for all 'cp' parameters
Expand Down
83 changes: 80 additions & 3 deletions test/command-tests/cp.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ load ../bin/plugins/bats-assert/load
assert_output "test"

#######################################
echo "==== case: copy single directory ===="
echo "==== case: copy single directory without trailing '/' ===="
run ${APP_BIN} -c "cp ${KV_BACKEND}/src/dev ${KV_BACKEND}/dest/dev"
assert_success

echo "ensure the directory got copied to destination"
run get_vault_value "value" "${KV_BACKEND}/dest/dev/1"
assert_success
assert_output "1"

run get_vault_value "value" "${KV_BACKEND}/dest/dev/2"
assert_success
assert_output "2"

run get_vault_value "value" "${KV_BACKEND}/dest/dev/3"
assert_success
assert_output "3"
Expand All @@ -46,11 +44,90 @@ load ../bin/plugins/bats-assert/load
run get_vault_value "value" "${KV_BACKEND}/src/dev/1"
assert_success
assert_output "1"
run get_vault_value "value" "${KV_BACKEND}/src/dev/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/src/dev/3"
assert_success
assert_output "3"

#######################################
echo "==== case: copy single directory with trailing '/' ===="
run ${APP_BIN} -c "cp ${KV_BACKEND}/src/dev/ ${KV_BACKEND}/dest/dev.copy"
assert_success

echo "ensure the directory got copied to destination"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy/1"
assert_success
assert_output "1"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy/3"
assert_success
assert_output "3"

echo "ensure the src directory still exists"
run get_vault_value "value" "${KV_BACKEND}/src/dev/1"
assert_success
assert_output "1"
run get_vault_value "value" "${KV_BACKEND}/src/dev/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/src/dev/3"
assert_success
assert_output "3"

######################################
echo "==== case: copy single directory with dest trailing '/' ===="
run ${APP_BIN} -c "cp ${KV_BACKEND}/src/dev ${KV_BACKEND}/dest/dev.copy2/"
assert_success

echo "ensure the directory got copied to destination"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy2/1"
assert_success
assert_output "1"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy2/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy2/3"
assert_success
assert_output "3"

echo "ensure the src directory still exists"
run get_vault_value "value" "${KV_BACKEND}/src/dev/1"
assert_success
assert_output "1"
run get_vault_value "value" "${KV_BACKEND}/src/dev/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/src/dev/3"
assert_success
assert_output "3"

######################################
echo "==== case: copy single directory with dsrc and est trailing '/' ===="
run ${APP_BIN} -c "cp ${KV_BACKEND}/src/dev/ ${KV_BACKEND}/dest/dev.copy3/"
assert_success

echo "ensure the directory got copied to destination"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy3/1"
assert_success
assert_output "1"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy3/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy3/3"
assert_success
assert_output "3"

echo "ensure the src directory still exists"
run get_vault_value "value" "${KV_BACKEND}/src/dev/1"
assert_success
assert_output "1"
run get_vault_value "value" "${KV_BACKEND}/src/dev/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/src/dev/3"
assert_success
assert_output "3"
Expand Down
60 changes: 55 additions & 5 deletions test/command-tests/mv.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ load ../bin/plugins/bats-assert/load
assert_output --partial "${NO_VALUE_FOUND}"

#######################################
echo "==== case: move single directory ===="
echo "==== case: move single directory without trailing '/' ===="
run ${APP_BIN} -c "mv ${KV_BACKEND}/src/dev ${KV_BACKEND}/dest/dev"
assert_success

echo "ensure the directory got moved to destination"
run get_vault_value "value" "${KV_BACKEND}/dest/dev/1"
assert_success
assert_output "1"

run get_vault_value "value" "${KV_BACKEND}/dest/dev/2"
assert_success
assert_output "2"

run get_vault_value "value" "${KV_BACKEND}/dest/dev/3"
assert_success
assert_output "3"
Expand All @@ -43,15 +41,67 @@ load ../bin/plugins/bats-assert/load
run get_vault_value "value" "${KV_BACKEND}/src/dev/1"
assert_success
assert_output --partial "${NO_VALUE_FOUND}"

run get_vault_value "value" "${KV_BACKEND}/src/dev/2"
assert_success
assert_output --partial "${NO_VALUE_FOUND}"

run get_vault_value "value" "${KV_BACKEND}/src/dev/3"
assert_success
assert_output --partial "${NO_VALUE_FOUND}"

#######################################
echo "==== case: move single directory with trailing '/' ===="
run ${APP_BIN} -c "mv ${KV_BACKEND}/dest/dev/ ${KV_BACKEND}/dest/dev.copy"
assert_success

echo "ensure the directory got moved to destination"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy/1"
assert_success
assert_output "1"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy/3"
assert_success
assert_output "3"

echo "ensure the src directory got removed"
run get_vault_value "value" "${KV_BACKEND}/dest/dev/1"
assert_success
assert_output --partial "${NO_VALUE_FOUND}"
run get_vault_value "value" "${KV_BACKEND}/dest/dev/2"
assert_success
assert_output --partial "${NO_VALUE_FOUND}"
run get_vault_value "value" "${KV_BACKEND}/dest/dev/3"
assert_success
assert_output --partial "${NO_VALUE_FOUND}"

#######################################
echo "==== case: move single directory with dest trailing '/' ===="
run ${APP_BIN} -c "mv ${KV_BACKEND}/dest/dev.copy ${KV_BACKEND}/dest/dev/"
assert_success

echo "ensure the directory got moved to destination"
run get_vault_value "value" "${KV_BACKEND}/dest/dev/1"
assert_success
assert_output "1"
run get_vault_value "value" "${KV_BACKEND}/dest/dev/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/dest/dev/3"
assert_success
assert_output "3"

echo "ensure the src directory got removed"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy/1"
assert_success
assert_output --partial "${NO_VALUE_FOUND}"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy/2"
assert_success
assert_output --partial "${NO_VALUE_FOUND}"
run get_vault_value "value" "${KV_BACKEND}/dest/dev.copy/3"
assert_success
assert_output --partial "${NO_VALUE_FOUND}"

#######################################
echo "==== TODO case: move ambigious file ===="

Expand Down
3 changes: 1 addition & 2 deletions test/util/util.bash
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash

export KV_VERSION="${KV_VERSION:-"2"}"

export VAULT_VERSION=${VAULT_VERSION:-"1.3.4"}
export KV_BACKEND=${KV_BACKEND:-"KV2"}
export VAULT_CONTAINER_NAME="vsh-integration-test-vault"
export VAULT_HOST_PORT=${VAULT_HOST_PORT:-"8888"}

Expand Down

0 comments on commit b0f78f9

Please sign in to comment.