@@ -40,8 +40,7 @@ func TestValidate(t *testing.T) {
4040 assert .Contains (t , buffer .String (), "i am two characters more thäaaaaaaaaaaaaaaaaaaaan " + color .Yellow + "50" )
4141 })
4242
43- t .Run ("returns 1 when commit message too long" , func (t * testing.T ) {
44- buffer .Reset ()
43+ t .Run ("asks user for abort when commit message too long" , func (t * testing.T ) {
4544 testFile := t .TempDir () + "/text.txt"
4645 content := "waaaaaaaaaaaaaaaaaaaaaaaaaay tooooooooooooooooooo" +
4746 "looooooooooooooooooooooong"
@@ -50,10 +49,34 @@ func TestValidate(t *testing.T) {
5049 handler := NewHandler (model.Config {CommitMsgFile : testFile })
5150 handler .Writer = buffer
5251
53- status := handler .Run ("validate" )
52+ t .Run ("user confirms abort returns 1" , func (t * testing.T ) {
53+ buffer .Reset ()
54+ handler .Reader = bytes .NewReader ([]byte ("y" ))
5455
55- assert .Contains (t , buffer .String (), color .Red + "Abort commit" )
56- assert .Equal (t , 1 , status )
56+ status := handler .Run ("validate" )
57+
58+ assert .Contains (t , buffer .String (), color .Red + "Subject line too long. Do you want to abort? (y/n)" )
59+ assert .Equal (t , 1 , status )
60+ })
61+
62+ t .Run ("user declines abort returns 0" , func (t * testing.T ) {
63+ buffer .Reset ()
64+ handler .Reader = bytes .NewReader ([]byte ("n" ))
65+
66+ status := handler .Run ("validate" )
67+
68+ assert .Equal (t , 0 , status )
69+ })
70+
71+ t .Run ("error at reading user input returns 1" , func (t * testing.T ) {
72+ buffer .Reset ()
73+ handler .Reader = bytes .NewReader ([]byte ("" ))
74+
75+ status := handler .Run ("validate" )
76+
77+ assert .Equal (t , 1 , status )
78+ assert .Contains (t , buffer .String (), color .Red + "Could not read user input." )
79+ })
5780 })
5881
5982 t .Run ("returns 1 when error at reading file" , func (t * testing.T ) {
0 commit comments