@@ -565,7 +565,7 @@ func TestMockTransportRespectsTimeout(t *testing.T) {
565565 }
566566}
567567
568- func TestMockTransportCallCount (t * testing.T ) {
568+ func TestMockTransportCallCountReset (t * testing.T ) {
569569 Reset ()
570570 Activate ()
571571 defer Deactivate ()
@@ -609,7 +609,7 @@ func TestMockTransportCallCount(t *testing.T) {
609609 }
610610
611611 if ! reflect .DeepEqual (info , expectedInfo ) {
612- 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 )
613613 }
614614
615615 Reset ()
@@ -618,6 +618,77 @@ func TestMockTransportCallCount(t *testing.T) {
618618 if afterResetTotalCallCount != 0 {
619619 t .Fatalf ("did not reset the total count of calls correctly. expected it to be 0 after reset, but it was %v" , afterResetTotalCallCount )
620620 }
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+ }
621692}
622693
623694func TestRegisterResponderWithQuery (t * testing.T ) {
0 commit comments