@@ -72,9 +72,7 @@ func TestMockTransport(t *testing.T) {
72
72
}
73
73
74
74
// 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 ()) {
78
76
t .Fatal (err )
79
77
}
80
78
}()
@@ -567,7 +565,7 @@ func TestMockTransportRespectsTimeout(t *testing.T) {
567
565
}
568
566
}
569
567
570
- func TestMockTransportCallCount (t * testing.T ) {
568
+ func TestMockTransportCallCountReset (t * testing.T ) {
571
569
Reset ()
572
570
Activate ()
573
571
defer Deactivate ()
@@ -611,7 +609,7 @@ func TestMockTransportCallCount(t *testing.T) {
611
609
}
612
610
613
611
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 )
615
613
}
616
614
617
615
Reset ()
@@ -620,6 +618,77 @@ func TestMockTransportCallCount(t *testing.T) {
620
618
if afterResetTotalCallCount != 0 {
621
619
t .Fatalf ("did not reset the total count of calls correctly. expected it to be 0 after reset, but it was %v" , afterResetTotalCallCount )
622
620
}
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
+ }
623
692
}
624
693
625
694
func TestRegisterResponderWithQuery (t * testing.T ) {
0 commit comments