@@ -72,9 +72,7 @@ func TestMockTransport(t *testing.T) {
7272 }
7373
7474 // the http client wraps our NoResponderFound error, so we just try and match on text
75- if _ , err := http .Get (testURL ); ! strings .Contains (err .Error (),
76- NoResponderFound .Error ()) {
77-
75+ if _ , err := http .Get (testURL ); ! strings .Contains (err .Error (), NoResponderFound .Error ()) {
7876 t .Fatal (err )
7977 }
8078 }()
@@ -567,7 +565,7 @@ func TestMockTransportRespectsTimeout(t *testing.T) {
567565 }
568566}
569567
570- func TestMockTransportCallCount (t * testing.T ) {
568+ func TestMockTransportCallCountReset (t * testing.T ) {
571569 Reset ()
572570 Activate ()
573571 defer Deactivate ()
@@ -611,7 +609,7 @@ func TestMockTransportCallCount(t *testing.T) {
611609 }
612610
613611 if ! reflect .DeepEqual (info , expectedInfo ) {
614- t .Fatalf ("did not correctly track the call count info. expected it to be \n %+v \n but it was \n %+v \n " , expectedInfo , info )
612+ t .Fatalf ("did not correctly track the call count info. expected it to be \n %+v\n but it was \n %+v" , expectedInfo , info )
615613 }
616614
617615 Reset ()
@@ -620,6 +618,77 @@ func TestMockTransportCallCount(t *testing.T) {
620618 if afterResetTotalCallCount != 0 {
621619 t .Fatalf ("did not reset the total count of calls correctly. expected it to be 0 after reset, but it was %v" , afterResetTotalCallCount )
622620 }
621+
622+ info = GetCallCountInfo ()
623+ if ! reflect .DeepEqual (info , map [string ]int {}) {
624+ t .Fatalf ("did not correctly reset the call count info. expected it to be \n {}\n but it was \n %+v" , info )
625+ }
626+ }
627+
628+ func TestMockTransportCallCountZero (t * testing.T ) {
629+ Reset ()
630+ Activate ()
631+ defer Deactivate ()
632+
633+ const (
634+ url = "https://github.com/path?b=1&a=2"
635+ url2 = "https://gitlab.com/"
636+ )
637+
638+ RegisterResponder ("GET" , url , NewStringResponder (200 , "body" ))
639+ RegisterResponder ("POST" , "=~gitlab" , NewStringResponder (200 , "body" ))
640+
641+ _ , err := http .Get (url )
642+ if err != nil {
643+ t .Fatal (err )
644+ }
645+
646+ buff := new (bytes.Buffer )
647+ json .NewEncoder (buff ).Encode ("{}" ) // nolint: errcheck
648+ _ , err = http .Post (url2 , "application/json" , buff )
649+ if err != nil {
650+ t .Fatal (err )
651+ }
652+
653+ _ , err = http .Get (url )
654+ if err != nil {
655+ t .Fatal (err )
656+ }
657+
658+ totalCallCount := GetTotalCallCount ()
659+ if totalCallCount != 3 {
660+ t .Fatalf ("did not track the total count of calls correctly. expected it to be 3, but it was %v" , totalCallCount )
661+ }
662+
663+ info := GetCallCountInfo ()
664+ expectedInfo := map [string ]int {
665+ "GET " + url : 2 ,
666+ // Regexp match generates 2 entries:
667+ "POST " + url2 : 1 , // the matched call
668+ "POST =~gitlab" : 1 , // the regexp responder
669+ }
670+
671+ if ! reflect .DeepEqual (info , expectedInfo ) {
672+ t .Fatalf ("did not correctly track the call count info. expected it to be \n %+v\n but it was \n %+v" , expectedInfo , info )
673+ }
674+
675+ ZeroCallCounters ()
676+
677+ afterResetTotalCallCount := GetTotalCallCount ()
678+ if afterResetTotalCallCount != 0 {
679+ t .Fatalf ("did not reset the total count of calls correctly. expected it to be 0 after reset, but it was %v" , afterResetTotalCallCount )
680+ }
681+
682+ info = GetCallCountInfo ()
683+ expectedInfo = map [string ]int {
684+ "GET " + url : 0 ,
685+ // Regexp match generates 2 entries:
686+ "POST " + url2 : 0 , // the matched call
687+ "POST =~gitlab" : 0 , // the regexp responder
688+ }
689+ if ! reflect .DeepEqual (info , expectedInfo ) {
690+ t .Fatalf ("did not correctly reset the call count info. expected it to be \n %+v\n but it was \n %+v" , expectedInfo , info )
691+ }
623692}
624693
625694func TestRegisterResponderWithQuery (t * testing.T ) {
0 commit comments