2018-01-12 16:30:54 +00:00
|
|
|
// Internal tests for operations
|
|
|
|
|
|
|
|
package operations
|
2018-01-31 16:15:30 +00:00
|
|
|
|
|
|
|
import (
|
2020-11-05 11:33:32 +00:00
|
|
|
"context"
|
2018-01-31 16:15:30 +00:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fs/object"
|
2018-01-31 16:15:30 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSizeDiffers(t *testing.T) {
|
2020-11-05 11:33:32 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
ci := fs.GetConfig(ctx)
|
2018-01-31 16:15:30 +00:00
|
|
|
when := time.Now()
|
|
|
|
for _, test := range []struct {
|
|
|
|
ignoreSize bool
|
|
|
|
srcSize int64
|
|
|
|
dstSize int64
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
{false, 0, 0, false},
|
|
|
|
{false, 1, 2, true},
|
|
|
|
{false, 1, -1, false},
|
|
|
|
{false, -1, 1, false},
|
|
|
|
{true, 0, 0, false},
|
|
|
|
{true, 1, 2, false},
|
|
|
|
{true, 1, -1, false},
|
|
|
|
{true, -1, 1, false},
|
|
|
|
} {
|
|
|
|
src := object.NewStaticObjectInfo("a", when, test.srcSize, true, nil, nil)
|
|
|
|
dst := object.NewStaticObjectInfo("a", when, test.dstSize, true, nil, nil)
|
2020-11-05 11:33:32 +00:00
|
|
|
oldIgnoreSize := ci.IgnoreSize
|
|
|
|
ci.IgnoreSize = test.ignoreSize
|
|
|
|
got := sizeDiffers(ctx, src, dst)
|
|
|
|
ci.IgnoreSize = oldIgnoreSize
|
2018-01-31 16:15:30 +00:00
|
|
|
assert.Equal(t, test.want, got, fmt.Sprintf("ignoreSize=%v, srcSize=%v, dstSize=%v", test.ignoreSize, test.srcSize, test.dstSize))
|
|
|
|
}
|
|
|
|
}
|