Convert more tests to use assert/require
This commit is contained in:
parent
f6a053df6e
commit
70dc97231e
7 changed files with 248 additions and 695 deletions
|
@ -8,122 +8,81 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/iotest"
|
"testing/iotest"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAsyncReader(t *testing.T) {
|
func TestAsyncReader(t *testing.T) {
|
||||||
buf := ioutil.NopCloser(bytes.NewBufferString("Testbuffer"))
|
buf := ioutil.NopCloser(bytes.NewBufferString("Testbuffer"))
|
||||||
ar, err := newAsyncReader(buf, 4, 10000)
|
ar, err := newAsyncReader(buf, 4, 10000)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("error when creating:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dst = make([]byte, 100)
|
var dst = make([]byte, 100)
|
||||||
n, err := ar.Read(dst)
|
n, err := ar.Read(dst)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("error when reading:", err)
|
assert.Equal(t, 10, n)
|
||||||
}
|
|
||||||
if n != 10 {
|
|
||||||
t.Fatal("unexpected length, expected 10, got ", n)
|
|
||||||
}
|
|
||||||
|
|
||||||
n, err = ar.Read(dst)
|
n, err = ar.Read(dst)
|
||||||
if err != io.EOF {
|
assert.Equal(t, io.EOF, err)
|
||||||
t.Fatal("expected io.EOF, got", err)
|
assert.Equal(t, 0, n)
|
||||||
}
|
|
||||||
if n != 0 {
|
|
||||||
t.Fatal("unexpected length, expected 0, got ", n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test read after error
|
// Test read after error
|
||||||
n, err = ar.Read(dst)
|
n, err = ar.Read(dst)
|
||||||
if err != io.EOF {
|
assert.Equal(t, io.EOF, err)
|
||||||
t.Fatal("expected io.EOF, got", err)
|
assert.Equal(t, 0, n)
|
||||||
}
|
|
||||||
if n != 0 {
|
|
||||||
t.Fatal("unexpected length, expected 0, got ", n)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ar.Close()
|
err = ar.Close()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("error when closing:", err)
|
|
||||||
}
|
|
||||||
// Test double close
|
// Test double close
|
||||||
err = ar.Close()
|
err = ar.Close()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("error when closing:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test Close without reading everything
|
// Test Close without reading everything
|
||||||
buf = ioutil.NopCloser(bytes.NewBuffer(make([]byte, 50000)))
|
buf = ioutil.NopCloser(bytes.NewBuffer(make([]byte, 50000)))
|
||||||
ar, err = newAsyncReader(buf, 4, 100)
|
ar, err = newAsyncReader(buf, 4, 100)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("error when creating:", err)
|
|
||||||
}
|
|
||||||
err = ar.Close()
|
err = ar.Close()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("error when closing, noread:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAsyncWriteTo(t *testing.T) {
|
func TestAsyncWriteTo(t *testing.T) {
|
||||||
buf := ioutil.NopCloser(bytes.NewBufferString("Testbuffer"))
|
buf := ioutil.NopCloser(bytes.NewBufferString("Testbuffer"))
|
||||||
ar, err := newAsyncReader(buf, 4, 10000)
|
ar, err := newAsyncReader(buf, 4, 10000)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("error when creating:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dst = &bytes.Buffer{}
|
var dst = &bytes.Buffer{}
|
||||||
n, err := io.Copy(dst, ar)
|
n, err := io.Copy(dst, ar)
|
||||||
if err != io.EOF {
|
assert.Equal(t, io.EOF, err)
|
||||||
t.Fatal("error when reading:", err)
|
assert.Equal(t, int64(10), n)
|
||||||
}
|
|
||||||
if n != 10 {
|
|
||||||
t.Fatal("unexpected length, expected 10, got ", n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Should still return EOF
|
// Should still return EOF
|
||||||
n, err = io.Copy(dst, ar)
|
n, err = io.Copy(dst, ar)
|
||||||
if err != io.EOF {
|
assert.Equal(t, io.EOF, err)
|
||||||
t.Fatal("expected io.EOF, got", err)
|
assert.Equal(t, int64(0), n)
|
||||||
}
|
|
||||||
if n != 0 {
|
|
||||||
t.Fatal("unexpected length, expected 0, got ", n)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ar.Close()
|
err = ar.Close()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("error when closing:", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAsyncReaderErrors(t *testing.T) {
|
func TestAsyncReaderErrors(t *testing.T) {
|
||||||
// test nil reader
|
// test nil reader
|
||||||
_, err := newAsyncReader(nil, 4, 10000)
|
_, err := newAsyncReader(nil, 4, 10000)
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error when creating, but got nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
// invalid buffer number
|
// invalid buffer number
|
||||||
buf := ioutil.NopCloser(bytes.NewBufferString("Testbuffer"))
|
buf := ioutil.NopCloser(bytes.NewBufferString("Testbuffer"))
|
||||||
_, err = newAsyncReader(buf, 0, 10000)
|
_, err = newAsyncReader(buf, 0, 10000)
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error when creating, but got nil")
|
|
||||||
}
|
|
||||||
_, err = newAsyncReader(buf, -1, 10000)
|
_, err = newAsyncReader(buf, -1, 10000)
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error when creating, but got nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
// invalid buffer size
|
// invalid buffer size
|
||||||
_, err = newAsyncReader(buf, 4, 0)
|
_, err = newAsyncReader(buf, 4, 0)
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error when creating, but got nil")
|
|
||||||
}
|
|
||||||
_, err = newAsyncReader(buf, 4, -1)
|
_, err = newAsyncReader(buf, 4, -1)
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error when creating, but got nil")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complex read tests, leveraged from "bufio".
|
// Complex read tests, leveraged from "bufio".
|
||||||
|
@ -210,9 +169,7 @@ func TestAsyncReaderSizes(t *testing.T) {
|
||||||
readmaker.name, bufreader.name, bufsize, text, s)
|
readmaker.name, bufreader.name, bufsize, text, s)
|
||||||
}
|
}
|
||||||
err := ar.Close()
|
err := ar.Close()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Unexpected close error:", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,9 +214,7 @@ func TestAsyncReaderWriteTo(t *testing.T) {
|
||||||
readmaker.name, bufreader.name, bufsize, text, s)
|
readmaker.name, bufreader.name, bufsize, text, s)
|
||||||
}
|
}
|
||||||
err = ar.Close()
|
err = ar.Close()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Unexpected close error:", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSizeSuffixString(t *testing.T) {
|
func TestSizeSuffixString(t *testing.T) {
|
||||||
|
@ -23,14 +24,12 @@ func TestSizeSuffixString(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
ss := SizeSuffix(test.in)
|
ss := SizeSuffix(test.in)
|
||||||
got := ss.String()
|
got := ss.String()
|
||||||
if test.want != got {
|
assert.Equal(t, test.want, got)
|
||||||
t.Errorf("Want %v got %v", test.want, got)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSizeSuffixSet(t *testing.T) {
|
func TestSizeSuffixSet(t *testing.T) {
|
||||||
for i, test := range []struct {
|
for _, test := range []struct {
|
||||||
in string
|
in string
|
||||||
want int64
|
want int64
|
||||||
err bool
|
err bool
|
||||||
|
@ -56,13 +55,12 @@ func TestSizeSuffixSet(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
ss := SizeSuffix(0)
|
ss := SizeSuffix(0)
|
||||||
err := ss.Set(test.in)
|
err := ss.Set(test.in)
|
||||||
if (err != nil) != test.err {
|
if test.err {
|
||||||
t.Errorf("%d: Expecting error %v but got error %v", i, test.err, err)
|
require.Error(t, err)
|
||||||
}
|
} else {
|
||||||
got := int64(ss)
|
require.NoError(t, err)
|
||||||
if test.want != got {
|
|
||||||
t.Errorf("%d: Want %v got %v", i, test.want, got)
|
|
||||||
}
|
}
|
||||||
|
assert.Equal(t, test.want, int64(ss))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,12 +73,8 @@ func TestReveal(t *testing.T) {
|
||||||
{"2sTcyNrA", "potato"},
|
{"2sTcyNrA", "potato"},
|
||||||
} {
|
} {
|
||||||
got := Reveal(test.in)
|
got := Reveal(test.in)
|
||||||
if got != test.want {
|
assert.Equal(t, test.want, got)
|
||||||
t.Errorf("%q: want %q got %q", test.in, test.want, got)
|
assert.Equal(t, test.in, Obscure(got), "not bidirectional")
|
||||||
}
|
|
||||||
if Obscure(got) != test.in {
|
|
||||||
t.Errorf("%q: wasn't bidirectional", test.in)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,15 +91,11 @@ func TestConfigLoad(t *testing.T) {
|
||||||
}
|
}
|
||||||
sections := c.GetSectionList()
|
sections := c.GetSectionList()
|
||||||
var expect = []string{"RCLONE_ENCRYPT_V0", "nounc", "unc"}
|
var expect = []string{"RCLONE_ENCRYPT_V0", "nounc", "unc"}
|
||||||
if !reflect.DeepEqual(sections, expect) {
|
assert.Equal(t, expect, sections)
|
||||||
t.Fatalf("%v != %v", sections, expect)
|
|
||||||
}
|
|
||||||
|
|
||||||
keys := c.GetKeyList("nounc")
|
keys := c.GetKeyList("nounc")
|
||||||
expect = []string{"type", "nounc"}
|
expect = []string{"type", "nounc"}
|
||||||
if !reflect.DeepEqual(keys, expect) {
|
assert.Equal(t, expect, keys)
|
||||||
t.Fatalf("%v != %v", keys, expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigLoadEncrypted(t *testing.T) {
|
func TestConfigLoadEncrypted(t *testing.T) {
|
||||||
|
@ -119,24 +109,16 @@ func TestConfigLoadEncrypted(t *testing.T) {
|
||||||
|
|
||||||
// Set correct password
|
// Set correct password
|
||||||
err = setPassword("asdf")
|
err = setPassword("asdf")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
c, err := loadConfigFile()
|
c, err := loadConfigFile()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
sections := c.GetSectionList()
|
sections := c.GetSectionList()
|
||||||
var expect = []string{"nounc", "unc"}
|
var expect = []string{"nounc", "unc"}
|
||||||
if !reflect.DeepEqual(sections, expect) {
|
assert.Equal(t, expect, sections)
|
||||||
t.Fatalf("%v != %v", sections, expect)
|
|
||||||
}
|
|
||||||
|
|
||||||
keys := c.GetKeyList("nounc")
|
keys := c.GetKeyList("nounc")
|
||||||
expect = []string{"type", "nounc"}
|
expect = []string{"type", "nounc"}
|
||||||
if !reflect.DeepEqual(keys, expect) {
|
assert.Equal(t, expect, keys)
|
||||||
t.Fatalf("%v != %v", keys, expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigLoadEncryptedFailures(t *testing.T) {
|
func TestConfigLoadEncryptedFailures(t *testing.T) {
|
||||||
|
@ -147,36 +129,23 @@ func TestConfigLoadEncryptedFailures(t *testing.T) {
|
||||||
ConfigPath = "./testdata/enc-short.conf"
|
ConfigPath = "./testdata/enc-short.conf"
|
||||||
defer func() { ConfigPath = oldConfigPath }()
|
defer func() { ConfigPath = oldConfigPath }()
|
||||||
_, err = loadConfigFile()
|
_, err = loadConfigFile()
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error")
|
|
||||||
}
|
|
||||||
t.Log("Correctly got:", err)
|
|
||||||
|
|
||||||
// This file contains invalid base64 characters.
|
// This file contains invalid base64 characters.
|
||||||
ConfigPath = "./testdata/enc-invalid.conf"
|
ConfigPath = "./testdata/enc-invalid.conf"
|
||||||
_, err = loadConfigFile()
|
_, err = loadConfigFile()
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error")
|
|
||||||
}
|
|
||||||
t.Log("Correctly got:", err)
|
|
||||||
|
|
||||||
// This file contains invalid base64 characters.
|
// This file contains invalid base64 characters.
|
||||||
ConfigPath = "./testdata/enc-too-new.conf"
|
ConfigPath = "./testdata/enc-too-new.conf"
|
||||||
_, err = loadConfigFile()
|
_, err = loadConfigFile()
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error")
|
|
||||||
}
|
|
||||||
t.Log("Correctly got:", err)
|
|
||||||
|
|
||||||
// This file contains invalid base64 characters.
|
// This file contains invalid base64 characters.
|
||||||
ConfigPath = "./testdata/filenotfound.conf"
|
ConfigPath = "./testdata/filenotfound.conf"
|
||||||
c, err := loadConfigFile()
|
c, err := loadConfigFile()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
require.Len(t, c.GetSectionList(), 0, "Expected 0-length section")
|
||||||
}
|
|
||||||
if len(c.GetSectionList()) != 0 {
|
|
||||||
t.Fatalf("Expected 0-length section, got %d entries", len(c.GetSectionList()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPassword(t *testing.T) {
|
func TestPassword(t *testing.T) {
|
||||||
|
@ -186,15 +155,11 @@ func TestPassword(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
// Empty password should give error
|
// Empty password should give error
|
||||||
err = setPassword(" \t ")
|
err = setPassword(" \t ")
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test invalid utf8 sequence
|
// Test invalid utf8 sequence
|
||||||
err = setPassword(string([]byte{0xff, 0xfe, 0xfd}) + "abc")
|
err = setPassword(string([]byte{0xff, 0xfe, 0xfd}) + "abc")
|
||||||
if err == nil {
|
require.Error(t, err)
|
||||||
t.Fatal("expected error")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simple check of wrong passwords
|
// Simple check of wrong passwords
|
||||||
hashedKeyCompare(t, "mis", "match", false)
|
hashedKeyCompare(t, "mis", "match", false)
|
||||||
|
@ -212,21 +177,16 @@ func TestPassword(t *testing.T) {
|
||||||
|
|
||||||
func hashedKeyCompare(t *testing.T, a, b string, shouldMatch bool) {
|
func hashedKeyCompare(t *testing.T, a, b string, shouldMatch bool) {
|
||||||
err := setPassword(a)
|
err := setPassword(a)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
k1 := configKey
|
k1 := configKey
|
||||||
|
|
||||||
err = setPassword(b)
|
err = setPassword(b)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
k2 := configKey
|
k2 := configKey
|
||||||
matches := bytes.Equal(k1, k2)
|
|
||||||
if shouldMatch && !matches {
|
if shouldMatch {
|
||||||
t.Fatalf("%v != %v", k1, k2)
|
assert.Equal(t, k1, k2)
|
||||||
}
|
} else {
|
||||||
if !shouldMatch && matches {
|
assert.NotEqual(t, k1, k2)
|
||||||
t.Fatalf("%v == %v", k1, k2)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAgeSuffix(t *testing.T) {
|
func TestAgeSuffix(t *testing.T) {
|
||||||
for i, test := range []struct {
|
for _, test := range []struct {
|
||||||
in string
|
in string
|
||||||
want float64
|
want float64
|
||||||
err bool
|
err bool
|
||||||
|
@ -33,15 +33,12 @@ func TestAgeSuffix(t *testing.T) {
|
||||||
{"1x", 0, true},
|
{"1x", 0, true},
|
||||||
} {
|
} {
|
||||||
duration, err := ParseDuration(test.in)
|
duration, err := ParseDuration(test.in)
|
||||||
if (err != nil) != test.err {
|
if test.err {
|
||||||
t.Errorf("%d: Expecting error %v but got error %v", i, test.err, err)
|
require.Error(t, err)
|
||||||
continue
|
} else {
|
||||||
}
|
require.NoError(t, err)
|
||||||
|
|
||||||
got := float64(duration)
|
|
||||||
if test.want != got {
|
|
||||||
t.Errorf("%d: Want %v got %v", i, test.want, got)
|
|
||||||
}
|
}
|
||||||
|
assert.Equal(t, test.want, float64(duration))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,9 +65,7 @@ func testFile(t *testing.T, contents string) *string {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
err := out.Close()
|
err := out.Close()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
_, err = out.Write([]byte(contents))
|
_, err = out.Write([]byte(contents))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -182,13 +177,9 @@ func TestNewFilterIncludeFiles(t *testing.T) {
|
||||||
f, err := NewFilter()
|
f, err := NewFilter()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = f.AddFile("file1.jpg")
|
err = f.AddFile("file1.jpg")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
err = f.AddFile("/file2.jpg")
|
err = f.AddFile("/file2.jpg")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
assert.Equal(t, filesMap{
|
assert.Equal(t, filesMap{
|
||||||
"file1.jpg": {},
|
"file1.jpg": {},
|
||||||
"file2.jpg": {},
|
"file2.jpg": {},
|
||||||
|
@ -200,9 +191,7 @@ func TestNewFilterIncludeFiles(t *testing.T) {
|
||||||
{"potato/file2.jpg", 2, 0, false},
|
{"potato/file2.jpg", 2, 0, false},
|
||||||
{"file3.jpg", 3, 0, false},
|
{"file3.jpg", 3, 0, false},
|
||||||
})
|
})
|
||||||
if f.InActive() {
|
assert.False(t, f.InActive())
|
||||||
t.Errorf("want !InActive")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewFilterIncludeFilesDirs(t *testing.T) {
|
func TestNewFilterIncludeFilesDirs(t *testing.T) {
|
||||||
|
@ -215,9 +204,7 @@ func TestNewFilterIncludeFilesDirs(t *testing.T) {
|
||||||
"/path/to/dir2/file4.png",
|
"/path/to/dir2/file4.png",
|
||||||
} {
|
} {
|
||||||
err = f.AddFile(path)
|
err = f.AddFile(path)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
assert.Equal(t, filesMap{
|
assert.Equal(t, filesMap{
|
||||||
"path": {},
|
"path": {},
|
||||||
|
@ -248,9 +235,7 @@ func TestNewFilterMinSize(t *testing.T) {
|
||||||
{"file2.jpg", 101, 0, true},
|
{"file2.jpg", 101, 0, true},
|
||||||
{"potato/file2.jpg", 99, 0, false},
|
{"potato/file2.jpg", 99, 0, false},
|
||||||
})
|
})
|
||||||
if f.InActive() {
|
assert.False(t, f.InActive())
|
||||||
t.Errorf("want !InActive")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewFilterMaxSize(t *testing.T) {
|
func TestNewFilterMaxSize(t *testing.T) {
|
||||||
|
@ -262,9 +247,7 @@ func TestNewFilterMaxSize(t *testing.T) {
|
||||||
{"file2.jpg", 101, 0, false},
|
{"file2.jpg", 101, 0, false},
|
||||||
{"potato/file2.jpg", 99, 0, true},
|
{"potato/file2.jpg", 99, 0, true},
|
||||||
})
|
})
|
||||||
if f.InActive() {
|
assert.False(t, f.InActive())
|
||||||
t.Errorf("want !InActive")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewFilterMinAndMaxAge(t *testing.T) {
|
func TestNewFilterMinAndMaxAge(t *testing.T) {
|
||||||
|
@ -279,9 +262,7 @@ func TestNewFilterMinAndMaxAge(t *testing.T) {
|
||||||
{"potato/file1.jpg", 98, 1440000003, true},
|
{"potato/file1.jpg", 98, 1440000003, true},
|
||||||
{"potato/file2.jpg", 99, 1440000004, false},
|
{"potato/file2.jpg", 99, 1440000004, false},
|
||||||
})
|
})
|
||||||
if f.InActive() {
|
assert.False(t, f.InActive())
|
||||||
t.Errorf("want !InActive")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewFilterMinAge(t *testing.T) {
|
func TestNewFilterMinAge(t *testing.T) {
|
||||||
|
@ -295,9 +276,7 @@ func TestNewFilterMinAge(t *testing.T) {
|
||||||
{"potato/file1.jpg", 98, 1440000003, false},
|
{"potato/file1.jpg", 98, 1440000003, false},
|
||||||
{"potato/file2.jpg", 99, 1440000004, false},
|
{"potato/file2.jpg", 99, 1440000004, false},
|
||||||
})
|
})
|
||||||
if f.InActive() {
|
assert.False(t, f.InActive())
|
||||||
t.Errorf("want !InActive")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewFilterMaxAge(t *testing.T) {
|
func TestNewFilterMaxAge(t *testing.T) {
|
||||||
|
@ -311,9 +290,7 @@ func TestNewFilterMaxAge(t *testing.T) {
|
||||||
{"potato/file1.jpg", 98, 1440000003, true},
|
{"potato/file1.jpg", 98, 1440000003, true},
|
||||||
{"potato/file2.jpg", 99, 1440000004, true},
|
{"potato/file2.jpg", 99, 1440000004, true},
|
||||||
})
|
})
|
||||||
if f.InActive() {
|
assert.False(t, f.InActive())
|
||||||
t.Errorf("want !InActive")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewFilterMatches(t *testing.T) {
|
func TestNewFilterMatches(t *testing.T) {
|
||||||
|
@ -363,9 +340,7 @@ func TestNewFilterMatches(t *testing.T) {
|
||||||
{"sausage4", false},
|
{"sausage4", false},
|
||||||
{"a", true},
|
{"a", true},
|
||||||
})
|
})
|
||||||
if f.InActive() {
|
assert.False(t, f.InActive())
|
||||||
t.Errorf("want !InActive")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterForEachLine(t *testing.T) {
|
func TestFilterForEachLine(t *testing.T) {
|
||||||
|
@ -382,23 +357,15 @@ five
|
||||||
six `)
|
six `)
|
||||||
defer func() {
|
defer func() {
|
||||||
err := os.Remove(*file)
|
err := os.Remove(*file)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
lines := []string{}
|
lines := []string{}
|
||||||
err := forEachLine(*file, func(s string) error {
|
err := forEachLine(*file, func(s string) error {
|
||||||
lines = append(lines, s)
|
lines = append(lines, s)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Error(err)
|
assert.Equal(t, "one,two,three,four,five,six", strings.Join(lines, ","))
|
||||||
}
|
|
||||||
got := strings.Join(lines, ",")
|
|
||||||
want := "one,two,three,four,five,six"
|
|
||||||
if want != got {
|
|
||||||
t.Errorf("want %q got %q", want, got)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterMatchesFromDocs(t *testing.T) {
|
func TestFilterMatchesFromDocs(t *testing.T) {
|
||||||
|
@ -443,7 +410,7 @@ func TestFilterMatchesFromDocs(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
included := f.Include(test.file, 0, time.Unix(0, 0))
|
included := f.Include(test.file, 0, time.Unix(0, 0))
|
||||||
if included != test.included {
|
if included != test.included {
|
||||||
t.Logf("%q match %q: want %v got %v", test.glob, test.file, test.included, included)
|
t.Errorf("%q match %q: want %v got %v", test.glob, test.file, test.included, included)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
195
fs/hash_test.go
195
fs/hash_test.go
|
@ -6,95 +6,54 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHashSet(t *testing.T) {
|
func TestHashSet(t *testing.T) {
|
||||||
var h fs.HashSet
|
var h fs.HashSet
|
||||||
|
|
||||||
if h.Count() != 0 {
|
assert.Equal(t, 0, h.Count())
|
||||||
t.Fatalf("expected empty set to have 0 elements, got %d", h.Count())
|
|
||||||
}
|
|
||||||
a := h.Array()
|
a := h.Array()
|
||||||
if len(a) != 0 {
|
assert.Len(t, a, 0)
|
||||||
t.Fatalf("expected empty slice, got %d", len(a))
|
|
||||||
}
|
|
||||||
|
|
||||||
h = h.Add(fs.HashMD5)
|
h = h.Add(fs.HashMD5)
|
||||||
if h.Count() != 1 {
|
assert.Equal(t, 1, h.Count())
|
||||||
t.Fatalf("expected 1 element, got %d", h.Count())
|
assert.Equal(t, fs.HashMD5, h.GetOne())
|
||||||
}
|
|
||||||
if h.GetOne() != fs.HashMD5 {
|
|
||||||
t.Fatalf("expected HashMD5, got %v", h.GetOne())
|
|
||||||
}
|
|
||||||
a = h.Array()
|
a = h.Array()
|
||||||
if len(a) != 1 {
|
assert.Len(t, a, 1)
|
||||||
t.Fatalf("expected 1 element, got %d", len(a))
|
assert.Equal(t, a[0], fs.HashMD5)
|
||||||
}
|
|
||||||
if a[0] != fs.HashMD5 {
|
|
||||||
t.Fatalf("expected HashMD5, got %v", a[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test overlap, with all hashes
|
// Test overlap, with all hashes
|
||||||
h = h.Overlap(fs.SupportedHashes)
|
h = h.Overlap(fs.SupportedHashes)
|
||||||
if h.Count() != 1 {
|
assert.Equal(t, 1, h.Count())
|
||||||
t.Fatalf("expected 1 element, got %d", h.Count())
|
assert.Equal(t, fs.HashMD5, h.GetOne())
|
||||||
}
|
assert.True(t, h.SubsetOf(fs.SupportedHashes))
|
||||||
if h.GetOne() != fs.HashMD5 {
|
assert.True(t, h.SubsetOf(fs.NewHashSet(fs.HashMD5)))
|
||||||
t.Fatalf("expected HashMD5, got %v", h.GetOne())
|
|
||||||
}
|
|
||||||
if !h.SubsetOf(fs.SupportedHashes) {
|
|
||||||
t.Fatalf("expected to be subset of all hashes")
|
|
||||||
}
|
|
||||||
if !h.SubsetOf(fs.NewHashSet(fs.HashMD5)) {
|
|
||||||
t.Fatalf("expected to be subset of itself")
|
|
||||||
}
|
|
||||||
|
|
||||||
h = h.Add(fs.HashSHA1)
|
h = h.Add(fs.HashSHA1)
|
||||||
if h.Count() != 2 {
|
assert.Equal(t, 2, h.Count())
|
||||||
t.Fatalf("expected 2 elements, got %d", h.Count())
|
|
||||||
}
|
|
||||||
one := h.GetOne()
|
one := h.GetOne()
|
||||||
if !(one == fs.HashMD5 || one == fs.HashSHA1) {
|
if !(one == fs.HashMD5 || one == fs.HashSHA1) {
|
||||||
t.Fatalf("expected to be either MD5 or SHA1, got %v", one)
|
t.Fatalf("expected to be either MD5 or SHA1, got %v", one)
|
||||||
}
|
}
|
||||||
if !h.SubsetOf(fs.SupportedHashes) {
|
assert.True(t, h.SubsetOf(fs.SupportedHashes))
|
||||||
t.Fatalf("expected to be subset of all hashes")
|
assert.False(t, h.SubsetOf(fs.NewHashSet(fs.HashMD5)))
|
||||||
}
|
assert.False(t, h.SubsetOf(fs.NewHashSet(fs.HashSHA1)))
|
||||||
if h.SubsetOf(fs.NewHashSet(fs.HashMD5)) {
|
assert.True(t, h.SubsetOf(fs.NewHashSet(fs.HashMD5, fs.HashSHA1)))
|
||||||
t.Fatalf("did not expect to be subset of only MD5")
|
|
||||||
}
|
|
||||||
if h.SubsetOf(fs.NewHashSet(fs.HashSHA1)) {
|
|
||||||
t.Fatalf("did not expect to be subset of only SHA1")
|
|
||||||
}
|
|
||||||
if !h.SubsetOf(fs.NewHashSet(fs.HashMD5, fs.HashSHA1)) {
|
|
||||||
t.Fatalf("expected to be subset of MD5/SHA1")
|
|
||||||
}
|
|
||||||
a = h.Array()
|
a = h.Array()
|
||||||
if len(a) != 2 {
|
assert.Len(t, a, 2)
|
||||||
t.Fatalf("expected 2 elements, got %d", len(a))
|
|
||||||
}
|
|
||||||
|
|
||||||
ol := h.Overlap(fs.NewHashSet(fs.HashMD5))
|
ol := h.Overlap(fs.NewHashSet(fs.HashMD5))
|
||||||
if ol.Count() != 1 {
|
assert.Equal(t, 1, ol.Count())
|
||||||
t.Fatalf("expected 1 element overlap, got %d", ol.Count())
|
assert.True(t, ol.Contains(fs.HashMD5))
|
||||||
}
|
assert.False(t, ol.Contains(fs.HashSHA1))
|
||||||
if !ol.Contains(fs.HashMD5) {
|
|
||||||
t.Fatalf("expected overlap to be MD5, got %v", ol)
|
|
||||||
}
|
|
||||||
if ol.Contains(fs.HashSHA1) {
|
|
||||||
t.Fatalf("expected overlap NOT to contain SHA1, got %v", ol)
|
|
||||||
}
|
|
||||||
|
|
||||||
ol = h.Overlap(fs.NewHashSet(fs.HashMD5, fs.HashSHA1))
|
ol = h.Overlap(fs.NewHashSet(fs.HashMD5, fs.HashSHA1))
|
||||||
if ol.Count() != 2 {
|
assert.Equal(t, 2, ol.Count())
|
||||||
t.Fatalf("expected 2 element overlap, got %d", ol.Count())
|
assert.True(t, ol.Contains(fs.HashMD5))
|
||||||
}
|
assert.True(t, ol.Contains(fs.HashSHA1))
|
||||||
if !ol.Contains(fs.HashMD5) {
|
|
||||||
t.Fatalf("expected overlap to contain MD5, got %v", ol)
|
|
||||||
}
|
|
||||||
if !ol.Contains(fs.HashSHA1) {
|
|
||||||
t.Fatalf("expected overlap to contain SHA1, got %v", ol)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type hashTest struct {
|
type hashTest struct {
|
||||||
|
@ -124,31 +83,19 @@ func TestMultiHasher(t *testing.T) {
|
||||||
for _, test := range hashTestSet {
|
for _, test := range hashTestSet {
|
||||||
mh := fs.NewMultiHasher()
|
mh := fs.NewMultiHasher()
|
||||||
n, err := io.Copy(mh, bytes.NewBuffer(test.input))
|
n, err := io.Copy(mh, bytes.NewBuffer(test.input))
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
assert.Len(t, test.input, int(n))
|
||||||
}
|
|
||||||
if int(n) != len(test.input) {
|
|
||||||
t.Fatalf("copy mismatch: %d != %d", n, len(test.input))
|
|
||||||
}
|
|
||||||
sums := mh.Sums()
|
sums := mh.Sums()
|
||||||
for k, v := range sums {
|
for k, v := range sums {
|
||||||
expect, ok := test.output[k]
|
expect, ok := test.output[k]
|
||||||
if !ok {
|
require.True(t, ok)
|
||||||
t.Errorf("Unknown hash type %v, sum: %q", k, v)
|
assert.Equal(t, v, expect)
|
||||||
}
|
|
||||||
if expect != v {
|
|
||||||
t.Errorf("hash %v mismatch %q != %q", k, v, expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Test that all are present
|
// Test that all are present
|
||||||
for k, v := range test.output {
|
for k, v := range test.output {
|
||||||
expect, ok := sums[k]
|
expect, ok := sums[k]
|
||||||
if !ok {
|
require.True(t, ok)
|
||||||
t.Errorf("did not calculate hash type %v, sum: %q", k, v)
|
assert.Equal(t, v, expect)
|
||||||
}
|
|
||||||
if expect != v {
|
|
||||||
t.Errorf("hash %d mismatch %q != %q", k, v, expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,47 +108,28 @@ func TestMultiHasherTypes(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
n, err := io.Copy(mh, bytes.NewBuffer(test.input))
|
n, err := io.Copy(mh, bytes.NewBuffer(test.input))
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
assert.Len(t, test.input, int(n))
|
||||||
}
|
|
||||||
if int(n) != len(test.input) {
|
|
||||||
t.Fatalf("copy mismatch: %d != %d", n, len(test.input))
|
|
||||||
}
|
|
||||||
sums := mh.Sums()
|
sums := mh.Sums()
|
||||||
if len(sums) != 1 {
|
assert.Len(t, sums, 1)
|
||||||
t.Fatalf("expected 1 sum, got %d", len(sums))
|
assert.Equal(t, sums[h], test.output[h])
|
||||||
}
|
|
||||||
expect := test.output[h]
|
|
||||||
if expect != sums[h] {
|
|
||||||
t.Errorf("hash %v mismatch %q != %q", h, sums[h], expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHashStream(t *testing.T) {
|
func TestHashStream(t *testing.T) {
|
||||||
for _, test := range hashTestSet {
|
for _, test := range hashTestSet {
|
||||||
sums, err := fs.HashStream(bytes.NewBuffer(test.input))
|
sums, err := fs.HashStream(bytes.NewBuffer(test.input))
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
for k, v := range sums {
|
for k, v := range sums {
|
||||||
expect, ok := test.output[k]
|
expect, ok := test.output[k]
|
||||||
if !ok {
|
require.True(t, ok)
|
||||||
t.Errorf("Unknown hash type %v, sum: %q", k, v)
|
assert.Equal(t, v, expect)
|
||||||
}
|
|
||||||
if expect != v {
|
|
||||||
t.Errorf("hash %v mismatch %q != %q", k, v, expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Test that all are present
|
// Test that all are present
|
||||||
for k, v := range test.output {
|
for k, v := range test.output {
|
||||||
expect, ok := sums[k]
|
expect, ok := sums[k]
|
||||||
if !ok {
|
require.True(t, ok)
|
||||||
t.Errorf("did not calculate hash type %v, sum: %q", k, v)
|
assert.Equal(t, v, expect)
|
||||||
}
|
|
||||||
if expect != v {
|
|
||||||
t.Errorf("hash %v mismatch %q != %q", k, v, expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,51 +138,24 @@ func TestHashStreamTypes(t *testing.T) {
|
||||||
h := fs.HashSHA1
|
h := fs.HashSHA1
|
||||||
for _, test := range hashTestSet {
|
for _, test := range hashTestSet {
|
||||||
sums, err := fs.HashStreamTypes(bytes.NewBuffer(test.input), fs.NewHashSet(h))
|
sums, err := fs.HashStreamTypes(bytes.NewBuffer(test.input), fs.NewHashSet(h))
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
assert.Len(t, sums, 1)
|
||||||
}
|
assert.Equal(t, sums[h], test.output[h])
|
||||||
if len(sums) != 1 {
|
|
||||||
t.Fatalf("expected 1 sum, got %d", len(sums))
|
|
||||||
}
|
|
||||||
expect := test.output[h]
|
|
||||||
if expect != sums[h] {
|
|
||||||
t.Errorf("hash %d mismatch %q != %q", h, sums[h], expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHashSetStringer(t *testing.T) {
|
func TestHashSetStringer(t *testing.T) {
|
||||||
h := fs.NewHashSet(fs.HashSHA1, fs.HashMD5)
|
h := fs.NewHashSet(fs.HashSHA1, fs.HashMD5)
|
||||||
s := h.String()
|
assert.Equal(t, h.String(), "[MD5, SHA-1]")
|
||||||
expect := "[MD5, SHA-1]"
|
|
||||||
if s != expect {
|
|
||||||
t.Errorf("unexpected stringer: was %q, expected %q", s, expect)
|
|
||||||
}
|
|
||||||
h = fs.NewHashSet(fs.HashSHA1)
|
h = fs.NewHashSet(fs.HashSHA1)
|
||||||
s = h.String()
|
assert.Equal(t, h.String(), "[SHA-1]")
|
||||||
expect = "[SHA-1]"
|
|
||||||
if s != expect {
|
|
||||||
t.Errorf("unexpected stringer: was %q, expected %q", s, expect)
|
|
||||||
}
|
|
||||||
h = fs.NewHashSet()
|
h = fs.NewHashSet()
|
||||||
s = h.String()
|
assert.Equal(t, h.String(), "[]")
|
||||||
expect = "[]"
|
|
||||||
if s != expect {
|
|
||||||
t.Errorf("unexpected stringer: was %q, expected %q", s, expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHashStringer(t *testing.T) {
|
func TestHashStringer(t *testing.T) {
|
||||||
h := fs.HashMD5
|
h := fs.HashMD5
|
||||||
s := h.String()
|
assert.Equal(t, h.String(), "MD5")
|
||||||
expect := "MD5"
|
|
||||||
if s != expect {
|
|
||||||
t.Errorf("unexpected stringer: was %q, expected %q", s, expect)
|
|
||||||
}
|
|
||||||
h = fs.HashNone
|
h = fs.HashNone
|
||||||
s = h.String()
|
assert.Equal(t, h.String(), "None")
|
||||||
expect = "None"
|
|
||||||
if s != expect {
|
|
||||||
t.Errorf("unexpected stringer: was %q, expected %q", s, expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import (
|
||||||
_ "github.com/ncw/rclone/fs/all" // import all fs
|
_ "github.com/ncw/rclone/fs/all" // import all fs
|
||||||
"github.com/ncw/rclone/fstest"
|
"github.com/ncw/rclone/fstest"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
|
@ -271,9 +272,7 @@ func TestCopyWithDryRun(t *testing.T) {
|
||||||
fs.Config.DryRun = true
|
fs.Config.DryRun = true
|
||||||
err := fs.CopyDir(r.fremote, r.flocal)
|
err := fs.CopyDir(r.fremote, r.flocal)
|
||||||
fs.Config.DryRun = false
|
fs.Config.DryRun = false
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Copy failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file1)
|
fstest.CheckItems(t, r.flocal, file1)
|
||||||
fstest.CheckItems(t, r.fremote)
|
fstest.CheckItems(t, r.fremote)
|
||||||
|
@ -286,9 +285,7 @@ func TestCopy(t *testing.T) {
|
||||||
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
||||||
|
|
||||||
err := fs.CopyDir(r.fremote, r.flocal)
|
err := fs.CopyDir(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Copy failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file1)
|
fstest.CheckItems(t, r.flocal, file1)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
@ -305,7 +302,7 @@ func TestCopyNoTraverse(t *testing.T) {
|
||||||
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
||||||
|
|
||||||
err := fs.CopyDir(r.fremote, r.flocal)
|
err := fs.CopyDir(r.fremote, r.flocal)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file1)
|
fstest.CheckItems(t, r.flocal, file1)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
@ -322,7 +319,7 @@ func TestSyncNoTraverse(t *testing.T) {
|
||||||
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
|
||||||
|
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file1)
|
fstest.CheckItems(t, r.flocal, file1)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
@ -340,9 +337,7 @@ func TestCopyWithDepth(t *testing.T) {
|
||||||
defer func() { fs.Config.MaxDepth = -1 }()
|
defer func() { fs.Config.MaxDepth = -1 }()
|
||||||
|
|
||||||
err := fs.CopyDir(r.fremote, r.flocal)
|
err := fs.CopyDir(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Copy failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file1, file2)
|
fstest.CheckItems(t, r.flocal, file1, file2)
|
||||||
fstest.CheckItems(t, r.fremote, file2)
|
fstest.CheckItems(t, r.fremote, file2)
|
||||||
|
@ -356,16 +351,12 @@ func TestServerSideCopy(t *testing.T) {
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
|
||||||
fremoteCopy, finaliseCopy, err := fstest.RandomRemote(*RemoteName, *SubDir)
|
fremoteCopy, finaliseCopy, err := fstest.RandomRemote(*RemoteName, *SubDir)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Failed to open remote copy %q: %v", *RemoteName, err)
|
|
||||||
}
|
|
||||||
defer finaliseCopy()
|
defer finaliseCopy()
|
||||||
t.Logf("Server side copy (if possible) %v -> %v", r.fremote, fremoteCopy)
|
t.Logf("Server side copy (if possible) %v -> %v", r.fremote, fremoteCopy)
|
||||||
|
|
||||||
err = fs.CopyDir(fremoteCopy, r.fremote)
|
err = fs.CopyDir(fremoteCopy, r.fremote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Server Side Copy failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, fremoteCopy, file1)
|
fstest.CheckItems(t, fremoteCopy, file1)
|
||||||
}
|
}
|
||||||
|
@ -379,13 +370,9 @@ func TestLsd(t *testing.T) {
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := fs.ListDir(r.fremote, &buf)
|
err := fs.ListDir(r.fremote, &buf)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("ListDir failed: %v", err)
|
|
||||||
}
|
|
||||||
res := buf.String()
|
res := buf.String()
|
||||||
if !strings.Contains(res, "sub dir\n") {
|
assert.Contains(t, res, "sub dir\n")
|
||||||
t.Fatalf("Result wrong %q", res)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that if the local file doesn't exist when we copy it up,
|
// Check that if the local file doesn't exist when we copy it up,
|
||||||
|
@ -398,14 +385,10 @@ func TestCopyAfterDelete(t *testing.T) {
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
|
||||||
err := fs.Mkdir(r.flocal)
|
err := fs.Mkdir(r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Mkdir failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = fs.CopyDir(r.fremote, r.flocal)
|
err = fs.CopyDir(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Copy failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal)
|
fstest.CheckItems(t, r.flocal)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
@ -419,9 +402,7 @@ func TestCopyRedownload(t *testing.T) {
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
|
||||||
err := fs.CopyDir(r.flocal, r.fremote)
|
err := fs.CopyDir(r.flocal, r.fremote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Copy failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file1)
|
fstest.CheckItems(t, r.flocal, file1)
|
||||||
}
|
}
|
||||||
|
@ -440,15 +421,10 @@ func TestSyncBasedOnCheckSum(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Initial sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should have transferred exactly one file.
|
// We should have transferred exactly one file.
|
||||||
if fs.Stats.GetTransfers() != 1 {
|
assert.Equal(t, int64(1), fs.Stats.GetTransfers())
|
||||||
t.Fatalf("Sync 1: want 1 transfer, got %d", fs.Stats.GetTransfers())
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
|
||||||
// Change last modified date only
|
// Change last modified date only
|
||||||
|
@ -457,15 +433,10 @@ func TestSyncBasedOnCheckSum(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err = fs.Sync(r.fremote, r.flocal)
|
err = fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should have transferred no files
|
// We should have transferred no files
|
||||||
if fs.Stats.GetTransfers() != 0 {
|
assert.Equal(t, int64(0), fs.Stats.GetTransfers())
|
||||||
t.Fatalf("Sync 2: want 0 transfers, got %d", fs.Stats.GetTransfers())
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file2)
|
fstest.CheckItems(t, r.flocal, file2)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
}
|
}
|
||||||
|
@ -484,15 +455,10 @@ func TestSyncSizeOnly(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Initial sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should have transferred exactly one file.
|
// We should have transferred exactly one file.
|
||||||
if fs.Stats.GetTransfers() != 1 {
|
assert.Equal(t, int64(1), fs.Stats.GetTransfers())
|
||||||
t.Fatalf("Sync 1: want 1 transfer, got %d", fs.Stats.GetTransfers())
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
|
||||||
// Update mtime, md5sum but not length of file
|
// Update mtime, md5sum but not length of file
|
||||||
|
@ -501,15 +467,10 @@ func TestSyncSizeOnly(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err = fs.Sync(r.fremote, r.flocal)
|
err = fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should have transferred no files
|
// We should have transferred no files
|
||||||
if fs.Stats.GetTransfers() != 0 {
|
assert.Equal(t, int64(0), fs.Stats.GetTransfers())
|
||||||
t.Fatalf("Sync 2: want 0 transfers, got %d", fs.Stats.GetTransfers())
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file2)
|
fstest.CheckItems(t, r.flocal, file2)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
}
|
}
|
||||||
|
@ -528,15 +489,10 @@ func TestSyncIgnoreSize(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Initial sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should have transferred exactly one file.
|
// We should have transferred exactly one file.
|
||||||
if fs.Stats.GetTransfers() != 1 {
|
assert.Equal(t, int64(1), fs.Stats.GetTransfers())
|
||||||
t.Fatalf("Sync 1: want 1 transfer, got %d", fs.Stats.GetTransfers())
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
|
||||||
// Update size but not date of file
|
// Update size but not date of file
|
||||||
|
@ -545,15 +501,10 @@ func TestSyncIgnoreSize(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err = fs.Sync(r.fremote, r.flocal)
|
err = fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should have transferred no files
|
// We should have transferred no files
|
||||||
if fs.Stats.GetTransfers() != 0 {
|
assert.Equal(t, int64(0), fs.Stats.GetTransfers())
|
||||||
t.Fatalf("Sync 2: want 0 transfers, got %d", fs.Stats.GetTransfers())
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file2)
|
fstest.CheckItems(t, r.flocal, file2)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
}
|
}
|
||||||
|
@ -566,30 +517,22 @@ func TestSyncIgnoreTimes(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should have transferred exactly 0 files because the
|
// We should have transferred exactly 0 files because the
|
||||||
// files were identical.
|
// files were identical.
|
||||||
if fs.Stats.GetTransfers() != 0 {
|
assert.Equal(t, int64(0), fs.Stats.GetTransfers())
|
||||||
t.Fatalf("Sync 1: want 0 transfer, got %d", fs.Stats.GetTransfers())
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.Config.IgnoreTimes = true
|
fs.Config.IgnoreTimes = true
|
||||||
defer func() { fs.Config.IgnoreTimes = false }()
|
defer func() { fs.Config.IgnoreTimes = false }()
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err = fs.Sync(r.fremote, r.flocal)
|
err = fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should have transferred exactly one file even though the
|
// We should have transferred exactly one file even though the
|
||||||
// files were identical.
|
// files were identical.
|
||||||
if fs.Stats.GetTransfers() != 1 {
|
assert.Equal(t, int64(1), fs.Stats.GetTransfers())
|
||||||
t.Fatalf("Sync 2: want 1 transfer, got %d", fs.Stats.GetTransfers())
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file1)
|
fstest.CheckItems(t, r.flocal, file1)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
@ -605,9 +548,7 @@ func TestSyncIgnoreExisting(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.flocal, file1)
|
fstest.CheckItems(t, r.flocal, file1)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
|
||||||
|
@ -615,9 +556,7 @@ func TestSyncIgnoreExisting(t *testing.T) {
|
||||||
r.WriteFile("existing", "newpotatoes", t2)
|
r.WriteFile("existing", "newpotatoes", t2)
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err = fs.Sync(r.fremote, r.flocal)
|
err = fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
// Items should not change
|
// Items should not change
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
}
|
}
|
||||||
|
@ -630,9 +569,7 @@ func TestSyncAfterChangingModtimeOnly(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file1)
|
fstest.CheckItems(t, r.flocal, file1)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
@ -646,9 +583,7 @@ func TestSyncAfterAddingAFile(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.flocal, file1, file2)
|
fstest.CheckItems(t, r.flocal, file1, file2)
|
||||||
fstest.CheckItems(t, r.fremote, file1, file2)
|
fstest.CheckItems(t, r.fremote, file1, file2)
|
||||||
}
|
}
|
||||||
|
@ -663,9 +598,7 @@ func TestSyncAfterChangingFilesSizeOnly(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.flocal, file2)
|
fstest.CheckItems(t, r.flocal, file2)
|
||||||
fstest.CheckItems(t, r.fremote, file2)
|
fstest.CheckItems(t, r.fremote, file2)
|
||||||
}
|
}
|
||||||
|
@ -688,9 +621,7 @@ func TestSyncAfterChangingContentsOnly(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.flocal, file2)
|
fstest.CheckItems(t, r.flocal, file2)
|
||||||
fstest.CheckItems(t, r.fremote, file2)
|
fstest.CheckItems(t, r.fremote, file2)
|
||||||
}
|
}
|
||||||
|
@ -707,9 +638,7 @@ func TestSyncAfterRemovingAFileAndAddingAFileDryRun(t *testing.T) {
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
fs.Config.DryRun = false
|
fs.Config.DryRun = false
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.flocal, file3, file1)
|
fstest.CheckItems(t, r.flocal, file3, file1)
|
||||||
fstest.CheckItems(t, r.fremote, file3, file2)
|
fstest.CheckItems(t, r.fremote, file3, file2)
|
||||||
|
@ -727,9 +656,7 @@ func TestSyncAfterRemovingAFileAndAddingAFile(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.flocal, file1, file3)
|
fstest.CheckItems(t, r.flocal, file1, file3)
|
||||||
fstest.CheckItems(t, r.fremote, file1, file3)
|
fstest.CheckItems(t, r.fremote, file1, file3)
|
||||||
}
|
}
|
||||||
|
@ -747,9 +674,7 @@ func TestSyncAfterRemovingAFileAndAddingAFileWithErrors(t *testing.T) {
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
fs.Stats.Error()
|
fs.Stats.Error()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != fs.ErrorNotDeleting {
|
assert.Equal(t, fs.ErrorNotDeleting, err)
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.flocal, file1, file3)
|
fstest.CheckItems(t, r.flocal, file1, file3)
|
||||||
fstest.CheckItems(t, r.fremote, file1, file2, file3)
|
fstest.CheckItems(t, r.fremote, file1, file2, file3)
|
||||||
}
|
}
|
||||||
|
@ -806,18 +731,14 @@ func TestSyncWithExclude(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.fremote, file2, file1)
|
fstest.CheckItems(t, r.fremote, file2, file1)
|
||||||
|
|
||||||
// Now sync the other way round and check enormous doesn't get
|
// Now sync the other way round and check enormous doesn't get
|
||||||
// deleted as it is excluded from the sync
|
// deleted as it is excluded from the sync
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err = fs.Sync(r.flocal, r.fremote)
|
err = fs.Sync(r.flocal, r.fremote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.flocal, file2, file1, file3)
|
fstest.CheckItems(t, r.flocal, file2, file1, file3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -840,18 +761,14 @@ func TestSyncWithExcludeAndDeleteExcluded(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.fremote, file2)
|
fstest.CheckItems(t, r.fremote, file2)
|
||||||
|
|
||||||
// Check sync the other way round to make sure enormous gets
|
// Check sync the other way round to make sure enormous gets
|
||||||
// deleted even though it is excluded
|
// deleted even though it is excluded
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err = fs.Sync(r.flocal, r.fremote)
|
err = fs.Sync(r.flocal, r.fremote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.flocal, file2)
|
fstest.CheckItems(t, r.flocal, file2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,9 +803,7 @@ func TestSyncWithUpdateOlder(t *testing.T) {
|
||||||
|
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err := fs.Sync(r.fremote, r.flocal)
|
err := fs.Sync(r.fremote, r.flocal)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.fremote, oneO, twoF, threeO, fourF, fiveF)
|
fstest.CheckItems(t, r.fremote, oneO, twoF, threeO, fourF, fiveF)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -902,9 +817,7 @@ func TestServerSideMove(t *testing.T) {
|
||||||
fstest.CheckItems(t, r.fremote, file2, file1)
|
fstest.CheckItems(t, r.fremote, file2, file1)
|
||||||
|
|
||||||
fremoteMove, finaliseMove, err := fstest.RandomRemote(*RemoteName, *SubDir)
|
fremoteMove, finaliseMove, err := fstest.RandomRemote(*RemoteName, *SubDir)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Failed to open remote move %q: %v", *RemoteName, err)
|
|
||||||
}
|
|
||||||
defer finaliseMove()
|
defer finaliseMove()
|
||||||
t.Logf("Server side move (if possible) %v -> %v", r.fremote, fremoteMove)
|
t.Logf("Server side move (if possible) %v -> %v", r.fremote, fremoteMove)
|
||||||
|
|
||||||
|
@ -915,9 +828,7 @@ func TestServerSideMove(t *testing.T) {
|
||||||
// Do server side move
|
// Do server side move
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err = fs.MoveDir(fremoteMove, r.fremote)
|
err = fs.MoveDir(fremoteMove, r.fremote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Server Side Move failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.fremote)
|
fstest.CheckItems(t, r.fremote)
|
||||||
fstest.CheckItems(t, fremoteMove, file2, file1)
|
fstest.CheckItems(t, fremoteMove, file2, file1)
|
||||||
|
@ -925,9 +836,7 @@ func TestServerSideMove(t *testing.T) {
|
||||||
// Move it back again, dst does not exist this time
|
// Move it back again, dst does not exist this time
|
||||||
fs.Stats.ResetCounters()
|
fs.Stats.ResetCounters()
|
||||||
err = fs.MoveDir(r.fremote, fremoteMove)
|
err = fs.MoveDir(r.fremote, fremoteMove)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Server Side Move 2 failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.fremote, file2, file1)
|
fstest.CheckItems(t, r.fremote, file2, file1)
|
||||||
fstest.CheckItems(t, fremoteMove)
|
fstest.CheckItems(t, fremoteMove)
|
||||||
|
@ -943,16 +852,10 @@ func TestLs(t *testing.T) {
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := fs.List(r.fremote, &buf)
|
err := fs.List(r.fremote, &buf)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("List failed: %v", err)
|
|
||||||
}
|
|
||||||
res := buf.String()
|
res := buf.String()
|
||||||
if !strings.Contains(res, " 0 empty space\n") {
|
assert.Contains(t, res, " 0 empty space\n")
|
||||||
t.Errorf("empty space missing: %q", res)
|
assert.Contains(t, res, " 60 potato2\n")
|
||||||
}
|
|
||||||
if !strings.Contains(res, " 60 potato2\n") {
|
|
||||||
t.Errorf("potato2 missing: %q", res)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLsLong(t *testing.T) {
|
func TestLsLong(t *testing.T) {
|
||||||
|
@ -965,14 +868,10 @@ func TestLsLong(t *testing.T) {
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := fs.ListLong(r.fremote, &buf)
|
err := fs.ListLong(r.fremote, &buf)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("List failed: %v", err)
|
|
||||||
}
|
|
||||||
res := buf.String()
|
res := buf.String()
|
||||||
lines := strings.Split(strings.Trim(res, "\n"), "\n")
|
lines := strings.Split(strings.Trim(res, "\n"), "\n")
|
||||||
if len(lines) != 2 {
|
assert.Equal(t, 2, len(lines))
|
||||||
t.Fatalf("Wrong number of lines in list: %q", lines)
|
|
||||||
}
|
|
||||||
|
|
||||||
timeFormat := "2006-01-02 15:04:05.000000000"
|
timeFormat := "2006-01-02 15:04:05.000000000"
|
||||||
precision := r.fremote.Precision()
|
precision := r.fremote.Precision()
|
||||||
|
@ -1014,9 +913,7 @@ func TestMd5sum(t *testing.T) {
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := fs.Md5sum(r.fremote, &buf)
|
err := fs.Md5sum(r.fremote, &buf)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("List failed: %v", err)
|
|
||||||
}
|
|
||||||
res := buf.String()
|
res := buf.String()
|
||||||
if !strings.Contains(res, "d41d8cd98f00b204e9800998ecf8427e empty space\n") &&
|
if !strings.Contains(res, "d41d8cd98f00b204e9800998ecf8427e empty space\n") &&
|
||||||
!strings.Contains(res, " UNSUPPORTED empty space\n") &&
|
!strings.Contains(res, " UNSUPPORTED empty space\n") &&
|
||||||
|
@ -1040,9 +937,7 @@ func TestSha1sum(t *testing.T) {
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := fs.Sha1sum(r.fremote, &buf)
|
err := fs.Sha1sum(r.fremote, &buf)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("List failed: %v", err)
|
|
||||||
}
|
|
||||||
res := buf.String()
|
res := buf.String()
|
||||||
if !strings.Contains(res, "da39a3ee5e6b4b0d3255bfef95601890afd80709 empty space\n") &&
|
if !strings.Contains(res, "da39a3ee5e6b4b0d3255bfef95601890afd80709 empty space\n") &&
|
||||||
!strings.Contains(res, " UNSUPPORTED empty space\n") &&
|
!strings.Contains(res, " UNSUPPORTED empty space\n") &&
|
||||||
|
@ -1070,15 +965,9 @@ func TestCount(t *testing.T) {
|
||||||
defer func() { fs.Config.MaxDepth = -1 }()
|
defer func() { fs.Config.MaxDepth = -1 }()
|
||||||
|
|
||||||
objects, size, err := fs.Count(r.fremote)
|
objects, size, err := fs.Count(r.fremote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Count failed: %v", err)
|
assert.Equal(t, int64(2), objects)
|
||||||
}
|
assert.Equal(t, int64(60), size)
|
||||||
if objects != 2 {
|
|
||||||
t.Errorf("want 2 objects got %d", objects)
|
|
||||||
}
|
|
||||||
if size != 60 {
|
|
||||||
t.Errorf("want size 60 got %d", size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDelete(t *testing.T) {
|
func TestDelete(t *testing.T) {
|
||||||
|
@ -1095,9 +984,7 @@ func TestDelete(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := fs.Delete(r.fremote)
|
err := fs.Delete(r.fremote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Sync failed: %v", err)
|
|
||||||
}
|
|
||||||
fstest.CheckItems(t, r.fremote, file3)
|
fstest.CheckItems(t, r.fremote, file3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1157,19 +1044,13 @@ func TestCheckSizeOnly(t *testing.T) {
|
||||||
|
|
||||||
func (r *Run) checkWithDuplicates(t *testing.T, items ...fstest.Item) {
|
func (r *Run) checkWithDuplicates(t *testing.T, items ...fstest.Item) {
|
||||||
objects, size, err := fs.Count(r.fremote)
|
objects, size, err := fs.Count(r.fremote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Error listing: %v", err)
|
assert.Equal(t, int64(len(items)), objects)
|
||||||
}
|
|
||||||
if objects != int64(len(items)) {
|
|
||||||
t.Fatalf("Error listing want %d objects, got %d", len(items), objects)
|
|
||||||
}
|
|
||||||
wantSize := int64(0)
|
wantSize := int64(0)
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
wantSize += item.Size
|
wantSize += item.Size
|
||||||
}
|
}
|
||||||
if wantSize != size {
|
assert.Equal(t, wantSize, size)
|
||||||
t.Fatalf("Error listing want %d size, got %d", wantSize, size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeduplicateInteractive(t *testing.T) {
|
func TestDeduplicateInteractive(t *testing.T) {
|
||||||
|
@ -1185,9 +1066,7 @@ func TestDeduplicateInteractive(t *testing.T) {
|
||||||
r.checkWithDuplicates(t, file1, file2, file3)
|
r.checkWithDuplicates(t, file1, file2, file3)
|
||||||
|
|
||||||
err := fs.Deduplicate(r.fremote, fs.DeduplicateInteractive)
|
err := fs.Deduplicate(r.fremote, fs.DeduplicateInteractive)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("fs.Deduplicate returned error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
}
|
}
|
||||||
|
@ -1205,9 +1084,7 @@ func TestDeduplicateSkip(t *testing.T) {
|
||||||
r.checkWithDuplicates(t, file1, file2, file3)
|
r.checkWithDuplicates(t, file1, file2, file3)
|
||||||
|
|
||||||
err := fs.Deduplicate(r.fremote, fs.DeduplicateSkip)
|
err := fs.Deduplicate(r.fremote, fs.DeduplicateSkip)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("fs.Deduplicate returned error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
r.checkWithDuplicates(t, file1, file3)
|
r.checkWithDuplicates(t, file1, file3)
|
||||||
}
|
}
|
||||||
|
@ -1225,17 +1102,11 @@ func TestDeduplicateFirst(t *testing.T) {
|
||||||
r.checkWithDuplicates(t, file1, file2, file3)
|
r.checkWithDuplicates(t, file1, file2, file3)
|
||||||
|
|
||||||
err := fs.Deduplicate(r.fremote, fs.DeduplicateFirst)
|
err := fs.Deduplicate(r.fremote, fs.DeduplicateFirst)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("fs.Deduplicate returned error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
objects, size, err := fs.Count(r.fremote)
|
objects, size, err := fs.Count(r.fremote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Error listing: %v", err)
|
assert.Equal(t, 1, objects)
|
||||||
}
|
|
||||||
if objects != 1 {
|
|
||||||
t.Errorf("Expecting 1 object got %v", objects)
|
|
||||||
}
|
|
||||||
if size != file1.Size && size != file2.Size && size != file3.Size {
|
if size != file1.Size && size != file2.Size && size != file3.Size {
|
||||||
t.Errorf("Size not one of the object sizes %d", size)
|
t.Errorf("Size not one of the object sizes %d", size)
|
||||||
}
|
}
|
||||||
|
@ -1254,9 +1125,7 @@ func TestDeduplicateNewest(t *testing.T) {
|
||||||
r.checkWithDuplicates(t, file1, file2, file3)
|
r.checkWithDuplicates(t, file1, file2, file3)
|
||||||
|
|
||||||
err := fs.Deduplicate(r.fremote, fs.DeduplicateNewest)
|
err := fs.Deduplicate(r.fremote, fs.DeduplicateNewest)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("fs.Deduplicate returned error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.fremote, file3)
|
fstest.CheckItems(t, r.fremote, file3)
|
||||||
}
|
}
|
||||||
|
@ -1274,9 +1143,7 @@ func TestDeduplicateOldest(t *testing.T) {
|
||||||
r.checkWithDuplicates(t, file1, file2, file3)
|
r.checkWithDuplicates(t, file1, file2, file3)
|
||||||
|
|
||||||
err := fs.Deduplicate(r.fremote, fs.DeduplicateOldest)
|
err := fs.Deduplicate(r.fremote, fs.DeduplicateOldest)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("fs.Deduplicate returned error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
}
|
}
|
||||||
|
@ -1294,16 +1161,12 @@ func TestDeduplicateRename(t *testing.T) {
|
||||||
r.checkWithDuplicates(t, file1, file2, file3)
|
r.checkWithDuplicates(t, file1, file2, file3)
|
||||||
|
|
||||||
err := fs.Deduplicate(r.fremote, fs.DeduplicateRename)
|
err := fs.Deduplicate(r.fremote, fs.DeduplicateRename)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("fs.Deduplicate returned error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
list := fs.NewLister().Start(r.fremote, "")
|
list := fs.NewLister().Start(r.fremote, "")
|
||||||
for {
|
for {
|
||||||
o, err := list.GetObject()
|
o, err := list.GetObject()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Listing failed: %v", err)
|
|
||||||
}
|
|
||||||
// Check if we are finished
|
// Check if we are finished
|
||||||
if o == nil {
|
if o == nil {
|
||||||
break
|
break
|
||||||
|
|
|
@ -5,6 +5,7 @@ package fstest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -17,6 +18,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -69,35 +72,25 @@ func CheckTimeEqualWithPrecision(t0, t1 time.Time, precision time.Duration) (tim
|
||||||
// CheckModTime checks the mod time to the given precision
|
// CheckModTime checks the mod time to the given precision
|
||||||
func (i *Item) CheckModTime(t *testing.T, obj fs.Object, modTime time.Time, precision time.Duration) {
|
func (i *Item) CheckModTime(t *testing.T, obj fs.Object, modTime time.Time, precision time.Duration) {
|
||||||
dt, ok := CheckTimeEqualWithPrecision(modTime, i.ModTime, precision)
|
dt, ok := CheckTimeEqualWithPrecision(modTime, i.ModTime, precision)
|
||||||
if !ok {
|
assert.True(t, ok, fmt.Sprintf("%s: Modification time difference too big |%s| > %s (%s vs %s) (precision %s)", obj.Remote(), dt, precision, modTime, i.ModTime, precision))
|
||||||
t.Errorf("%s: Modification time difference too big |%s| > %s (%s vs %s) (precision %s)", obj.Remote(), dt, precision, modTime, i.ModTime, precision)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckHashes checks all the hashes the object supports are correct
|
// CheckHashes checks all the hashes the object supports are correct
|
||||||
func (i *Item) CheckHashes(t *testing.T, obj fs.Object) {
|
func (i *Item) CheckHashes(t *testing.T, obj fs.Object) {
|
||||||
if obj == nil {
|
require.NotNil(t, obj)
|
||||||
t.Fatalf("Object is nil")
|
|
||||||
}
|
|
||||||
types := obj.Fs().Hashes().Array()
|
types := obj.Fs().Hashes().Array()
|
||||||
for _, hash := range types {
|
for _, hash := range types {
|
||||||
// Check attributes
|
// Check attributes
|
||||||
sum, err := obj.Hash(hash)
|
sum, err := obj.Hash(hash)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("%s: Failed to read hash %v for %q: %v", obj.Fs().String(), hash, obj.Remote(), err)
|
assert.True(t, fs.HashEquals(i.Hashes[hash], sum), fmt.Sprintf("%s/%s: %v hash incorrect - expecting %q got %q", obj.Fs().String(), obj.Remote(), hash, i.Hashes[hash], sum))
|
||||||
}
|
|
||||||
if !fs.HashEquals(i.Hashes[hash], sum) {
|
|
||||||
t.Errorf("%s/%s: %v hash incorrect - expecting %q got %q", obj.Fs().String(), obj.Remote(), hash, i.Hashes[hash], sum)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check checks all the attributes of the object are correct
|
// Check checks all the attributes of the object are correct
|
||||||
func (i *Item) Check(t *testing.T, obj fs.Object, precision time.Duration) {
|
func (i *Item) Check(t *testing.T, obj fs.Object, precision time.Duration) {
|
||||||
i.CheckHashes(t, obj)
|
i.CheckHashes(t, obj)
|
||||||
if i.Size != obj.Size() {
|
assert.Equal(t, i.Size, obj.Size())
|
||||||
t.Errorf("%s/%s: Size incorrect - expecting %d got %d", obj.Fs().String(), obj.Remote(), i.Size, obj.Size())
|
|
||||||
}
|
|
||||||
i.CheckModTime(t, obj, obj.ModTime(), precision)
|
i.CheckModTime(t, obj, obj.ModTime(), precision)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,10 +121,7 @@ func (is *Items) Find(t *testing.T, obj fs.Object, precision time.Duration) {
|
||||||
i, ok := is.byName[obj.Remote()]
|
i, ok := is.byName[obj.Remote()]
|
||||||
if !ok {
|
if !ok {
|
||||||
i, ok = is.byNameAlt[obj.Remote()]
|
i, ok = is.byNameAlt[obj.Remote()]
|
||||||
if !ok {
|
assert.True(t, ok, fmt.Sprintf("Unexpected file %q", obj.Remote()))
|
||||||
t.Errorf("Unexpected file %q", obj.Remote())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
delete(is.byName, i.Path)
|
delete(is.byName, i.Path)
|
||||||
delete(is.byName, i.WinPath)
|
delete(is.byName, i.WinPath)
|
||||||
|
@ -177,10 +167,7 @@ func CheckListingWithPrecision(t *testing.T, f fs.Fs, items []Item, precision ti
|
||||||
time.Sleep(sleep)
|
time.Sleep(sleep)
|
||||||
}
|
}
|
||||||
for _, obj := range objs {
|
for _, obj := range objs {
|
||||||
if obj == nil {
|
require.NotNil(t, obj)
|
||||||
t.Errorf("Unexpected nil in List()")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
is.Find(t, obj, precision)
|
is.Find(t, obj, precision)
|
||||||
}
|
}
|
||||||
is.Done(t)
|
is.Done(t)
|
||||||
|
@ -308,25 +295,19 @@ func RandomRemote(remoteName string, subdir bool) (fs.Fs, func(), error) {
|
||||||
// TestMkdir tests Mkdir works
|
// TestMkdir tests Mkdir works
|
||||||
func TestMkdir(t *testing.T, remote fs.Fs) {
|
func TestMkdir(t *testing.T, remote fs.Fs) {
|
||||||
err := fs.Mkdir(remote)
|
err := fs.Mkdir(remote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Mkdir failed: %v", err)
|
|
||||||
}
|
|
||||||
CheckListing(t, remote, []Item{})
|
CheckListing(t, remote, []Item{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestPurge tests Purge works
|
// TestPurge tests Purge works
|
||||||
func TestPurge(t *testing.T, remote fs.Fs) {
|
func TestPurge(t *testing.T, remote fs.Fs) {
|
||||||
err := fs.Purge(remote)
|
err := fs.Purge(remote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Purge failed: %v", err)
|
|
||||||
}
|
|
||||||
CheckListing(t, remote, []Item{})
|
CheckListing(t, remote, []Item{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestRmdir tests Rmdir works
|
// TestRmdir tests Rmdir works
|
||||||
func TestRmdir(t *testing.T, remote fs.Fs) {
|
func TestRmdir(t *testing.T, remote fs.Fs) {
|
||||||
err := fs.Rmdir(remote)
|
err := fs.Rmdir(remote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Rmdir failed: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,23 +67,17 @@ func TestInit(t *testing.T) {
|
||||||
t.Logf("Using remote %q", RemoteName)
|
t.Logf("Using remote %q", RemoteName)
|
||||||
if RemoteName == "" {
|
if RemoteName == "" {
|
||||||
RemoteName, err = fstest.LocalRemote()
|
RemoteName, err = fstest.LocalRemote()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Failed to create tmp dir: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
subRemoteName, subRemoteLeaf, err = fstest.RandomRemoteName(RemoteName)
|
subRemoteName, subRemoteLeaf, err = fstest.RandomRemoteName(RemoteName)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Couldn't make remote name: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
remote, err = fs.NewFs(subRemoteName)
|
remote, err = fs.NewFs(subRemoteName)
|
||||||
if err == fs.ErrorNotFoundInConfigFile {
|
if err == fs.ErrorNotFoundInConfigFile {
|
||||||
t.Logf("Didn't find %q in config file - skipping tests", RemoteName)
|
t.Logf("Didn't find %q in config file - skipping tests", RemoteName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Couldn't start FS: %v", err)
|
|
||||||
}
|
|
||||||
fstest.TestMkdir(t, remote)
|
fstest.TestMkdir(t, remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,9 +91,7 @@ func skipIfNotOk(t *testing.T) {
|
||||||
func TestFsString(t *testing.T) {
|
func TestFsString(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
str := remote.String()
|
str := remote.String()
|
||||||
if str == "" {
|
require.NotEqual(t, str, "")
|
||||||
t.Fatal("Bad fs.String()")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestFsRmdirEmpty tests deleting an empty directory
|
// TestFsRmdirEmpty tests deleting an empty directory
|
||||||
|
@ -112,9 +104,7 @@ func TestFsRmdirEmpty(t *testing.T) {
|
||||||
func TestFsRmdirNotFound(t *testing.T) {
|
func TestFsRmdirNotFound(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
err := remote.Rmdir()
|
err := remote.Rmdir()
|
||||||
if err == nil {
|
assert.Error(t, err, "Expecting error on Rmdir non existent")
|
||||||
t.Fatalf("Expecting error on Rmdir non existent")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestFsMkdir tests tests making a directory
|
// TestFsMkdir tests tests making a directory
|
||||||
|
@ -192,9 +182,7 @@ func findObject(t *testing.T, Name string) fs.Object {
|
||||||
t.Logf("Sleeping for 1 second for findObject eventual consistency: %d/%d (%v)", i, eventualConsistencyRetries, err)
|
t.Logf("Sleeping for 1 second for findObject eventual consistency: %d/%d (%v)", i, eventualConsistencyRetries, err)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Object %q not found: %v", Name, err)
|
|
||||||
}
|
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +205,7 @@ again:
|
||||||
tries++
|
tries++
|
||||||
goto again
|
goto again
|
||||||
}
|
}
|
||||||
t.Fatal("Put error", err)
|
require.NoError(t, err, "Put error")
|
||||||
}
|
}
|
||||||
file.Hashes = hash.Sums()
|
file.Hashes = hash.Sums()
|
||||||
file.Check(t, obj, remote.Precision())
|
file.Check(t, obj, remote.Precision())
|
||||||
|
@ -268,9 +256,7 @@ func TestFsListDirFile2(t *testing.T) {
|
||||||
func TestFsListDirRoot(t *testing.T) {
|
func TestFsListDirRoot(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
rootRemote, err := fs.NewFs(RemoteName)
|
rootRemote, err := fs.NewFs(RemoteName)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Failed to make remote %q: %v", RemoteName, err)
|
|
||||||
}
|
|
||||||
dirs, err := fs.NewLister().SetLevel(1).Start(rootRemote, "").GetDirs()
|
dirs, err := fs.NewLister().SetLevel(1).Start(rootRemote, "").GetDirs()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Contains(t, dirsToNames(dirs), subRemoteLeaf, "Remote leaf not found")
|
assert.Contains(t, dirsToNames(dirs), subRemoteLeaf, "Remote leaf not found")
|
||||||
|
@ -339,23 +325,17 @@ func TestFsCopy(t *testing.T) {
|
||||||
// do the copy
|
// do the copy
|
||||||
src := findObject(t, file1.Path)
|
src := findObject(t, file1.Path)
|
||||||
dst, err := remote.(fs.Copier).Copy(src, file1Copy.Path)
|
dst, err := remote.(fs.Copier).Copy(src, file1Copy.Path)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Copy failed: %v (%#v)", err, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check file exists in new listing
|
// check file exists in new listing
|
||||||
fstest.CheckListing(t, remote, []fstest.Item{file1, file2, file1Copy})
|
fstest.CheckListing(t, remote, []fstest.Item{file1, file2, file1Copy})
|
||||||
|
|
||||||
// Check dst lightly - list above has checked ModTime/Hashes
|
// Check dst lightly - list above has checked ModTime/Hashes
|
||||||
if dst.Remote() != file1Copy.Path {
|
assert.Equal(t, file1Copy.Path, dst.Remote())
|
||||||
t.Errorf("object path: want %q got %q", file1Copy.Path, dst.Remote())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete copy
|
// Delete copy
|
||||||
err = dst.Remove()
|
err = dst.Remove()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Remove copy error", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,24 +355,18 @@ func TestFsMove(t *testing.T) {
|
||||||
// do the move
|
// do the move
|
||||||
src := findObject(t, file1.Path)
|
src := findObject(t, file1.Path)
|
||||||
dst, err := remote.(fs.Mover).Move(src, file1Move.Path)
|
dst, err := remote.(fs.Mover).Move(src, file1Move.Path)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Move failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check file exists in new listing
|
// check file exists in new listing
|
||||||
fstest.CheckListing(t, remote, []fstest.Item{file2, file1Move})
|
fstest.CheckListing(t, remote, []fstest.Item{file2, file1Move})
|
||||||
|
|
||||||
// Check dst lightly - list above has checked ModTime/Hashes
|
// Check dst lightly - list above has checked ModTime/Hashes
|
||||||
if dst.Remote() != file1Move.Path {
|
assert.Equal(t, file1Move.Path, dst.Remote())
|
||||||
t.Errorf("object path: want %q got %q", file1Move.Path, dst.Remote())
|
|
||||||
}
|
|
||||||
|
|
||||||
// move it back
|
// move it back
|
||||||
src = findObject(t, file1Move.Path)
|
src = findObject(t, file1Move.Path)
|
||||||
_, err = remote.(fs.Mover).Move(src, file1.Path)
|
_, err = remote.(fs.Mover).Move(src, file1.Path)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Errorf("Move failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check file exists in new listing
|
// check file exists in new listing
|
||||||
fstest.CheckListing(t, remote, []fstest.Item{file2, file1})
|
fstest.CheckListing(t, remote, []fstest.Item{file2, file1})
|
||||||
|
@ -418,22 +392,16 @@ func TestFsDirMove(t *testing.T) {
|
||||||
|
|
||||||
// Check it can't move onto itself
|
// Check it can't move onto itself
|
||||||
err := remote.(fs.DirMover).DirMove(remote)
|
err := remote.(fs.DirMover).DirMove(remote)
|
||||||
if err != fs.ErrorDirExists {
|
require.Equal(t, fs.ErrorDirExists, err)
|
||||||
t.Errorf("Expecting fs.ErrorDirExists got: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// new remote
|
// new remote
|
||||||
newRemote, removeNewRemote, err := fstest.RandomRemote(RemoteName, false)
|
newRemote, removeNewRemote, err := fstest.RandomRemote(RemoteName, false)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Failed to create remote: %v", err)
|
|
||||||
}
|
|
||||||
defer removeNewRemote()
|
defer removeNewRemote()
|
||||||
|
|
||||||
// try the move
|
// try the move
|
||||||
err = newRemote.(fs.DirMover).DirMove(remote)
|
err = newRemote.(fs.DirMover).DirMove(remote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Errorf("Failed to DirMove: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check remotes
|
// check remotes
|
||||||
// FIXME: Prints errors.
|
// FIXME: Prints errors.
|
||||||
|
@ -442,9 +410,7 @@ func TestFsDirMove(t *testing.T) {
|
||||||
|
|
||||||
// move it back
|
// move it back
|
||||||
err = remote.(fs.DirMover).DirMove(newRemote)
|
err = remote.(fs.DirMover).DirMove(newRemote)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Errorf("Failed to DirMove: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check remotes
|
// check remotes
|
||||||
fstest.CheckListing(t, remote, []fstest.Item{file2, file1})
|
fstest.CheckListing(t, remote, []fstest.Item{file2, file1})
|
||||||
|
@ -455,9 +421,7 @@ func TestFsDirMove(t *testing.T) {
|
||||||
func TestFsRmdirFull(t *testing.T) {
|
func TestFsRmdirFull(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
err := remote.Rmdir()
|
err := remote.Rmdir()
|
||||||
if err == nil {
|
require.Error(t, err, "Expecting error on RMdir on non empty remote")
|
||||||
t.Fatalf("Expecting error on RMdir on non empty remote")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestFsPrecision tests the Precision of the Fs
|
// TestFsPrecision tests the Precision of the Fs
|
||||||
|
@ -477,40 +441,28 @@ func TestFsPrecision(t *testing.T) {
|
||||||
func TestObjectString(t *testing.T) {
|
func TestObjectString(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
obj := findObject(t, file1.Path)
|
obj := findObject(t, file1.Path)
|
||||||
s := obj.String()
|
assert.Equal(t, file1.Path, obj.String())
|
||||||
if s != file1.Path {
|
assert.Equal(t, "<nil>", NilObject.String())
|
||||||
t.Errorf("String() wrong %v != %v", s, file1.Path)
|
|
||||||
}
|
|
||||||
obj = NilObject
|
|
||||||
s = obj.String()
|
|
||||||
if s != "<nil>" {
|
|
||||||
t.Errorf("String() wrong %v != %v", s, "<nil>")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestObjectFs tests the object can be found
|
// TestObjectFs tests the object can be found
|
||||||
func TestObjectFs(t *testing.T) {
|
func TestObjectFs(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
obj := findObject(t, file1.Path)
|
obj := findObject(t, file1.Path)
|
||||||
equal := obj.Fs() == remote
|
if obj.Fs() != remote {
|
||||||
if !equal {
|
|
||||||
// Check to see if this wraps something else
|
// Check to see if this wraps something else
|
||||||
if unwrap, ok := remote.(fs.UnWrapper); ok {
|
if unwrap, ok := remote.(fs.UnWrapper); ok {
|
||||||
equal = obj.Fs() == unwrap.UnWrap()
|
remote = unwrap.UnWrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !equal {
|
assert.Equal(t, obj.Fs(), remote)
|
||||||
t.Errorf("Fs is wrong %v != %v", obj.Fs(), remote)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestObjectRemote tests the Remote is correct
|
// TestObjectRemote tests the Remote is correct
|
||||||
func TestObjectRemote(t *testing.T) {
|
func TestObjectRemote(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
obj := findObject(t, file1.Path)
|
obj := findObject(t, file1.Path)
|
||||||
if obj.Remote() != file1.Path {
|
assert.Equal(t, file1.Path, obj.Remote())
|
||||||
t.Errorf("Remote is wrong %v != %v", obj.Remote(), file1.Path)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestObjectHashes checks all the hashes the object supports
|
// TestObjectHashes checks all the hashes the object supports
|
||||||
|
@ -536,9 +488,8 @@ func TestObjectSetModTime(t *testing.T) {
|
||||||
if err == fs.ErrorCantSetModTime {
|
if err == fs.ErrorCantSetModTime {
|
||||||
t.Log(err)
|
t.Log(err)
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
require.NoError(t, err)
|
||||||
file1.ModTime = newModTime
|
file1.ModTime = newModTime
|
||||||
file1.CheckModTime(t, obj, obj.ModTime(), remote.Precision())
|
file1.CheckModTime(t, obj, obj.ModTime(), remote.Precision())
|
||||||
// And make a new object and read it from there too
|
// And make a new object and read it from there too
|
||||||
|
@ -549,9 +500,7 @@ func TestObjectSetModTime(t *testing.T) {
|
||||||
func TestObjectSize(t *testing.T) {
|
func TestObjectSize(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
obj := findObject(t, file1.Path)
|
obj := findObject(t, file1.Path)
|
||||||
if obj.Size() != file1.Size {
|
assert.Equal(t, file1.Size, obj.Size())
|
||||||
t.Errorf("Size is wrong %v != %v", obj.Size(), file1.Size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestObjectOpen tests that Open works
|
// TestObjectOpen tests that Open works
|
||||||
|
@ -559,27 +508,16 @@ func TestObjectOpen(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
obj := findObject(t, file1.Path)
|
obj := findObject(t, file1.Path)
|
||||||
in, err := obj.Open()
|
in, err := obj.Open()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Open() return error: %v", err)
|
|
||||||
}
|
|
||||||
hasher := fs.NewMultiHasher()
|
hasher := fs.NewMultiHasher()
|
||||||
n, err := io.Copy(hasher, in)
|
n, err := io.Copy(hasher, in)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("io.Copy() return error: %v", err)
|
require.Equal(t, file1.Size, n, "Read wrong number of bytes")
|
||||||
}
|
|
||||||
if n != file1.Size {
|
|
||||||
t.Fatalf("Read wrong number of bytes %d != %d", n, file1.Size)
|
|
||||||
}
|
|
||||||
err = in.Close()
|
err = in.Close()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("in.Close() return error: %v", err)
|
|
||||||
}
|
|
||||||
// Check content of file by comparing the calculated hashes
|
// Check content of file by comparing the calculated hashes
|
||||||
for hashType, got := range hasher.Sums() {
|
for hashType, got := range hasher.Sums() {
|
||||||
want := file1.Hashes[hashType]
|
assert.Equal(t, file1.Hashes[hashType], got)
|
||||||
if want != got {
|
|
||||||
t.Errorf("%v is wrong %v != %v", hashType, want, got)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -595,9 +533,7 @@ func TestObjectUpdate(t *testing.T) {
|
||||||
obj := findObject(t, file1.Path)
|
obj := findObject(t, file1.Path)
|
||||||
obji := fs.NewStaticObjectInfo("", file1.ModTime, file1.Size, true, nil, obj.Fs())
|
obji := fs.NewStaticObjectInfo("", file1.ModTime, file1.Size, true, nil, obj.Fs())
|
||||||
err := obj.Update(in, obji)
|
err := obj.Update(in, obji)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Update error", err)
|
|
||||||
}
|
|
||||||
file1.Hashes = hash.Sums()
|
file1.Hashes = hash.Sums()
|
||||||
file1.Check(t, obj, remote.Precision())
|
file1.Check(t, obj, remote.Precision())
|
||||||
// Re-read the object and check again
|
// Re-read the object and check again
|
||||||
|
@ -609,9 +545,7 @@ func TestObjectUpdate(t *testing.T) {
|
||||||
func TestObjectStorable(t *testing.T) {
|
func TestObjectStorable(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
obj := findObject(t, file1.Path)
|
obj := findObject(t, file1.Path)
|
||||||
if !obj.Storable() {
|
require.NotNil(t, !obj.Storable(), "Expecting object to be storable")
|
||||||
t.Fatalf("Expecting %v to be storable", obj)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestFsIsFile tests that an error is returned along with a valid fs
|
// TestFsIsFile tests that an error is returned along with a valid fs
|
||||||
|
@ -631,9 +565,7 @@ func TestFsIsFileNotFound(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
remoteName := subRemoteName + "/not found.txt"
|
remoteName := subRemoteName + "/not found.txt"
|
||||||
fileRemote, err := fs.NewFs(remoteName)
|
fileRemote, err := fs.NewFs(remoteName)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("Failed to make remote %q: %v", remoteName, err)
|
|
||||||
}
|
|
||||||
fstest.CheckListing(t, fileRemote, []fstest.Item{})
|
fstest.CheckListing(t, fileRemote, []fstest.Item{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,9 +574,7 @@ func TestObjectRemove(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
obj := findObject(t, file1.Path)
|
obj := findObject(t, file1.Path)
|
||||||
err := obj.Remove()
|
err := obj.Remove()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Remove error", err)
|
|
||||||
}
|
|
||||||
fstest.CheckListing(t, remote, []fstest.Item{file2})
|
fstest.CheckListing(t, remote, []fstest.Item{file2})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,9 +583,7 @@ func TestObjectPurge(t *testing.T) {
|
||||||
skipIfNotOk(t)
|
skipIfNotOk(t)
|
||||||
fstest.TestPurge(t, remote)
|
fstest.TestPurge(t, remote)
|
||||||
err := fs.Purge(remote)
|
err := fs.Purge(remote)
|
||||||
if err == nil {
|
assert.Error(t, err, "Expecting error after on second purge")
|
||||||
t.Fatal("Expecting error after on second purge")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestFinalise tidies up after the previous tests
|
// TestFinalise tidies up after the previous tests
|
||||||
|
@ -664,8 +592,6 @@ func TestFinalise(t *testing.T) {
|
||||||
if strings.HasPrefix(RemoteName, "/") {
|
if strings.HasPrefix(RemoteName, "/") {
|
||||||
// Remove temp directory
|
// Remove temp directory
|
||||||
err := os.Remove(RemoteName)
|
err := os.Remove(RemoteName)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Logf("Failed to remove %q: %v\n", RemoteName, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue