@@ -39,50 +39,43 @@ func Test_UncommittedChangeCount(t *testing.T) {
3939}
4040
4141func Test_CurrentBranch (t * testing.T ) {
42- cs , teardown := test .InitCmdStubber ()
43- defer teardown ()
44-
45- expected := "branch-name"
46-
47- cs .Stub (expected )
48-
49- result , err := CurrentBranch ()
50- if err != nil {
51- t .Errorf ("got unexpected error: %w" , err )
52- }
53- if len (cs .Calls ) != 1 {
54- t .Errorf ("expected 1 git call, saw %d" , len (cs .Calls ))
42+ type c struct {
43+ Stub string
44+ Expected string
5545 }
56- if result != expected {
57- t .Errorf ("unexpected branch name: %s instead of %s" , result , expected )
46+ cases := []c {
47+ {
48+ Stub : "branch-name" ,
49+ Expected : "branch-name" ,
50+ },
51+ {
52+ Stub : "refs/heads/branch-name" ,
53+ Expected : "branch-name" ,
54+ },
5855 }
59- }
6056
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 )
57+ for _ , v := range cases {
58+ cs , teardown := test .InitCmdStubber ()
59+ cs .Stub (v .Stub )
6860
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 )
61+ result , err := CurrentBranch ()
62+ if err != nil {
63+ t .Errorf ("got unexpected error: %w" , err )
64+ }
65+ if len (cs .Calls ) != 1 {
66+ t .Errorf ("expected 1 git call, saw %d" , len (cs .Calls ))
67+ }
68+ if result != v .Expected {
69+ t .Errorf ("unexpected branch name: %s instead of %s" , result , v .Expected )
70+ }
71+ teardown ()
7872 }
7973}
8074
8175func Test_CurrentBranch_detached_head (t * testing.T ) {
8276 cs , teardown := test .InitCmdStubber ()
8377 defer teardown ()
8478
85- cs .StubError ("" )
8679 cs .StubError ("" )
8780
8881 _ , err := CurrentBranch ()
@@ -92,16 +85,15 @@ func Test_CurrentBranch_detached_head(t *testing.T) {
9285 if err != ErrNotOnAnyBranch {
9386 t .Errorf ("got unexpected error: %s instead of %s" , err , ErrNotOnAnyBranch )
9487 }
95- if len (cs .Calls ) != 2 {
96- t .Errorf ("expected 2 git calls , saw %d" , len (cs .Calls ))
88+ if len (cs .Calls ) != 1 {
89+ t .Errorf ("expected 1 git call , saw %d" , len (cs .Calls ))
9790 }
9891}
9992
10093func Test_CurrentBranch_unexpected_error (t * testing.T ) {
10194 cs , teardown := test .InitCmdStubber ()
10295 defer teardown ()
10396
104- cs .StubError ("lol" )
10597 cs .StubError ("lol" )
10698
10799 expectedError := "lol\n stub: lol"
@@ -113,8 +105,8 @@ func Test_CurrentBranch_unexpected_error(t *testing.T) {
113105 if err .Error () != expectedError {
114106 t .Errorf ("got unexpected error: %s instead of %s" , err .Error (), expectedError )
115107 }
116- if len (cs .Calls ) != 2 {
117- t .Errorf ("expected 2 git calls , saw %d" , len (cs .Calls ))
108+ if len (cs .Calls ) != 1 {
109+ t .Errorf ("expected 1 git call , saw %d" , len (cs .Calls ))
118110 }
119111}
120112
0 commit comments