github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/git/tag_test.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 package git 7 8 import ( 9 "testing" 10 "time" 11 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func Test_parseTagData(t *testing.T) { 16 testData := []struct { 17 data []byte 18 tag Tag 19 }{ 20 {data: []byte(`object 3b114ab800c6432ad42387ccf6bc8d4388a2885a 21 type commit 22 tag 1.22.0 23 tagger Lucas Michot <lucas@semalead.com> 1484491741 +0100 24 25 `), tag: Tag{ 26 Name: "", 27 ID: SHA1{}, 28 Object: SHA1{0x3b, 0x11, 0x4a, 0xb8, 0x0, 0xc6, 0x43, 0x2a, 0xd4, 0x23, 0x87, 0xcc, 0xf6, 0xbc, 0x8d, 0x43, 0x88, 0xa2, 0x88, 0x5a}, 29 Type: "commit", 30 Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484491741, 0)}, 31 Message: "", 32 Signature: nil, 33 }}, 34 {data: []byte(`object 7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc 35 type commit 36 tag 1.22.1 37 tagger Lucas Michot <lucas@semalead.com> 1484553735 +0100 38 39 test message 40 o 41 42 ono`), tag: Tag{ 43 Name: "", 44 ID: SHA1{}, 45 Object: SHA1{0x7c, 0xdf, 0x42, 0xc0, 0xb1, 0xcc, 0x76, 0x3a, 0xb7, 0xe4, 0xc3, 0x3c, 0x47, 0xa2, 0x4e, 0x27, 0xc6, 0x6b, 0xfc, 0xcc}, 46 Type: "commit", 47 Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484553735, 0)}, 48 Message: "test message\no\n\nono", 49 Signature: nil, 50 }}, 51 } 52 53 for _, test := range testData { 54 tag, err := parseTagData(test.data) 55 assert.NoError(t, err) 56 assert.EqualValues(t, test.tag.ID, tag.ID) 57 assert.EqualValues(t, test.tag.Object, tag.Object) 58 assert.EqualValues(t, test.tag.Name, tag.Name) 59 assert.EqualValues(t, test.tag.Message, tag.Message) 60 assert.EqualValues(t, test.tag.Type, tag.Type) 61 if test.tag.Signature != nil && assert.NotNil(t, tag.Signature) { 62 assert.EqualValues(t, test.tag.Signature.Signature, tag.Signature.Signature) 63 assert.EqualValues(t, test.tag.Signature.Payload, tag.Signature.Payload) 64 } else { 65 assert.Nil(t, tag.Signature) 66 } 67 if test.tag.Tagger != nil && assert.NotNil(t, tag.Tagger) { 68 assert.EqualValues(t, test.tag.Tagger.Name, tag.Tagger.Name) 69 assert.EqualValues(t, test.tag.Tagger.Email, tag.Tagger.Email) 70 assert.EqualValues(t, test.tag.Tagger.When.Unix(), tag.Tagger.When.Unix()) 71 } else { 72 assert.Nil(t, tag.Tagger) 73 } 74 } 75 }