2019-01-11 15:35:26 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package sync2_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/memory"
|
|
|
|
"storj.io/storj/private/sync2"
|
|
|
|
"storj.io/storj/private/testrand"
|
2019-01-11 15:35:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCopy(t *testing.T) {
|
2019-02-20 09:22:53 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2019-01-11 15:35:26 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
r := io.LimitReader(testrand.Reader(), 32*memory.KiB.Int64())
|
2019-01-11 15:35:26 +00:00
|
|
|
|
|
|
|
n, err := sync2.Copy(ctx, ioutil.Discard, r)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
2019-03-18 10:55:06 +00:00
|
|
|
assert.Equal(t, n, 32*memory.KiB.Int64())
|
2019-01-11 15:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCopy_Cancel(t *testing.T) {
|
2019-02-20 09:22:53 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2019-01-11 15:35:26 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
r := io.LimitReader(testrand.Reader(), 32*memory.KiB.Int64())
|
2019-01-11 15:35:26 +00:00
|
|
|
|
|
|
|
n, err := sync2.Copy(ctx, ioutil.Discard, r)
|
|
|
|
|
|
|
|
assert.EqualError(t, err, context.Canceled.Error())
|
|
|
|
assert.EqualValues(t, n, 0)
|
|
|
|
}
|