File: io_test.go

package info (click to toggle)
golang-github-git-lfs-gitobj 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 432 kB
  • sloc: makefile: 2; sh: 1
file content (52 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (3)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package pack

import (
	"bytes"
	"fmt"
	"testing"

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

func TestOffsetReaderAtReadsAtOffset(t *testing.T) {
	bo := &OffsetReaderAt{
		r: bytes.NewReader([]byte{0x0, 0x1, 0x2, 0x3}),
		o: 1,
	}

	var x1 [1]byte
	n1, e1 := bo.Read(x1[:])

	assert.NoError(t, e1)
	assert.Equal(t, 1, n1)

	assert.EqualValues(t, 0x1, x1[0])

	var x2 [1]byte
	n2, e2 := bo.Read(x2[:])

	assert.NoError(t, e2)
	assert.Equal(t, 1, n2)
	assert.EqualValues(t, 0x2, x2[0])
}

func TestOffsetReaderPropogatesErrors(t *testing.T) {
	expected := fmt.Errorf("gitobj/pack: testing")
	bo := &OffsetReaderAt{
		r: &ErrReaderAt{Err: expected},
		o: 1,
	}

	n, err := bo.Read(make([]byte, 1))

	assert.Equal(t, expected, err)
	assert.Equal(t, 0, n)
}

type ErrReaderAt struct {
	Err error
}

func (e *ErrReaderAt) ReadAt(p []byte, at int64) (n int, err error) {
	return 0, e.Err
}