From 5241c72e6ebd21085e56a1c6d284c06154a202b5 Mon Sep 17 00:00:00 2001 From: Jesse Hathaway Date: Tue, 2 Jun 2020 12:30:42 -0500 Subject: Add support for parsing git trailers (#614) Adds a wrapper for git_message_trailers which returns a slice of trailer structs. --- message_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 message_test.go (limited to 'message_test.go') diff --git a/message_test.go b/message_test.go new file mode 100644 index 0000000..f33ccb7 --- /dev/null +++ b/message_test.go @@ -0,0 +1,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 \n", + []Trailer{ + Trailer{Key: "Co-authored-by", Value: "Alice "}, + }, + }, + { + "commit with two trailers\n\nCo-authored-by: Alice \nSigned-off-by: Bob \n", + []Trailer{ + Trailer{Key: "Co-authored-by", Value: "Alice "}, + Trailer{Key: "Signed-off-by", Value: "Bob "}}, + }, + } + 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) + } + } +} -- cgit v1.2.3