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) } } }