File: tag_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 (66 lines) | stat: -rw-r--r-- 1,712 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gitobj

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

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

func TestTagTypeReturnsCorrectObjectType(t *testing.T) {
	assert.Equal(t, TagObjectType, new(Tag).Type())
}

func TestTagEncode(t *testing.T) {
	tag := &Tag{
		Object:     []byte("aaaaaaaaaaaaaaaaaaaa"),
		ObjectType: CommitObjectType,
		Name:       "v2.4.0",
		Tagger:     "A U Thor <author@example.com>",

		Message: "The quick brown fox jumps over the lazy dog.",
	}

	buf := new(bytes.Buffer)

	n, err := tag.Encode(buf)

	assert.Nil(t, err)
	assert.EqualValues(t, buf.Len(), n)

	assertLine(t, buf, "object 6161616161616161616161616161616161616161")
	assertLine(t, buf, "type commit")
	assertLine(t, buf, "tag v2.4.0")
	assertLine(t, buf, "tagger A U Thor <author@example.com>")
	assertLine(t, buf, "")
	assertLine(t, buf, "The quick brown fox jumps over the lazy dog.")

	assert.Equal(t, 0, buf.Len())
}

func TestTagDecode(t *testing.T) {
	from := new(bytes.Buffer)

	fmt.Fprintf(from, "object 6161616161616161616161616161616161616161\n")
	fmt.Fprintf(from, "type commit\n")
	fmt.Fprintf(from, "tag v2.4.0\n")
	fmt.Fprintf(from, "tagger A U Thor <author@example.com>\n")
	fmt.Fprintf(from, "\n")
	fmt.Fprintf(from, "The quick brown fox jumps over the lazy dog.\n")

	flen := from.Len()

	tag := new(Tag)
	n, err := tag.Decode(sha1.New(), from, int64(flen))

	assert.Nil(t, err)
	assert.Equal(t, n, flen)

	assert.Equal(t, []byte("aaaaaaaaaaaaaaaaaaaa"), tag.Object)
	assert.Equal(t, CommitObjectType, tag.ObjectType)
	assert.Equal(t, "v2.4.0", tag.Name)
	assert.Equal(t, "A U Thor <author@example.com>", tag.Tagger)
	assert.Equal(t, "The quick brown fox jumps over the lazy dog.", tag.Message)
}