File: message_test.go

package info (click to toggle)
golang-github-libgit2-git2go 34.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 920 kB
  • sloc: ansic: 471; sh: 85; makefile: 39
file content (42 lines) | stat: -rw-r--r-- 994 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
package git

import (
	"fmt"
	"reflect"
	"testing"
)

func TestTrailers(t *testing.T) {
	t.Parallel()
	tests := []struct {
		input    string
		expected []Trailer
	}{
		{
			"commit with zero trailers\n",
			[]Trailer{},
		},
		{
			"commit with one trailer\n\nCo-authored-by: Alice <alice@example.com>\n",
			[]Trailer{
				Trailer{Key: "Co-authored-by", Value: "Alice <alice@example.com>"},
			},
		},
		{
			"commit with two trailers\n\nCo-authored-by: Alice <alice@example.com>\nSigned-off-by: Bob <bob@example.com>\n",
			[]Trailer{
				Trailer{Key: "Co-authored-by", Value: "Alice <alice@example.com>"},
				Trailer{Key: "Signed-off-by", Value: "Bob <bob@example.com>"}},
		},
	}
	for _, test := range tests {
		fmt.Printf("%s", test.input)
		actual, err := MessageTrailers(test.input)
		if err != nil {
			t.Errorf("Trailers returned an unexpected error: %v", err)
		}
		if !reflect.DeepEqual(test.expected, actual) {
			t.Errorf("expecting %#v\ngot %#v", test.expected, actual)
		}
	}
}