Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage/url: fixes the bug where some part of destination path is removed by cp #456

Merged
merged 15 commits into from
Jul 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
url: use filepath.Seperator to produce testcases for different OSs
The testcases will be generated depending on the OS using the filepath.Seperator, instead of preparing two different testcases one of whom is to be selected on runtime environment.
  • Loading branch information
kucukaslan committed Jul 21, 2022
commit 179c394a416ef7d0e6b3b08fef4642a73e0284c2
152 changes: 46 additions & 106 deletions storage/url/url_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package url

import (
"path/filepath"
"reflect"
"regexp"
"runtime"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -441,111 +441,51 @@ func TestURLSetRelative(t *testing.T) {
target string
expect string
}
var tests []testcase
if runtime.GOOS == "windows" {
tests = []testcase{
// The expectation is the path which will get us to target starting
// from the directory of base object.
{
name: `local_sibling_child_object`,
base: `\parent\child\object`,
target: `\parent\child2\object`,
expect: `..\child2\object`,
},
{
name: `local_same_directory_object`,
base: `\parent\child\object`,
target: `\parent\child\object2`,
expect: `object2`,
},
{
name: `s3_sibling_child_object`,
base: `s3://bucket/parent\child\object`,
target: `s3://bucket/parent\child2\`,
expect: `..\child2`,
},
{
name: `local_child_directory_fully_wildcarded`,
base: `\parent\*\object`,
target: `\parent\child\object`,
expect: `child\object`,
},
{
name: `local_child_directory_partially_wildcarded`,
base: `\parent\c*d\object`,
target: `\parent\child\object`,
expect: `child\object`,
},
{
name: `local_child_directory_fully_wildcarded_with_question_mark`,
base: `\parent\?\object`,
target: `\parent\c\object`,
expect: `c\object`,
},
{
name: `s3_child_directory_wildcarded`,
base: `s3://bucket/parent\*\object`,
target: `s3://bucket/parent\child2\`,
expect: `child2`,
},
}
} else {
tests = []testcase{
{
name: "local_sibling_child_object",
base: "/parent/child/object",
target: "/parent/child2/object",
expect: "../child2/object",
},
{
name: "local_same_directory_object",
base: "/parent/child/object",
target: "/parent/child/object2",
expect: "object2",
},
{
name: "s3_sibling_child_object",
base: "s3://bucket/parent/child/object",
target: "s3://bucket/parent/child2/",
expect: "../child2",
},
{
name: "local_child_directory_fully_wildcarded",
base: "/parent/*/object",
target: "/parent/child/object",
expect: "child/object",
},
{
name: "local_child_directory_partially_wildcarded",
base: "/parent/c*d/object",
target: "/parent/child/object",
expect: "child/object",
},
{
name: "local_child_directory_fully_wildcarded_with_question_mark",
base: "/parent/?/object",
target: "/parent/c/object",
expect: "c/object",
},
{
name: "local_directory_with_backslash_in_name",
base: "/parent/back\\slash/object",
target: "/parent/back\\slash/object",
expect: "object",
},
{
name: "local_sibling_directory_with_backslash_in_name",
base: "/parent/back\\slash/object",
target: "/parent/back\\slash2/object",
expect: "../back\\slash2/object",
},
{
name: "s3_child_directory_wildcarded",
base: "s3://bucket/parent/*/object",
target: "s3://bucket/parent/child2/",
expect: "child2",
},
}

sep := string(filepath.Separator)
tests := []testcase{
{
name: "local_sibling_child_object",
base: sep + "parent" + sep + "child" + sep + "object",
target: sep + "parent" + sep + "child2" + sep + "object",
expect: ".." + sep + "child2" + sep + "object",
},
{
name: "local_same_directory_object",
base: sep + "parent" + sep + "child" + sep + "object",
target: sep + "parent" + sep + "child" + sep + "object2",
expect: "object2",
},
{
name: "s3_sibling_child_object",
base: "s3://bucket/parent" + sep + "child" + sep + "object",
target: "s3://bucket/parent" + sep + "child2" + sep + "",
expect: ".." + sep + "child2",
},
{
name: "local_child_directory_fully_wildcarded",
base: sep + "parent" + sep + "*" + sep + "object",
target: sep + "parent" + sep + "child" + sep + "object",
expect: "child" + sep + "object",
},
{
name: "local_child_directory_partially_wildcarded",
base: sep + "parent" + sep + "c*d" + sep + "object",
target: sep + "parent" + sep + "child" + sep + "object",
expect: "child" + sep + "object",
},
{
name: "local_child_directory_fully_wildcarded_with_question_mark",
base: sep + "parent" + sep + "?" + sep + "object",
target: sep + "parent" + sep + "c" + sep + "object",
expect: "c" + sep + "object",
},
{
name: "s3_child_directory_wildcarded",
base: "s3://bucket/parent" + sep + "*" + sep + "object",
target: "s3://bucket/parent" + sep + "child2" + sep + "",
expect: "child2",
},
}

for _, tt := range tests {
Expand Down