8
8
"strings"
9
9
"sync"
10
10
"testing"
11
- "time"
12
11
)
13
12
14
13
func TestDetermineUpdates (t * testing.T ) {
@@ -581,27 +580,6 @@ func TestClientWithAPIVersion(t *testing.T) {
581
580
}
582
581
}
583
582
584
- func TestClientWithTimeout (t * testing.T ) {
585
- t .Parallel ()
586
- // Test creating a new client with a supported API version on the client
587
- client , err := NewNginxClient ("http://api-url" , WithTimeout (1 * time .Second ))
588
- if err != nil {
589
- t .Fatalf ("unexpected error: %v" , err )
590
- }
591
- if client == nil {
592
- t .Fatalf ("client is nil" )
593
- }
594
-
595
- // Test creating a new client with an invalid duration
596
- client , err = NewNginxClient ("http://api-url" , WithTimeout (- 1 * time .Second ))
597
- if err == nil {
598
- t .Fatalf ("expected error, but got nil" )
599
- }
600
- if client != nil {
601
- t .Fatalf ("expected client to be nil, but got %v" , client )
602
- }
603
- }
604
-
605
583
func TestClientWithHTTPClient (t * testing.T ) {
606
584
t .Parallel ()
607
585
// Test creating a new client passing a custom HTTP client
@@ -687,21 +665,6 @@ func TestClientWithMaxAPI(t *testing.T) {
687
665
}
688
666
689
667
func TestGetStats_NoStreamEndpoint (t * testing.T ) {
690
- tests := []struct {
691
- ctx context.Context
692
- name string
693
- }{
694
- {
695
- ctx : nil ,
696
- name : "no context test" ,
697
- },
698
- {
699
- ctx : context .Background (),
700
- name : "with context test" ,
701
- },
702
- }
703
- var err error
704
- var client * NginxClient
705
668
var writeLock sync.Mutex
706
669
707
670
t .Parallel ()
@@ -712,19 +675,19 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
712
675
switch {
713
676
case r .RequestURI == "/" :
714
677
715
- _ , err = w .Write ([]byte (`[4, 5, 6, 7, 8, 9]` ))
678
+ _ , err : = w .Write ([]byte (`[4, 5, 6, 7, 8, 9]` ))
716
679
if err != nil {
717
680
t .Fatalf ("unexpected error: %v" , err )
718
681
}
719
682
case r .RequestURI == "/7/" :
720
- _ , err = w .Write ([]byte (`["nginx","processes","connections","slabs","http","resolvers","ssl"]` ))
683
+ _ , err : = w .Write ([]byte (`["nginx","processes","connections","slabs","http","resolvers","ssl"]` ))
721
684
if err != nil {
722
685
t .Fatalf ("unexpected error: %v" , err )
723
686
}
724
687
case strings .HasPrefix (r .RequestURI , "/7/stream" ):
725
688
t .Fatal ("Stream endpoint should not be called since it does not exist." )
726
689
default :
727
- _ , err = w .Write ([]byte (`{}` ))
690
+ _ , err : = w .Write ([]byte (`{}` ))
728
691
if err != nil {
729
692
t .Fatalf ("unexpected error: %v" , err )
730
693
}
@@ -733,27 +696,17 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
733
696
defer ts .Close ()
734
697
735
698
// Test creating a new client with a supported API version on the server
736
- client , err = NewNginxClient (ts .URL , WithAPIVersion (7 ), WithCheckAPI ())
699
+ client , err : = NewNginxClient (ts .URL , WithAPIVersion (7 ), WithCheckAPI ())
737
700
if err != nil {
738
701
t .Fatalf ("unexpected error: %v" , err )
739
702
}
740
703
if client == nil {
741
704
t .Fatalf ("client is nil" )
742
705
}
743
706
744
- var stats * Stats
745
- for _ , test := range tests {
746
- if test .ctx == nil {
747
- stats , err = client .GetStats ()
748
- if err != nil {
749
- t .Fatalf ("unexpected error: %v" , err )
750
- }
751
- } else {
752
- stats , err = client .GetStatsWithContext (test .ctx )
753
- if err != nil {
754
- t .Fatalf ("unexpected error: %v" , err )
755
- }
756
- }
707
+ stats , err := client .GetStats (context .Background ())
708
+ if err != nil {
709
+ t .Fatalf ("unexpected error: %v" , err )
757
710
}
758
711
759
712
if ! reflect .DeepEqual (stats .StreamServerZones , StreamServerZones {}) {
@@ -771,20 +724,6 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
771
724
}
772
725
773
726
func TestGetStats_SSL (t * testing.T ) {
774
- tests := []struct {
775
- ctx context.Context
776
- name string
777
- }{
778
- {
779
- ctx : nil ,
780
- name : "no context test" ,
781
- },
782
- {
783
- ctx : context .Background (),
784
- name : "with context test" ,
785
- },
786
- }
787
-
788
727
t .Parallel ()
789
728
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
790
729
switch {
@@ -841,41 +780,30 @@ func TestGetStats_SSL(t *testing.T) {
841
780
t .Fatalf ("client is nil" )
842
781
}
843
782
844
- var stats * Stats
845
-
846
- for _ , test := range tests {
847
- if test .ctx == nil {
848
- stats , err = client .GetStats ()
849
- if err != nil {
850
- t .Fatalf ("unexpected error: %v" , err )
851
- }
852
- } else {
853
- stats , err = client .GetStatsWithContext (test .ctx )
854
- if err != nil {
855
- t .Fatalf ("unexpected error: %v" , err )
856
- }
857
- }
783
+ stats , err := client .GetStats (context .Background ())
784
+ if err != nil {
785
+ t .Fatalf ("unexpected error: %v" , err )
786
+ }
858
787
859
- testStats := SSL {
860
- Handshakes : 79572 ,
861
- HandshakesFailed : 21025 ,
862
- SessionReuses : 15762 ,
863
- NoCommonProtocol : 4 ,
864
- NoCommonCipher : 2 ,
865
- HandshakeTimeout : 0 ,
866
- PeerRejectedCert : 0 ,
867
- VerifyFailures : VerifyFailures {
868
- NoCert : 0 ,
869
- ExpiredCert : 2 ,
870
- RevokedCert : 1 ,
871
- HostnameMismatch : 2 ,
872
- Other : 1 ,
873
- },
874
- }
788
+ testStats := SSL {
789
+ Handshakes : 79572 ,
790
+ HandshakesFailed : 21025 ,
791
+ SessionReuses : 15762 ,
792
+ NoCommonProtocol : 4 ,
793
+ NoCommonCipher : 2 ,
794
+ HandshakeTimeout : 0 ,
795
+ PeerRejectedCert : 0 ,
796
+ VerifyFailures : VerifyFailures {
797
+ NoCert : 0 ,
798
+ ExpiredCert : 2 ,
799
+ RevokedCert : 1 ,
800
+ HostnameMismatch : 2 ,
801
+ Other : 1 ,
802
+ },
803
+ }
875
804
876
- if ! reflect .DeepEqual (stats .SSL , testStats ) {
877
- t .Fatalf ("SSL stats: expected %v, actual %v" , testStats , stats .SSL )
878
- }
805
+ if ! reflect .DeepEqual (stats .SSL , testStats ) {
806
+ t .Fatalf ("SSL stats: expected %v, actual %v" , testStats , stats .SSL )
879
807
}
880
808
}
881
809
@@ -902,7 +830,7 @@ func TestGetMaxAPIVersionServer(t *testing.T) {
902
830
t .Fatalf ("unexpected error: %v" , err )
903
831
}
904
832
905
- maxVer , err := c .GetMaxAPIVersion ()
833
+ maxVer , err := c .GetMaxAPIVersion (context . Background () )
906
834
if err != nil {
907
835
t .Fatalf ("unexpected error: %v" , err )
908
836
}
@@ -934,7 +862,7 @@ func TestGetMaxAPIVersionClient(t *testing.T) {
934
862
t .Fatalf ("unexpected error: %v" , err )
935
863
}
936
864
937
- maxVer , err := c .GetMaxAPIVersion ()
865
+ maxVer , err := c .GetMaxAPIVersion (context . Background () )
938
866
if err != nil {
939
867
t .Fatalf ("unexpected error: %v" , err )
940
868
}
0 commit comments