github.com/stffabi/git-lfs@v2.3.5-0.20180214015214-8eeaa8d88902+incompatible/git/odb/tag_test.go (about) 1 package odb 2 3 import ( 4 "bytes" 5 "fmt" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestTagTypeReturnsCorrectObjectType(t *testing.T) { 12 assert.Equal(t, TagObjectType, new(Tag).Type()) 13 } 14 15 func TestTagEncode(t *testing.T) { 16 tag := &Tag{ 17 Object: []byte("aaaaaaaaaaaaaaaaaaaa"), 18 ObjectType: CommitObjectType, 19 Name: "v2.4.0", 20 Tagger: "A U Thor <author@example.com>", 21 22 Message: "The quick brown fox jumps over the lazy dog.", 23 } 24 25 buf := new(bytes.Buffer) 26 27 n, err := tag.Encode(buf) 28 29 assert.Nil(t, err) 30 assert.EqualValues(t, buf.Len(), n) 31 32 assertLine(t, buf, "object 6161616161616161616161616161616161616161") 33 assertLine(t, buf, "type commit") 34 assertLine(t, buf, "tag v2.4.0") 35 assertLine(t, buf, "tagger A U Thor <author@example.com>") 36 assertLine(t, buf, "") 37 assertLine(t, buf, "The quick brown fox jumps over the lazy dog.") 38 39 assert.Equal(t, 0, buf.Len()) 40 } 41 42 func TestTagDecode(t *testing.T) { 43 from := new(bytes.Buffer) 44 45 fmt.Fprintf(from, "object 6161616161616161616161616161616161616161\n") 46 fmt.Fprintf(from, "type commit\n") 47 fmt.Fprintf(from, "tag v2.4.0\n") 48 fmt.Fprintf(from, "tagger A U Thor <author@example.com>\n") 49 fmt.Fprintf(from, "\n") 50 fmt.Fprintf(from, "The quick brown fox jumps over the lazy dog.\n") 51 52 flen := from.Len() 53 54 tag := new(Tag) 55 n, err := tag.Decode(from, int64(flen)) 56 57 assert.Nil(t, err) 58 assert.Equal(t, n, flen) 59 60 assert.Equal(t, []byte("aaaaaaaaaaaaaaaaaaaa"), tag.Object) 61 assert.Equal(t, CommitObjectType, tag.ObjectType) 62 assert.Equal(t, "v2.4.0", tag.Name) 63 assert.Equal(t, "A U Thor <author@example.com>", tag.Tagger) 64 assert.Equal(t, "The quick brown fox jumps over the lazy dog.", tag.Message) 65 }