diff --git a/client/nginx.go b/client/nginx.go index e75b5d22..4c609053 100644 --- a/client/nginx.go +++ b/client/nginx.go @@ -88,7 +88,7 @@ type Stats struct { Upstreams Upstreams StreamServerZones StreamServerZones StreamUpstreams StreamUpstreams - StreamZoneSync StreamZoneSync + StreamZoneSync *StreamZoneSync } // NginxInfo contains general information about NGINX Plus. @@ -764,7 +764,7 @@ func (client *NginxClient) GetStats() (*Stats, error) { StreamServerZones: *streamZones, Upstreams: *upstreams, StreamUpstreams: *streamUpstreams, - StreamZoneSync: *streamZoneSync, + StreamZoneSync: streamZoneSync, }, nil } @@ -855,9 +855,8 @@ func (client *NginxClient) getStreamZoneSync() (*StreamZoneSync, error) { err := client.get("stream/zone_sync", &streamZoneSync) if err != nil { if err, ok := err.(*internalError); ok { - if err.Code == pathNotFoundCode { - return &streamZoneSync, nil + return nil, nil } } return nil, fmt.Errorf("failed to get stream zone sync: %v", err) diff --git a/tests/client_no_stream_test.go b/tests/client_no_stream_test.go index 5c5a0bb3..7fc77b86 100644 --- a/tests/client_no_stream_test.go +++ b/tests/client_no_stream_test.go @@ -34,4 +34,8 @@ func TestStatsNoStream(t *testing.T) { if len(stats.StreamUpstreams) != 0 { t.Error("No stream block should result in no StreamUpstreams") } + + if stats.StreamZoneSync != nil { + t.Error("No stream block should result in StreamZoneSync = `nil`") + } } diff --git a/tests/client_test.go b/tests/client_test.go index a01cd71b..c29032b9 100644 --- a/tests/client_test.go +++ b/tests/client_test.go @@ -767,6 +767,10 @@ func TestStreamZoneSync(t *testing.T) { t.Errorf("Error getting stats: %v", err) } + if statsC1.StreamZoneSync == nil { + t.Errorf("Stream zone sync can't be nil if configured") + } + if statsC1.StreamZoneSync.Status.NodesOnline == 0 { t.Errorf("At least 1 node must be online") } @@ -803,6 +807,10 @@ func TestStreamZoneSync(t *testing.T) { t.Errorf("Error getting stats: %v", err) } + if statsC2.StreamZoneSync == nil { + t.Errorf("Stream zone sync can't be nil if configured") + } + if statsC2.StreamZoneSync.Status.NodesOnline == 0 { t.Errorf("At least 1 node must be online") }