File: packfile_decode_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 (43 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (2)
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
package pack

import (
	"bytes"
	"crypto/sha1"
	"crypto/sha256"
	"testing"

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

func TestDecodePackfileDecodesIntegerVersion(t *testing.T) {
	p, err := DecodePackfile(bytes.NewReader([]byte{
		'P', 'A', 'C', 'K', // Pack header.
		0x0, 0x0, 0x0, 0x2, // Pack version.
		0x0, 0x0, 0x0, 0x0, // Number of packed objects.
	}), sha1.New())

	assert.NoError(t, err)
	assert.EqualValues(t, 2, p.Version)
}

func TestDecodePackfileDecodesIntegerCount(t *testing.T) {
	p, err := DecodePackfile(bytes.NewReader([]byte{
		'P', 'A', 'C', 'K', // Pack header.
		0x0, 0x0, 0x0, 0x2, // Pack version.
		0x0, 0x0, 0x1, 0x2, // Number of packed objects.
	}), sha256.New())

	assert.NoError(t, err)
	assert.EqualValues(t, 258, p.Objects)
}

func TestDecodePackfileReportsBadHeaders(t *testing.T) {
	p, err := DecodePackfile(bytes.NewReader([]byte{
		'W', 'R', 'O', 'N', 'G', // Malformed pack header.
		0x0, 0x0, 0x0, 0x0, // Pack version.
		0x0, 0x0, 0x0, 0x0, // Number of packed objects.
	}), sha1.New())

	assert.Equal(t, errBadPackHeader, err)
	assert.Nil(t, p)
}