|
| 1 | +// Copyright 2020 The Gitea Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package git |
| 6 | + |
| 7 | +import ( |
| 8 | + "testing" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | +) |
| 13 | + |
| 14 | +func Test_parseTagData(t *testing.T) { |
| 15 | + testData := []struct { |
| 16 | + data []byte |
| 17 | + tag Tag |
| 18 | + }{ |
| 19 | + {data: []byte(`object 3b114ab800c6432ad42387ccf6bc8d4388a2885a |
| 20 | +type commit |
| 21 | +tag 1.22.0 |
| 22 | +tagger Lucas Michot <[email protected]> 1484491741 +0100 |
| 23 | +
|
| 24 | +`), tag: Tag{ |
| 25 | + Name: "", |
| 26 | + ID: SHA1{}, |
| 27 | + repo: nil, |
| 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: "[email protected]", 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 <[email protected]> 1484553735 +0100 |
| 38 | +
|
| 39 | +test message |
| 40 | +o |
| 41 | +
|
| 42 | +ono`), tag: Tag{ |
| 43 | + Name: "", |
| 44 | + ID: SHA1{}, |
| 45 | + repo: nil, |
| 46 | + Object: SHA1{0x7c, 0xdf, 0x42, 0xc0, 0xb1, 0xcc, 0x76, 0x3a, 0xb7, 0xe4, 0xc3, 0x3c, 0x47, 0xa2, 0x4e, 0x27, 0xc6, 0x6b, 0xfc, 0xcc}, |
| 47 | + Type: "commit", |
| 48 | + Tagger: &Signature{ Name: "Lucas Michot", Email: "[email protected]", When: time. Unix( 1484553735, 0)}, |
| 49 | + Message: "test message\no\n\nono", |
| 50 | + Signature: nil, |
| 51 | + }}, |
| 52 | + } |
| 53 | + |
| 54 | + for _, test := range testData { |
| 55 | + tag, err := parseTagData(test.data) |
| 56 | + assert.NoError(t, err) |
| 57 | + assert.EqualValues(t, test.tag.ID, tag.ID) |
| 58 | + assert.EqualValues(t, test.tag.Object, tag.Object) |
| 59 | + assert.EqualValues(t, test.tag.Name, tag.Name) |
| 60 | + assert.EqualValues(t, test.tag.Message, tag.Message) |
| 61 | + assert.EqualValues(t, test.tag.Type, tag.Type) |
| 62 | + if test.tag.Signature != nil && assert.NotNil(t, tag.Signature) { |
| 63 | + assert.EqualValues(t, test.tag.Signature.Signature, tag.Signature.Signature) |
| 64 | + assert.EqualValues(t, test.tag.Signature.Payload, tag.Signature.Payload) |
| 65 | + } else { |
| 66 | + assert.Nil(t, tag.Signature) |
| 67 | + } |
| 68 | + if test.tag.Tagger != nil && assert.NotNil(t, tag.Tagger) { |
| 69 | + assert.EqualValues(t, test.tag.Tagger.Name, tag.Tagger.Name) |
| 70 | + assert.EqualValues(t, test.tag.Tagger.Email, tag.Tagger.Email) |
| 71 | + assert.EqualValues(t, test.tag.Tagger.When.Unix(), tag.Tagger.When.Unix()) |
| 72 | + } else { |
| 73 | + assert.Nil(t, tag.Tagger) |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments