@@ -22,6 +22,7 @@ func TestConventionalCommitPolicy(t *testing.T) {
2222 Name string
2323 CreateCommit func (t * testing.T ) error
2424 ExpectValid bool
25+ Conventional * Conventional
2526 }
2627
2728 for _ , test := range []testDesc {
@@ -60,6 +61,27 @@ func TestConventionalCommitPolicy(t *testing.T) {
6061 CreateCommit : createInvalidEmptyCommit ,
6162 ExpectValid : false ,
6263 },
64+ {
65+ Name : "Fixup" ,
66+ CreateCommit : createFixupCommit ,
67+ ExpectValid : true ,
68+ },
69+ {
70+ Name : "FixupRejected" ,
71+ CreateCommit : createFixupCommit ,
72+ ExpectValid : false ,
73+ Conventional : rejectAutoSquashConventional (),
74+ },
75+ {
76+ Name : "Squash" ,
77+ CreateCommit : createSquashCommit ,
78+ ExpectValid : true ,
79+ },
80+ {
81+ Name : "Amend" ,
82+ CreateCommit : createAmendCommit ,
83+ ExpectValid : true ,
84+ },
6385 } {
6486 func (test testDesc ) {
6587 t .Run (test .Name , func (tt * testing.T ) {
@@ -77,7 +99,7 @@ func TestConventionalCommitPolicy(t *testing.T) {
7799 tt .Error (err )
78100 }
79101
80- report , err := runCompliance ( )
102+ report , err := runComplianceWithConventional ( test . Conventional )
81103 if err != nil {
82104 t .Error (err )
83105 }
@@ -363,16 +385,30 @@ func runComplianceRange(id1, id2 string) (*policy.Report, error) {
363385}
364386
365387func runCompliance () (* policy.Report , error ) {
366- c := & Commit {
367- Conventional : & Conventional {
388+ return runComplianceWithConventional (nil )
389+ }
390+
391+ func runComplianceWithConventional (conventional * Conventional ) (* policy.Report , error ) {
392+ if conventional == nil {
393+ conventional = & Conventional {
368394 Types : []string {"type" },
369395 Scopes : []string {"scope" , "^valid" },
370- },
396+ }
371397 }
372398
399+ c := & Commit {Conventional : conventional }
400+
373401 return c .Compliance (& policy.Options {})
374402}
375403
404+ func rejectAutoSquashConventional () * Conventional {
405+ return & Conventional {
406+ Types : []string {"type" },
407+ Scopes : []string {"scope" , "^valid" },
408+ RejectAutoSquash : true ,
409+ }
410+ }
411+
376412func initRepo (t * testing.T ) error {
377413 _ , err := exec .CommandContext (t .Context (), "git" , "init" ).Output ()
378414 if err != nil {
@@ -442,3 +478,21 @@ func createInvalidCommitRegex(t *testing.T) error {
442478
443479 return err
444480}
481+
482+ func createFixupCommit (t * testing.T ) error {
483+ _ , err := exec .CommandContext (t .Context (), "git" , "-c" , "user.name='test'" , "-c" , "user.email='test@siderolabs.io'" , "commit" , "-m" , "fixup! deadbeef" ).Output ()
484+
485+ return err
486+ }
487+
488+ func createSquashCommit (t * testing.T ) error {
489+ _ , err := exec .CommandContext (t .Context (), "git" , "-c" , "user.name='test'" , "-c" , "user.email='test@siderolabs.io'" , "commit" , "-m" , "squash! deadbeef" ).Output ()
490+
491+ return err
492+ }
493+
494+ func createAmendCommit (t * testing.T ) error {
495+ _ , err := exec .CommandContext (t .Context (), "git" , "-c" , "user.name='test'" , "-c" , "user.email='test@siderolabs.io'" , "commit" , "-m" , "amend! deadbeef" ).Output ()
496+
497+ return err
498+ }
0 commit comments