File: set_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 (78 lines) | stat: -rw-r--r-- 1,729 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package pack

import (
	"bytes"
	"testing"

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

func TestSetOpenOpensAPackedObject(t *testing.T) {
	const sha = "decafdecafdecafdecafdecafdecafdecafdecaf"
	const data = "Hello, world!\n"
	compressed, _ := compress(data)

	set := NewSetPacks(&Packfile{
		idx: IndexWith(map[string]uint32{
			sha: 0,
		}),
		r: bytes.NewReader(append([]byte{0x3e}, compressed...)),
	})

	o, err := set.Object(DecodeHex(t, sha))

	assert.NoError(t, err)
	assert.Equal(t, TypeBlob, o.Type())

	unpacked, err := o.Unpack()
	assert.NoError(t, err)
	assert.Equal(t, []byte(data), unpacked)
}

func TestSetOpenOpensPackedObjectsInPackOrder(t *testing.T) {
	p1 := &Packfile{
		Objects: 1,

		idx: IndexWith(map[string]uint32{
			"aa00000000000000000000000000000000000000": 1,
		}),
		r: bytes.NewReader(nil),
	}
	p2 := &Packfile{
		Objects: 2,

		idx: IndexWith(map[string]uint32{
			"aa11111111111111111111111111111111111111": 1,
			"aa22222222222222222222222222222222222222": 2,
		}),
		r: bytes.NewReader(nil),
	}
	p3 := &Packfile{
		Objects: 3,

		idx: IndexWith(map[string]uint32{
			"aa33333333333333333333333333333333333333": 3,
			"aa44444444444444444444444444444444444444": 4,
			"aa55555555555555555555555555555555555555": 5,
		}),
		r: bytes.NewReader(nil),
	}

	set := NewSetPacks(p1, p2, p3)

	var visited []*Packfile

	set.each(
		DecodeHex(t, "aa55555555555555555555555555555555555555"),
		func(p *Packfile) (*Object, error) {
			visited = append(visited, p)
			return nil, errNotFound
		},
	)

	require.Len(t, visited, 3)
	assert.EqualValues(t, visited[0].Objects, 3)
	assert.EqualValues(t, visited[1].Objects, 2)
	assert.EqualValues(t, visited[2].Objects, 1)
}