rclone cat: add --head, --tail, --offset, --count and --discard

Fixes #819
This commit is contained in:
Nick Craig-Wood
2017-02-08 08:09:41 +00:00
parent 381b845307
commit d091d4a8bb
3 changed files with 100 additions and 14 deletions

View File

@@ -667,18 +667,30 @@ func TestDeduplicateRename(t *testing.T) {
func TestCat(t *testing.T) {
r := NewRun(t)
defer r.Finalise()
file1 := r.WriteBoth("file1", "aaa", t1)
file2 := r.WriteBoth("file2", "bbb", t2)
file1 := r.WriteBoth("file1", "ABCDEFGHIJ", t1)
file2 := r.WriteBoth("file2", "012345678", t2)
fstest.CheckItems(t, r.fremote, file1, file2)
var buf bytes.Buffer
err := fs.Cat(r.fremote, &buf)
require.NoError(t, err)
res := buf.String()
for _, test := range []struct {
offset int64
count int64
a string
b string
}{
{0, -1, "ABCDEFGHIJ", "012345678"},
{0, 5, "ABCDE", "01234"},
{-3, -1, "HIJ", "678"},
{1, 3, "BCD", "123"},
} {
var buf bytes.Buffer
err := fs.Cat(r.fremote, &buf, test.offset, test.count)
require.NoError(t, err)
res := buf.String()
if res != "aaabbb" && res != "bbbaaa" {
t.Errorf("Incorrect output from Cat: %q", res)
if res != test.a+test.b && res != test.b+test.a {
t.Errorf("Incorrect output from Cat(%d,%d): %q", test.offset, test.count, res)
}
}
}