storj/internal/sync2/copy_test.go
Egon Elbre 05d148aeb5
Storage node and upload/download protocol refactor (#1422)
refactor storage node server
refactor upload and download protocol
2019-03-18 12:55:06 +02:00

46 lines
877 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information
package sync2_test
import (
"context"
"crypto/rand"
"io"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
"storj.io/storj/internal/memory"
"storj.io/storj/internal/sync2"
)
func TestCopy(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
r := io.LimitReader(rand.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) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
cancel()
r := io.LimitReader(rand.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)
}