2015-12-04 06:30:35 +03:00
|
|
|
// Copyright ©2015 Steve Francia <spf@spf13.com>
|
|
|
|
// Portions Copyright ©2015 The Hugo Authors
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
2015-12-05 19:43:38 +03:00
|
|
|
package afero
|
2015-12-04 06:30:35 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2015-12-05 19:43:38 +03:00
|
|
|
var testFS = new(MemMapFs)
|
2015-12-04 06:30:35 +03:00
|
|
|
|
|
|
|
func TestDirExists(t *testing.T) {
|
|
|
|
type test struct {
|
|
|
|
input string
|
|
|
|
expected bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// First create a couple directories so there is something in the filesystem
|
2015-12-05 19:43:38 +03:00
|
|
|
//testFS := new(MemMapFs)
|
2015-12-04 06:30:35 +03:00
|
|
|
testFS.MkdirAll("/foo/bar", 0777)
|
|
|
|
|
|
|
|
data := []test{
|
|
|
|
{".", true},
|
|
|
|
{"./", true},
|
|
|
|
{"..", true},
|
|
|
|
{"../", true},
|
|
|
|
{"./..", true},
|
|
|
|
{"./../", true},
|
|
|
|
{"/foo/", true},
|
|
|
|
{"/foo", true},
|
|
|
|
{"/foo/bar", true},
|
|
|
|
{"/foo/bar/", true},
|
|
|
|
{"/", true},
|
|
|
|
{"/some-really-random-directory-name", false},
|
|
|
|
{"/some/really/random/directory/name", false},
|
|
|
|
{"./some-really-random-local-directory-name", false},
|
|
|
|
{"./some/really/random/local/directory/name", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, d := range data {
|
2015-12-07 17:29:41 +03:00
|
|
|
exists, _ := DirExists(testFS, filepath.FromSlash(d.input))
|
2015-12-04 06:30:35 +03:00
|
|
|
if d.expected != exists {
|
|
|
|
t.Errorf("Test %d %q failed. Expected %t got %t", i, d.input, d.expected, exists)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsDir(t *testing.T) {
|
2015-12-05 19:43:38 +03:00
|
|
|
testFS = new(MemMapFs)
|
2015-12-04 06:30:35 +03:00
|
|
|
|
|
|
|
type test struct {
|
|
|
|
input string
|
|
|
|
expected bool
|
|
|
|
}
|
|
|
|
data := []test{
|
|
|
|
{"./", true},
|
|
|
|
{"/", true},
|
|
|
|
{"./this-directory-does-not-existi", false},
|
|
|
|
{"/this-absolute-directory/does-not-exist", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, d := range data {
|
|
|
|
|
2015-12-07 17:29:41 +03:00
|
|
|
exists, _ := IsDir(testFS, d.input)
|
2015-12-04 06:30:35 +03:00
|
|
|
if d.expected != exists {
|
|
|
|
t.Errorf("Test %d failed. Expected %t got %t", i, d.expected, exists)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsEmpty(t *testing.T) {
|
2015-12-05 19:43:38 +03:00
|
|
|
testFS = new(MemMapFs)
|
2015-12-04 06:30:35 +03:00
|
|
|
|
|
|
|
zeroSizedFile, _ := createZeroSizedFileInTempDir()
|
|
|
|
defer deleteFileInTempDir(zeroSizedFile)
|
|
|
|
nonZeroSizedFile, _ := createNonZeroSizedFileInTempDir()
|
|
|
|
defer deleteFileInTempDir(nonZeroSizedFile)
|
|
|
|
emptyDirectory, _ := createEmptyTempDir()
|
|
|
|
defer deleteTempDir(emptyDirectory)
|
|
|
|
nonEmptyZeroLengthFilesDirectory, _ := createTempDirWithZeroLengthFiles()
|
|
|
|
defer deleteTempDir(nonEmptyZeroLengthFilesDirectory)
|
|
|
|
nonEmptyNonZeroLengthFilesDirectory, _ := createTempDirWithNonZeroLengthFiles()
|
|
|
|
defer deleteTempDir(nonEmptyNonZeroLengthFilesDirectory)
|
|
|
|
nonExistentFile := os.TempDir() + "/this-file-does-not-exist.txt"
|
|
|
|
nonExistentDir := os.TempDir() + "/this/direcotry/does/not/exist/"
|
|
|
|
|
|
|
|
fileDoesNotExist := fmt.Errorf("%q path does not exist", nonExistentFile)
|
|
|
|
dirDoesNotExist := fmt.Errorf("%q path does not exist", nonExistentDir)
|
|
|
|
|
|
|
|
type test struct {
|
|
|
|
input string
|
|
|
|
expectedResult bool
|
|
|
|
expectedErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
data := []test{
|
|
|
|
{zeroSizedFile.Name(), true, nil},
|
|
|
|
{nonZeroSizedFile.Name(), false, nil},
|
|
|
|
{emptyDirectory, true, nil},
|
|
|
|
{nonEmptyZeroLengthFilesDirectory, false, nil},
|
|
|
|
{nonEmptyNonZeroLengthFilesDirectory, false, nil},
|
|
|
|
{nonExistentFile, false, fileDoesNotExist},
|
|
|
|
{nonExistentDir, false, dirDoesNotExist},
|
|
|
|
}
|
|
|
|
for i, d := range data {
|
2015-12-07 17:29:41 +03:00
|
|
|
exists, err := IsEmpty(testFS, d.input)
|
2015-12-04 06:30:35 +03:00
|
|
|
if d.expectedResult != exists {
|
|
|
|
t.Errorf("Test %d %q failed exists. Expected result %t got %t", i, d.input, d.expectedResult, exists)
|
|
|
|
}
|
|
|
|
if d.expectedErr != nil {
|
|
|
|
if d.expectedErr.Error() != err.Error() {
|
|
|
|
t.Errorf("Test %d failed with err. Expected %q(%#v) got %q(%#v)", i, d.expectedErr, d.expectedErr, err, err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if d.expectedErr != err {
|
|
|
|
t.Errorf("Test %d failed. Expected error %q(%#v) got %q(%#v)", i, d.expectedErr, d.expectedErr, err, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-17 13:05:13 +03:00
|
|
|
func TestReaderContains(t *testing.T) {
|
|
|
|
for i, this := range []struct {
|
|
|
|
v1 string
|
2016-02-17 13:33:17 +03:00
|
|
|
v2 [][]byte
|
2016-02-17 13:05:13 +03:00
|
|
|
expect bool
|
|
|
|
}{
|
2016-02-17 13:33:17 +03:00
|
|
|
{"abc", [][]byte{[]byte("a")}, true},
|
|
|
|
{"abc", [][]byte{[]byte("b")}, true},
|
|
|
|
{"abcdefg", [][]byte{[]byte("efg")}, true},
|
|
|
|
{"abc", [][]byte{[]byte("d")}, false},
|
|
|
|
{"abc", [][]byte{[]byte("d"), []byte("e")}, false},
|
|
|
|
{"abc", [][]byte{[]byte("d"), []byte("a")}, true},
|
|
|
|
{"abc", [][]byte{[]byte("b"), []byte("e")}, true},
|
2016-02-17 13:05:13 +03:00
|
|
|
{"", nil, false},
|
2016-02-17 13:33:17 +03:00
|
|
|
{"", [][]byte{[]byte("a")}, false},
|
|
|
|
{"a", [][]byte{[]byte("")}, false},
|
|
|
|
{"", [][]byte{[]byte("")}, false}} {
|
|
|
|
result := readerContainsAny(strings.NewReader(this.v1), this.v2...)
|
2016-02-17 13:05:13 +03:00
|
|
|
if result != this.expect {
|
|
|
|
t.Errorf("[%d] readerContains: got %t but expected %t", i, result, this.expect)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-17 13:33:17 +03:00
|
|
|
if readerContainsAny(nil, []byte("a")) {
|
2016-02-17 13:05:13 +03:00
|
|
|
t.Error("readerContains with nil reader")
|
|
|
|
}
|
|
|
|
|
2016-02-17 13:33:17 +03:00
|
|
|
if readerContainsAny(nil, nil) {
|
2016-02-17 13:05:13 +03:00
|
|
|
t.Error("readerContains with nil arguments")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-05 19:43:38 +03:00
|
|
|
func createZeroSizedFileInTempDir() (File, error) {
|
2015-12-04 06:30:35 +03:00
|
|
|
filePrefix := "_path_test_"
|
2015-12-07 17:29:41 +03:00
|
|
|
f, e := TempFile(testFS, "", filePrefix) // dir is os.TempDir()
|
2015-12-04 06:30:35 +03:00
|
|
|
if e != nil {
|
|
|
|
// if there was an error no file was created.
|
|
|
|
// => no requirement to delete the file
|
|
|
|
return nil, e
|
|
|
|
}
|
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
|
2015-12-05 19:43:38 +03:00
|
|
|
func createNonZeroSizedFileInTempDir() (File, error) {
|
2015-12-04 06:30:35 +03:00
|
|
|
f, err := createZeroSizedFileInTempDir()
|
|
|
|
if err != nil {
|
|
|
|
// no file ??
|
|
|
|
}
|
|
|
|
byteString := []byte("byteString")
|
2015-12-07 17:29:41 +03:00
|
|
|
err = WriteFile(testFS, f.Name(), byteString, 0644)
|
2015-12-04 06:30:35 +03:00
|
|
|
if err != nil {
|
|
|
|
// delete the file
|
|
|
|
deleteFileInTempDir(f)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
|
2015-12-05 19:43:38 +03:00
|
|
|
func deleteFileInTempDir(f File) {
|
2015-12-04 06:30:35 +03:00
|
|
|
err := testFS.Remove(f.Name())
|
|
|
|
if err != nil {
|
|
|
|
// now what?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func createEmptyTempDir() (string, error) {
|
|
|
|
dirPrefix := "_dir_prefix_"
|
2015-12-07 17:29:41 +03:00
|
|
|
d, e := TempDir(testFS, "", dirPrefix) // will be in os.TempDir()
|
2015-12-04 06:30:35 +03:00
|
|
|
if e != nil {
|
|
|
|
// no directory to delete - it was never created
|
|
|
|
return "", e
|
|
|
|
}
|
|
|
|
return d, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func createTempDirWithZeroLengthFiles() (string, error) {
|
|
|
|
d, dirErr := createEmptyTempDir()
|
|
|
|
if dirErr != nil {
|
|
|
|
//now what?
|
|
|
|
}
|
|
|
|
filePrefix := "_path_test_"
|
2015-12-07 17:29:41 +03:00
|
|
|
_, fileErr := TempFile(testFS, d, filePrefix) // dir is os.TempDir()
|
2015-12-04 06:30:35 +03:00
|
|
|
if fileErr != nil {
|
|
|
|
// if there was an error no file was created.
|
|
|
|
// but we need to remove the directory to clean-up
|
|
|
|
deleteTempDir(d)
|
|
|
|
return "", fileErr
|
|
|
|
}
|
|
|
|
// the dir now has one, zero length file in it
|
|
|
|
return d, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func createTempDirWithNonZeroLengthFiles() (string, error) {
|
|
|
|
d, dirErr := createEmptyTempDir()
|
|
|
|
if dirErr != nil {
|
|
|
|
//now what?
|
|
|
|
}
|
|
|
|
filePrefix := "_path_test_"
|
2015-12-07 17:29:41 +03:00
|
|
|
f, fileErr := TempFile(testFS, d, filePrefix) // dir is os.TempDir()
|
2015-12-04 06:30:35 +03:00
|
|
|
if fileErr != nil {
|
|
|
|
// if there was an error no file was created.
|
|
|
|
// but we need to remove the directory to clean-up
|
|
|
|
deleteTempDir(d)
|
|
|
|
return "", fileErr
|
|
|
|
}
|
|
|
|
byteString := []byte("byteString")
|
2015-12-07 17:29:41 +03:00
|
|
|
fileErr = WriteFile(testFS, f.Name(), byteString, 0644)
|
2015-12-04 06:30:35 +03:00
|
|
|
if fileErr != nil {
|
|
|
|
// delete the file
|
|
|
|
deleteFileInTempDir(f)
|
|
|
|
// also delete the directory
|
|
|
|
deleteTempDir(d)
|
|
|
|
return "", fileErr
|
|
|
|
}
|
|
|
|
|
|
|
|
// the dir now has one, zero length file in it
|
|
|
|
return d, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExists(t *testing.T) {
|
|
|
|
zeroSizedFile, _ := createZeroSizedFileInTempDir()
|
|
|
|
defer deleteFileInTempDir(zeroSizedFile)
|
|
|
|
nonZeroSizedFile, _ := createNonZeroSizedFileInTempDir()
|
|
|
|
defer deleteFileInTempDir(nonZeroSizedFile)
|
|
|
|
emptyDirectory, _ := createEmptyTempDir()
|
|
|
|
defer deleteTempDir(emptyDirectory)
|
|
|
|
nonExistentFile := os.TempDir() + "/this-file-does-not-exist.txt"
|
|
|
|
nonExistentDir := os.TempDir() + "/this/direcotry/does/not/exist/"
|
|
|
|
|
|
|
|
type test struct {
|
|
|
|
input string
|
|
|
|
expectedResult bool
|
|
|
|
expectedErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
data := []test{
|
|
|
|
{zeroSizedFile.Name(), true, nil},
|
|
|
|
{nonZeroSizedFile.Name(), true, nil},
|
|
|
|
{emptyDirectory, true, nil},
|
|
|
|
{nonExistentFile, false, nil},
|
|
|
|
{nonExistentDir, false, nil},
|
|
|
|
}
|
|
|
|
for i, d := range data {
|
2015-12-07 17:29:41 +03:00
|
|
|
exists, err := Exists(testFS, d.input)
|
2015-12-04 06:30:35 +03:00
|
|
|
if d.expectedResult != exists {
|
|
|
|
t.Errorf("Test %d failed. Expected result %t got %t", i, d.expectedResult, exists)
|
|
|
|
}
|
|
|
|
if d.expectedErr != err {
|
|
|
|
t.Errorf("Test %d failed. Expected %q got %q", i, d.expectedErr, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSafeWriteToDisk(t *testing.T) {
|
|
|
|
emptyFile, _ := createZeroSizedFileInTempDir()
|
|
|
|
defer deleteFileInTempDir(emptyFile)
|
|
|
|
tmpDir, _ := createEmptyTempDir()
|
|
|
|
defer deleteTempDir(tmpDir)
|
|
|
|
|
|
|
|
randomString := "This is a random string!"
|
|
|
|
reader := strings.NewReader(randomString)
|
|
|
|
|
|
|
|
fileExists := fmt.Errorf("%v already exists", emptyFile.Name())
|
|
|
|
|
|
|
|
type test struct {
|
|
|
|
filename string
|
|
|
|
expectedErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
nowStr := strconv.FormatInt(now, 10)
|
|
|
|
data := []test{
|
|
|
|
{emptyFile.Name(), fileExists},
|
|
|
|
{tmpDir + "/" + nowStr, nil},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, d := range data {
|
2015-12-07 17:29:41 +03:00
|
|
|
e := SafeWriteReader(testFS, d.filename, reader)
|
2015-12-04 06:30:35 +03:00
|
|
|
if d.expectedErr != nil {
|
|
|
|
if d.expectedErr.Error() != e.Error() {
|
|
|
|
t.Errorf("Test %d failed. Expected error %q but got %q", i, d.expectedErr.Error(), e.Error())
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if d.expectedErr != e {
|
|
|
|
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expectedErr, e)
|
|
|
|
}
|
2015-12-07 17:29:41 +03:00
|
|
|
contents, _ := ReadFile(testFS, d.filename)
|
2015-12-04 06:30:35 +03:00
|
|
|
if randomString != string(contents) {
|
|
|
|
t.Errorf("Test %d failed. Expected contents %q but got %q", i, randomString, string(contents))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reader.Seek(0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWriteToDisk(t *testing.T) {
|
|
|
|
emptyFile, _ := createZeroSizedFileInTempDir()
|
|
|
|
defer deleteFileInTempDir(emptyFile)
|
|
|
|
tmpDir, _ := createEmptyTempDir()
|
|
|
|
defer deleteTempDir(tmpDir)
|
|
|
|
|
|
|
|
randomString := "This is a random string!"
|
|
|
|
reader := strings.NewReader(randomString)
|
|
|
|
|
|
|
|
type test struct {
|
|
|
|
filename string
|
|
|
|
expectedErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
nowStr := strconv.FormatInt(now, 10)
|
|
|
|
data := []test{
|
|
|
|
{emptyFile.Name(), nil},
|
|
|
|
{tmpDir + "/" + nowStr, nil},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, d := range data {
|
2015-12-07 17:29:41 +03:00
|
|
|
e := WriteReader(testFS, d.filename, reader)
|
2015-12-04 06:30:35 +03:00
|
|
|
if d.expectedErr != e {
|
|
|
|
t.Errorf("Test %d failed. WriteToDisk Error Expected %q but got %q", i, d.expectedErr, e)
|
|
|
|
}
|
2015-12-07 17:29:41 +03:00
|
|
|
contents, e := ReadFile(testFS, d.filename)
|
2015-12-04 06:30:35 +03:00
|
|
|
if e != nil {
|
|
|
|
t.Errorf("Test %d failed. Could not read file %s. Reason: %s\n", i, d.filename, e)
|
|
|
|
}
|
|
|
|
if randomString != string(contents) {
|
|
|
|
t.Errorf("Test %d failed. Expected contents %q but got %q", i, randomString, string(contents))
|
|
|
|
}
|
|
|
|
reader.Seek(0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetTempDir(t *testing.T) {
|
|
|
|
dir := os.TempDir()
|
|
|
|
if FilePathSeparator != dir[len(dir)-1:] {
|
|
|
|
dir = dir + FilePathSeparator
|
|
|
|
}
|
|
|
|
testDir := "hugoTestFolder" + FilePathSeparator
|
|
|
|
tests := []struct {
|
|
|
|
input string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{"", dir},
|
|
|
|
{testDir + " Foo bar ", dir + testDir + " Foo bar " + FilePathSeparator},
|
|
|
|
{testDir + "Foo.Bar/foo_Bar-Foo", dir + testDir + "Foo.Bar/foo_Bar-Foo" + FilePathSeparator},
|
|
|
|
{testDir + "fOO,bar:foo%bAR", dir + testDir + "fOObarfoo%bAR" + FilePathSeparator},
|
|
|
|
{testDir + "FOo/BaR.html", dir + testDir + "FOo/BaR.html" + FilePathSeparator},
|
|
|
|
{testDir + "трям/трям", dir + testDir + "трям/трям" + FilePathSeparator},
|
|
|
|
{testDir + "은행", dir + testDir + "은행" + FilePathSeparator},
|
|
|
|
{testDir + "Банковский кассир", dir + testDir + "Банковский кассир" + FilePathSeparator},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2015-12-07 17:29:41 +03:00
|
|
|
output := GetTempDir(new(MemMapFs), test.input)
|
2015-12-04 06:30:35 +03:00
|
|
|
if output != test.expected {
|
|
|
|
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function is very dangerous. Don't use it.
|
|
|
|
func deleteTempDir(d string) {
|
|
|
|
err := os.RemoveAll(d)
|
|
|
|
if err != nil {
|
|
|
|
// now what?
|
|
|
|
}
|
|
|
|
}
|
2016-04-20 15:12:23 +03:00
|
|
|
|
|
|
|
func TestFullBaseFsPath(t *testing.T) {
|
|
|
|
type dirSpec struct {
|
|
|
|
Dir1, Dir2, Dir3 string
|
|
|
|
}
|
|
|
|
dirSpecs := []dirSpec{
|
|
|
|
dirSpec{Dir1: "/", Dir2: "/", Dir3: "/"},
|
|
|
|
dirSpec{Dir1: "/", Dir2: "/path2", Dir3: "/"},
|
|
|
|
dirSpec{Dir1: "/path1/dir", Dir2: "/path2/dir/", Dir3: "/path3/dir"},
|
|
|
|
dirSpec{Dir1: "C:/path1", Dir2: "path2/dir", Dir3: "/path3/dir/"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ds := range dirSpecs {
|
|
|
|
memFs := NewMemMapFs()
|
|
|
|
level1Fs := NewBasePathFs(memFs, ds.Dir1)
|
|
|
|
level2Fs := NewBasePathFs(level1Fs, ds.Dir2)
|
|
|
|
level3Fs := NewBasePathFs(level2Fs, ds.Dir3)
|
|
|
|
|
|
|
|
type spec struct {
|
|
|
|
BaseFs Fs
|
|
|
|
FileName string
|
|
|
|
ExpectedPath string
|
|
|
|
}
|
|
|
|
specs := []spec{
|
|
|
|
spec{BaseFs: level3Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, "f.txt")},
|
|
|
|
spec{BaseFs: level3Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, "")},
|
|
|
|
spec{BaseFs: level2Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, "f.txt")},
|
|
|
|
spec{BaseFs: level2Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, "")},
|
|
|
|
spec{BaseFs: level1Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, "f.txt")},
|
|
|
|
spec{BaseFs: level1Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, "")},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range specs {
|
|
|
|
if actualPath := FullBaseFsPath(s.BaseFs.(*BasePathFs), s.FileName); actualPath != s.ExpectedPath {
|
|
|
|
t.Errorf("Expected \n%s got \n%s", s.ExpectedPath, actualPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|