storj/private/sync2/copy_test.go

46 lines
907 B
Go
Raw Normal View History

// 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"
"storj.io/storj/private/memory"
"storj.io/storj/private/sync2"
"storj.io/storj/private/testrand"
)
func TestCopy(t *testing.T) {
2019-02-20 09:22:53 +00:00
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
r := io.LimitReader(testrand.Reader(), 32*memory.KiB.Int64())
n, err := sync2.Copy(ctx, ioutil.Discard, r)
assert.NoError(t, err)
assert.Equal(t, n, 32*memory.KiB.Int64())
}
func TestCopy_Cancel(t *testing.T) {
2019-02-20 09:22:53 +00:00
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
cancel()
r := io.LimitReader(testrand.Reader(), 32*memory.KiB.Int64())
n, err := sync2.Copy(ctx, ioutil.Discard, r)
assert.EqualError(t, err, context.Canceled.Error())
assert.EqualValues(t, n, 0)
}