@@ -525,7 +525,7 @@ func TestHaveSameParametersForStream(t *testing.T) {
525525func TestClientWithCheckAPI (t * testing.T ) {
526526 // Create a test server that returns supported API versions
527527 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 ]` ))
529529 if err != nil {
530530 t .Fatalf ("unexpected error: %v" , err )
531531 }
@@ -542,7 +542,7 @@ func TestClientWithCheckAPI(t *testing.T) {
542542 }
543543
544544 // 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 ())
546546 if err == nil {
547547 t .Fatalf ("expected error, but got nil" )
548548 }
@@ -594,7 +594,7 @@ func TestClientWithHTTPClient(t *testing.T) {
594594func TestGetStats_NoStreamEndpoint (t * testing.T ) {
595595 ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
596596 if r .RequestURI == "/" {
597- _ , err := w .Write ([]byte (`[4, 5, 6, 7]` ))
597+ _ , err := w .Write ([]byte (`[4, 5, 6, 7, 8, 9 ]` ))
598598 if err != nil {
599599 t .Fatalf ("unexpected error: %v" , err )
600600 }
@@ -641,3 +641,80 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
641641 t .Fatalf ("StreamZoneSync: expected %v, actual %v" , & StreamZoneSync {}, stats .StreamZoneSync )
642642 }
643643}
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