File: upload_reader_test.go

package info (click to toggle)
golang-github-containers-image 5.28.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,104 kB
  • sloc: sh: 194; makefile: 73
file content (34 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package uploadreader

import (
	"bytes"
	"errors"
	"io"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestUploadReader(t *testing.T) {
	// This is a smoke test in a single goroutine, without really testing the locking.

	data := bytes.Repeat([]byte{0x01}, 65535)
	// No termination
	ur := NewUploadReader(bytes.NewReader(data))
	read, err := io.ReadAll(ur)
	require.NoError(t, err)
	assert.Equal(t, data, read)

	// Terminated
	ur = NewUploadReader(bytes.NewReader(data))
	readLen := len(data) / 2
	read, err = io.ReadAll(io.LimitReader(ur, int64(readLen)))
	require.NoError(t, err)
	assert.Equal(t, data[:readLen], read)
	terminationErr := errors.New("Terminated")
	ur.Terminate(terminationErr)
	read, err = io.ReadAll(ur)
	assert.Equal(t, terminationErr, err)
	assert.Len(t, read, 0)
}