@@ -333,3 +333,70 @@ func TestGetCommitMessageFromHistory(t *testing.T) {
333333		})
334334	}
335335}
336+ 
337+ func  TestAddCoAuthorToMessage (t  * testing.T ) {
338+ 	scenarios  :=  []struct  {
339+ 		name            string 
340+ 		message         string 
341+ 		expectedResult  string 
342+ 	}{
343+ 		{
344+ 			// This never happens, I think it isn't possible to create a commit 
345+ 			// with an empty message. Just including it for completeness. 
346+ 			name :           "Empty message" ,
347+ 			message :        "" ,
348+ 			expectedResult : 
"\n \n Co-authored-by: John Doe <[email protected] >" ,
 349+ 		},
350+ 		{
351+ 			name :           "Just a subject, no body" ,
352+ 			message :        "Subject" ,
353+ 			expectedResult : 
"Subject\n \n Co-authored-by: John Doe <[email protected] >" ,
 354+ 		},
355+ 		{
356+ 			name :           "Subject and body" ,
357+ 			message :        "Subject\n \n Body" ,
358+ 			expectedResult : 
"Subject\n \n Body\n \n Co-authored-by: John Doe <[email protected] >" ,
 359+ 		},
360+ 		{
361+ 			name :           "Body already ending with a Co-authored-by line" ,
362+ 			message :        
"Subject\n \n Body\n \n Co-authored-by: Jane Smith <[email protected] >" ,
 363+ 			expectedResult : 
"Subject\n \n Body\n \n Co-authored-by: Jane Smith <[email protected] >\n Co-authored-by: John Doe <[email protected] >" ,
 364+ 		},
365+ 	}
366+ 	for  _ , s  :=  range  scenarios  {
367+ 		t .Run (s .name , func (t  * testing.T ) {
368+ 			result  :=  AddCoAuthorToMessage (
s .
message , 
"John Doe <[email protected] >" )
 369+ 			assert .Equal (t , s .expectedResult , result )
370+ 		})
371+ 	}
372+ }
373+ 
374+ func  TestAddCoAuthorToDescription (t  * testing.T ) {
375+ 	scenarios  :=  []struct  {
376+ 		name            string 
377+ 		description     string 
378+ 		expectedResult  string 
379+ 	}{
380+ 		{
381+ 			name :           "Empty description" ,
382+ 			description :    "" ,
383+ 			expectedResult : 
"Co-authored-by: John Doe <[email protected] >" ,
 384+ 		},
385+ 		{
386+ 			name :           "Non-empty description" ,
387+ 			description :    "Body" ,
388+ 			expectedResult : 
"Body\n \n Co-authored-by: John Doe <[email protected] >" ,
 389+ 		},
390+ 		{
391+ 			name :           "Description already ending with a Co-authored-by line" ,
392+ 			description :    
"Body\n \n Co-authored-by: Jane Smith <[email protected] >" ,
 393+ 			expectedResult : 
"Body\n \n Co-authored-by: Jane Smith <[email protected] >\n Co-authored-by: John Doe <[email protected] >" ,
 394+ 		},
395+ 	}
396+ 	for  _ , s  :=  range  scenarios  {
397+ 		t .Run (s .name , func (t  * testing.T ) {
398+ 			result  :=  AddCoAuthorToDescription (
s .
description , 
"John Doe <[email protected] >" )
 399+ 			assert .Equal (t , s .expectedResult , result )
400+ 		})
401+ 	}
402+ }
0 commit comments