@@ -525,7 +525,7 @@ func TestHaveSameParametersForStream(t *testing.T) {
525
525
func TestClientWithCheckAPI (t * testing.T ) {
526
526
// Create a test server that returns supported API versions
527
527
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
528
- _ , err := w .Write ([]byte (`[4, 5, 6, 7]` ))
528
+ _ , err := w .Write ([]byte (`[4, 5, 6, 7, 8, 9 ]` ))
529
529
if err != nil {
530
530
t .Fatalf ("unexpected error: %v" , err )
531
531
}
@@ -542,7 +542,7 @@ func TestClientWithCheckAPI(t *testing.T) {
542
542
}
543
543
544
544
// Test creating a new client with an unsupported API version on the server
545
- client , err = NewNginxClient (ts .URL , WithAPIVersion (8 ), WithCheckAPI ())
545
+ client , err = NewNginxClient (ts .URL , WithAPIVersion (3 ), WithCheckAPI ())
546
546
if err == nil {
547
547
t .Fatalf ("expected error, but got nil" )
548
548
}
@@ -594,7 +594,7 @@ func TestClientWithHTTPClient(t *testing.T) {
594
594
func TestGetStats_NoStreamEndpoint (t * testing.T ) {
595
595
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
596
596
if r .RequestURI == "/" {
597
- _ , err := w .Write ([]byte (`[4, 5, 6, 7]` ))
597
+ _ , err := w .Write ([]byte (`[4, 5, 6, 7, 8, 9 ]` ))
598
598
if err != nil {
599
599
t .Fatalf ("unexpected error: %v" , err )
600
600
}
@@ -641,3 +641,80 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
641
641
t .Fatalf ("StreamZoneSync: expected %v, actual %v" , & StreamZoneSync {}, stats .StreamZoneSync )
642
642
}
643
643
}
644
+
645
+ func TestGetStats_SSL (t * testing.T ) {
646
+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
647
+ if r .RequestURI == "/" {
648
+ _ , err := w .Write ([]byte (`[4, 5, 6, 7, 8, 9]` ))
649
+ if err != nil {
650
+ t .Fatalf ("unexpected error: %v" , err )
651
+ }
652
+ } else if r .RequestURI == "/8/" {
653
+ _ , err := w .Write ([]byte (`["nginx","processes","connections","slabs","http","resolvers","ssl","workers"]` ))
654
+ if err != nil {
655
+ t .Fatalf ("unexpected error: %v" , err )
656
+ }
657
+ } else if strings .HasPrefix (r .RequestURI , "/8/ssl" ) {
658
+ _ , err := w .Write ([]byte (`{
659
+ "handshakes" : 79572,
660
+ "handshakes_failed" : 21025,
661
+ "session_reuses" : 15762,
662
+ "no_common_protocol" : 4,
663
+ "no_common_cipher" : 2,
664
+ "handshake_timeout" : 0,
665
+ "peer_rejected_cert" : 0,
666
+ "verify_failures" : {
667
+ "no_cert" : 0,
668
+ "expired_cert" : 2,
669
+ "revoked_cert" : 1,
670
+ "hostname_mismatch" : 2,
671
+ "other" : 1
672
+ }
673
+ }` ))
674
+ if err != nil {
675
+ t .Fatalf ("unexpected error: %v" , err )
676
+ }
677
+ } else {
678
+ _ , err := w .Write ([]byte (`{}` ))
679
+ if err != nil {
680
+ t .Fatalf ("unexpected error: %v" , err )
681
+ }
682
+ }
683
+ }))
684
+ defer ts .Close ()
685
+
686
+ // Test creating a new client with a supported API version on the server
687
+ client , err := NewNginxClient (ts .URL , WithAPIVersion (8 ), WithCheckAPI ())
688
+ if err != nil {
689
+ t .Fatalf ("unexpected error: %v" , err )
690
+ }
691
+ if client == nil {
692
+ t .Fatalf ("client is nil" )
693
+ }
694
+
695
+ stats , err := client .GetStats ()
696
+ if err != nil {
697
+ t .Fatalf ("unexpected error: %v" , err )
698
+ }
699
+
700
+ testStats := SSL {
701
+ Handshakes : 79572 ,
702
+ HandshakesFailed : 21025 ,
703
+ SessionReuses : 15762 ,
704
+ NoCommonProtocol : 4 ,
705
+ NoCommonCipher : 2 ,
706
+ HandshakeTimeout : 0 ,
707
+ PeerRejectedCert : 0 ,
708
+ VerifyFailures : VerifyFailures {
709
+ NoCert : 0 ,
710
+ ExpiredCert : 2 ,
711
+ RevokedCert : 1 ,
712
+ HostnameMismatch : 2 ,
713
+ Other : 1 ,
714
+ },
715
+ }
716
+
717
+ if ! reflect .DeepEqual (stats .SSL , testStats ) {
718
+ t .Fatalf ("SSL stats: expected %v, actual %v" , testStats , stats .SSL )
719
+ }
720
+ }
0 commit comments