code.gitea.io/gitea@v1.22.3/modules/git/tag_test.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package git 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func Test_parseTagData(t *testing.T) { 14 testData := []struct { 15 data string 16 expected Tag 17 }{ 18 { 19 data: `object 3b114ab800c6432ad42387ccf6bc8d4388a2885a 20 type commit 21 tag 1.22.0 22 tagger Lucas Michot <lucas@semalead.com> 1484491741 +0100 23 24 `, 25 expected: Tag{ 26 Name: "", 27 ID: Sha1ObjectFormat.EmptyObjectID(), 28 Object: MustIDFromString("3b114ab800c6432ad42387ccf6bc8d4388a2885a"), 29 Type: "commit", 30 Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484491741, 0).In(time.FixedZone("", 3600))}, 31 Message: "", 32 Signature: nil, 33 }, 34 }, 35 { 36 data: `object 7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc 37 type commit 38 tag 1.22.1 39 tagger Lucas Michot <lucas@semalead.com> 1484553735 +0100 40 41 test message 42 o 43 44 ono`, 45 expected: Tag{ 46 Name: "", 47 ID: Sha1ObjectFormat.EmptyObjectID(), 48 Object: MustIDFromString("7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc"), 49 Type: "commit", 50 Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484553735, 0).In(time.FixedZone("", 3600))}, 51 Message: "test message\no\n\nono", 52 Signature: nil, 53 }, 54 }, 55 { 56 data: `object 7cdf42c0b1cc763ab7e4c33c47a24e27c66bfaaa 57 type commit 58 tag v0 59 tagger dummy user <dummy-email@example.com> 1484491741 +0100 60 61 dummy message 62 -----BEGIN SSH SIGNATURE----- 63 dummy signature 64 -----END SSH SIGNATURE----- 65 `, 66 expected: Tag{ 67 Name: "", 68 ID: Sha1ObjectFormat.EmptyObjectID(), 69 Object: MustIDFromString("7cdf42c0b1cc763ab7e4c33c47a24e27c66bfaaa"), 70 Type: "commit", 71 Tagger: &Signature{Name: "dummy user", Email: "dummy-email@example.com", When: time.Unix(1484491741, 0).In(time.FixedZone("", 3600))}, 72 Message: "dummy message", 73 Signature: &CommitSignature{ 74 Signature: `-----BEGIN SSH SIGNATURE----- 75 dummy signature 76 -----END SSH SIGNATURE-----`, 77 Payload: `object 7cdf42c0b1cc763ab7e4c33c47a24e27c66bfaaa 78 type commit 79 tag v0 80 tagger dummy user <dummy-email@example.com> 1484491741 +0100 81 82 dummy message`, 83 }, 84 }, 85 }, 86 } 87 88 for _, test := range testData { 89 tag, err := parseTagData(Sha1ObjectFormat, []byte(test.data)) 90 assert.NoError(t, err) 91 assert.Equal(t, test.expected, *tag) 92 } 93 94 tag, err := parseTagData(Sha1ObjectFormat, []byte("type commit\n\nfoo\n-----BEGIN SSH SIGNATURE-----\ncorrupted...")) 95 assert.NoError(t, err) 96 assert.Equal(t, "foo\n-----BEGIN SSH SIGNATURE-----\ncorrupted...", tag.Message) 97 }