2015-09-22 17:47:16 +00:00
|
|
|
package dropbox
|
2015-05-23 18:56:48 +00:00
|
|
|
|
|
|
|
import (
|
2015-09-22 17:47:16 +00:00
|
|
|
"testing"
|
|
|
|
|
2015-05-23 18:56:48 +00:00
|
|
|
"github.com/ncw/rclone/fs"
|
|
|
|
dropboxapi "github.com/stacktic/dropbox"
|
2016-04-23 20:46:52 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2015-05-23 18:56:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPutCaseCorrectDirectoryName(t *testing.T) {
|
|
|
|
errors := fs.Stats.GetErrors()
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
tree := newNameTree()
|
2015-05-23 18:56:48 +00:00
|
|
|
tree.PutCaseCorrectDirectoryName("a/b", "C")
|
|
|
|
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.Equal(t, "", tree.CaseCorrectName, "Root CaseCorrectName should be empty")
|
|
|
|
|
|
|
|
a := tree.Directories["a"]
|
|
|
|
assert.Equal(t, "", a.CaseCorrectName, "CaseCorrectName at 'a' should be empty")
|
|
|
|
|
|
|
|
b := a.Directories["b"]
|
|
|
|
assert.Equal(t, "", b.CaseCorrectName, "CaseCorrectName at 'a/b' should be empty")
|
|
|
|
|
|
|
|
c := b.Directories["c"]
|
|
|
|
assert.Equal(t, "C", c.CaseCorrectName, "CaseCorrectName at 'a/b/c' should be 'C'")
|
|
|
|
|
|
|
|
assert.Equal(t, errors, fs.Stats.GetErrors(), "No errors should be reported")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutCaseCorrectPath(t *testing.T) {
|
|
|
|
errors := fs.Stats.GetErrors()
|
|
|
|
|
|
|
|
tree := newNameTree()
|
|
|
|
tree.PutCaseCorrectPath("A/b/C")
|
|
|
|
|
|
|
|
assert.Equal(t, "", tree.CaseCorrectName, "Root CaseCorrectName should be empty")
|
2015-05-23 18:56:48 +00:00
|
|
|
|
|
|
|
a := tree.Directories["a"]
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.Equal(t, "A", a.CaseCorrectName, "CaseCorrectName at 'a' should be 'A'")
|
2015-05-23 18:56:48 +00:00
|
|
|
|
|
|
|
b := a.Directories["b"]
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.Equal(t, "b", b.CaseCorrectName, "CaseCorrectName at 'a/b' should be 'b'")
|
2015-05-23 18:56:48 +00:00
|
|
|
|
|
|
|
c := b.Directories["c"]
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.Equal(t, "C", c.CaseCorrectName, "CaseCorrectName at 'a/b/c' should be 'C'")
|
2015-05-23 18:56:48 +00:00
|
|
|
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.Equal(t, errors, fs.Stats.GetErrors(), "No errors should be reported")
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutCaseCorrectDirectoryNameEmptyComponent(t *testing.T) {
|
|
|
|
errors := fs.Stats.GetErrors()
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
tree := newNameTree()
|
2015-05-23 18:56:48 +00:00
|
|
|
tree.PutCaseCorrectDirectoryName("/a", "C")
|
|
|
|
tree.PutCaseCorrectDirectoryName("b/", "C")
|
|
|
|
tree.PutCaseCorrectDirectoryName("a//b", "C")
|
|
|
|
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, fs.Stats.GetErrors() == errors+3, "3 errors should be reported")
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutCaseCorrectDirectoryNameEmptyParent(t *testing.T) {
|
|
|
|
errors := fs.Stats.GetErrors()
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
tree := newNameTree()
|
2015-05-23 18:56:48 +00:00
|
|
|
tree.PutCaseCorrectDirectoryName("", "C")
|
|
|
|
|
|
|
|
c := tree.Directories["c"]
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, c.CaseCorrectName == "C", "CaseCorrectName at 'c' should be 'C'")
|
2015-05-23 18:56:48 +00:00
|
|
|
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, fs.Stats.GetErrors() == errors, "No errors should be reported")
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetPathWithCorrectCase(t *testing.T) {
|
|
|
|
errors := fs.Stats.GetErrors()
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
tree := newNameTree()
|
2015-05-23 18:56:48 +00:00
|
|
|
tree.PutCaseCorrectDirectoryName("a", "C")
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, tree.GetPathWithCorrectCase("a/c") == nil, "Path for 'a' should not be available")
|
2015-05-23 18:56:48 +00:00
|
|
|
|
|
|
|
tree.PutCaseCorrectDirectoryName("", "A")
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, *tree.GetPathWithCorrectCase("a/c") == "/A/C", "Path for 'a/c' should be '/A/C'")
|
2015-05-23 18:56:48 +00:00
|
|
|
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, fs.Stats.GetErrors() == errors, "No errors should be reported")
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutAndWalk(t *testing.T) {
|
|
|
|
errors := fs.Stats.GetErrors()
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
tree := newNameTree()
|
2015-05-23 18:56:48 +00:00
|
|
|
tree.PutFile("a", "F", &dropboxapi.Entry{Path: "xxx"})
|
|
|
|
tree.PutCaseCorrectDirectoryName("", "A")
|
|
|
|
|
|
|
|
numCalled := 0
|
2016-04-21 19:06:21 +00:00
|
|
|
walkFunc := func(caseCorrectFilePath string, entry *dropboxapi.Entry) error {
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, caseCorrectFilePath == "A/F", "caseCorrectFilePath should be A/F, not "+caseCorrectFilePath)
|
|
|
|
assert.True(t, entry.Path == "xxx", "entry.Path should be xxx")
|
2015-05-23 18:56:48 +00:00
|
|
|
numCalled++
|
2016-04-21 19:06:21 +00:00
|
|
|
return nil
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|
2016-04-21 19:06:21 +00:00
|
|
|
err := tree.WalkFiles("", walkFunc)
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, err == nil, "No error should be returned")
|
|
|
|
assert.True(t, numCalled == 1, "walk func should be called only once")
|
|
|
|
assert.True(t, fs.Stats.GetErrors() == errors, "No errors should be reported")
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutAndWalkWithPrefix(t *testing.T) {
|
|
|
|
errors := fs.Stats.GetErrors()
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
tree := newNameTree()
|
2015-05-23 18:56:48 +00:00
|
|
|
tree.PutFile("a", "F", &dropboxapi.Entry{Path: "xxx"})
|
|
|
|
tree.PutCaseCorrectDirectoryName("", "A")
|
|
|
|
|
|
|
|
numCalled := 0
|
2016-04-21 19:06:21 +00:00
|
|
|
walkFunc := func(caseCorrectFilePath string, entry *dropboxapi.Entry) error {
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, caseCorrectFilePath == "A/F", "caseCorrectFilePath should be A/F, not "+caseCorrectFilePath)
|
|
|
|
assert.True(t, entry.Path == "xxx", "entry.Path should be xxx")
|
2015-05-23 18:56:48 +00:00
|
|
|
numCalled++
|
2016-04-21 19:06:21 +00:00
|
|
|
return nil
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|
2016-04-21 19:06:21 +00:00
|
|
|
err := tree.WalkFiles("A", walkFunc)
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, err == nil, "No error should be returned")
|
|
|
|
assert.True(t, numCalled == 1, "walk func should be called only once")
|
|
|
|
assert.True(t, fs.Stats.GetErrors() == errors, "No errors should be reported")
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutAndWalkIncompleteTree(t *testing.T) {
|
|
|
|
errors := fs.Stats.GetErrors()
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
tree := newNameTree()
|
2015-05-23 18:56:48 +00:00
|
|
|
tree.PutFile("a", "F", &dropboxapi.Entry{Path: "xxx"})
|
|
|
|
|
2016-04-21 19:06:21 +00:00
|
|
|
walkFunc := func(caseCorrectFilePath string, entry *dropboxapi.Entry) error {
|
2015-05-23 18:56:48 +00:00
|
|
|
t.Fatal("Should not be called")
|
2016-04-21 19:06:21 +00:00
|
|
|
return nil
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|
2016-04-21 19:06:21 +00:00
|
|
|
err := tree.WalkFiles("", walkFunc)
|
2016-04-23 20:46:52 +00:00
|
|
|
assert.True(t, err == nil, "No error should be returned")
|
|
|
|
assert.True(t, fs.Stats.GetErrors() == errors+1, "One error should be reported")
|
2015-05-23 18:56:48 +00:00
|
|
|
}
|