2022-05-06 17:04:09 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHasFilepathPrefix(t *testing.T) {
|
|
|
|
f := func(dst, storageDataPath string, resultExpected bool) {
|
|
|
|
t.Helper()
|
2024-07-11 15:53:40 +02:00
|
|
|
|
2022-05-06 17:04:09 +02:00
|
|
|
result := hasFilepathPrefix(dst, storageDataPath)
|
|
|
|
if result != resultExpected {
|
2024-07-11 15:53:40 +02:00
|
|
|
t.Fatalf("unexpected hasFilepathPrefix(%q, %q); got: %v; want: %v", dst, storageDataPath, result, resultExpected)
|
2022-05-06 17:04:09 +02:00
|
|
|
}
|
|
|
|
}
|
2024-07-11 15:53:40 +02:00
|
|
|
|
2022-05-06 17:04:09 +02:00
|
|
|
pwd, err := filepath.Abs("")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("cannot determine working directory: %s", err)
|
|
|
|
}
|
2024-07-11 15:53:40 +02:00
|
|
|
|
2022-05-06 17:04:09 +02:00
|
|
|
f("s3://foo/bar", "foo", false)
|
|
|
|
f("fs://"+pwd+"/foo", "foo", true)
|
|
|
|
f("fs://"+pwd+"/foo", "foo/bar", false)
|
|
|
|
f("fs://"+pwd+"/foo/bar", "foo", true)
|
|
|
|
f("fs://"+pwd+"/foo", "bar", false)
|
|
|
|
f("fs://"+pwd+"/foo", pwd+"/foo", true)
|
|
|
|
f("fs://"+pwd+"/foo", pwd+"/foo/bar", false)
|
|
|
|
f("fs://"+pwd+"/foo/bar", pwd+"/foo", true)
|
|
|
|
f("fs://"+pwd+"/foo", pwd+"/bar", false)
|
2023-08-16 14:45:35 +02:00
|
|
|
f("fs:///data1", "/data", false)
|
|
|
|
f("fs:///data", "/data1", false)
|
|
|
|
f("fs:///data", "/data/foo", false)
|
|
|
|
f("fs:///data/foo", "/data", true)
|
|
|
|
f("fs:///data/foo/", "/data/", true)
|
2022-05-06 17:04:09 +02:00
|
|
|
}
|