@@ -37,58 +37,57 @@ func Test_UncommittedChangeCount(t *testing.T) {
3737 }
3838}
3939
40- func Test_CurrentBranch_no_commits (t * testing.T ) {
40+ func Test_CurrentBranch (t * testing.T ) {
4141 cs , teardown := test .InitCmdStubber ()
4242 defer teardown ()
4343
4444 expected := "branch-name"
4545
46- cs .StubError ("" )
4746 cs .Stub (expected )
4847
4948 result , err := CurrentBranch ()
5049 if err != nil {
5150 t .Errorf ("got unexpected error: %w" , err )
5251 }
53- if len (cs .Calls ) != 2 {
54- t .Errorf ("expected 2 git calls , saw %d" , len (cs .Calls ))
52+ if len (cs .Calls ) != 1 {
53+ t .Errorf ("expected 1 git call , saw %d" , len (cs .Calls ))
5554 }
5655 if result != expected {
5756 t .Errorf ("unexpected branch name: %s instead of %s" , result , expected )
5857 }
5958}
6059
61- func Test_CurrentBranch (t * testing.T ) {
60+ func Test_CurrentBranch_detached_head (t * testing.T ) {
6261 cs , teardown := test .InitCmdStubber ()
6362 defer teardown ()
6463
65- expected := "branch-name"
66-
67- cs .Stub (expected )
64+ cs .StubError ("" )
6865
69- result , err := CurrentBranch ()
70- if err != nil {
71- t .Errorf ("got unexpected error: %w" , err )
66+ _ , err := CurrentBranch ()
67+ if err == nil {
68+ t .Errorf ("expected an error" )
69+ }
70+ expectedError := "git: not on any branch"
71+ if err .Error () != expectedError {
72+ t .Errorf ("got unexpected error: %s instead of %s" , err .Error (), expectedError )
7273 }
7374 if len (cs .Calls ) != 1 {
7475 t .Errorf ("expected 1 git call, saw %d" , len (cs .Calls ))
7576 }
76- if result != expected {
77- t .Errorf ("unexpected branch name: %s instead of %s" , result , expected )
78- }
7977}
8078
81- func Test_CurrentBranch_detached_head (t * testing.T ) {
79+ func Test_CurrentBranch_unexpected_error (t * testing.T ) {
8280 cs , teardown := test .InitCmdStubber ()
8381 defer teardown ()
8482
85- cs .Stub ("HEAD" )
83+ cs .StubError ("lol" )
84+
85+ expectedError := "lol\n stub: lol"
8686
8787 _ , err := CurrentBranch ()
8888 if err == nil {
8989 t .Errorf ("expected an error" )
9090 }
91- expectedError := "git: not on any branch"
9291 if err .Error () != expectedError {
9392 t .Errorf ("got unexpected error: %s instead of %s" , err .Error (), expectedError )
9493 }
0 commit comments