@@ -58,10 +58,31 @@ func Test_CurrentBranch(t *testing.T) {
5858 }
5959}
6060
61+ func Test_CurrentBranch_show_current_error (t * testing.T ) {
62+ cs , teardown := test .InitCmdStubber ()
63+ defer teardown ()
64+
65+ cs .StubError ("" )
66+ expected := "branch-name"
67+ cs .Stub (expected )
68+
69+ result , err := CurrentBranch ()
70+ if err != nil {
71+ t .Errorf ("got unexpected error: %w" , err )
72+ }
73+ if len (cs .Calls ) != 2 {
74+ t .Errorf ("expected 2 git calls, saw %d" , len (cs .Calls ))
75+ }
76+ if result != expected {
77+ t .Errorf ("unexpected branch name: %s instead of %s" , result , expected )
78+ }
79+ }
80+
6181func Test_CurrentBranch_detached_head (t * testing.T ) {
6282 cs , teardown := test .InitCmdStubber ()
6383 defer teardown ()
6484
85+ cs .StubError ("" )
6586 cs .StubError ("" )
6687
6788 _ , err := CurrentBranch ()
@@ -71,15 +92,16 @@ func Test_CurrentBranch_detached_head(t *testing.T) {
7192 if err != ErrNotOnAnyBranch {
7293 t .Errorf ("got unexpected error: %s instead of %s" , err , ErrNotOnAnyBranch )
7394 }
74- if len (cs .Calls ) != 1 {
75- t .Errorf ("expected 1 git call , saw %d" , len (cs .Calls ))
95+ if len (cs .Calls ) != 2 {
96+ t .Errorf ("expected 2 git calls , saw %d" , len (cs .Calls ))
7697 }
7798}
7899
79100func Test_CurrentBranch_unexpected_error (t * testing.T ) {
80101 cs , teardown := test .InitCmdStubber ()
81102 defer teardown ()
82103
104+ cs .StubError ("lol" )
83105 cs .StubError ("lol" )
84106
85107 expectedError := "lol\n stub: lol"
@@ -91,8 +113,8 @@ func Test_CurrentBranch_unexpected_error(t *testing.T) {
91113 if err .Error () != expectedError {
92114 t .Errorf ("got unexpected error: %s instead of %s" , err .Error (), expectedError )
93115 }
94- if len (cs .Calls ) != 1 {
95- t .Errorf ("expected 1 git call , saw %d" , len (cs .Calls ))
116+ if len (cs .Calls ) != 2 {
117+ t .Errorf ("expected 2 git calls , saw %d" , len (cs .Calls ))
96118 }
97119}
98120
0 commit comments