Skip to content

Commit bb9e3de

Browse files
committed
Make zone sync struct optional
1 parent 8f20f67 commit bb9e3de

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

client/nginx.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type Stats struct {
8888
Upstreams Upstreams
8989
StreamServerZones StreamServerZones
9090
StreamUpstreams StreamUpstreams
91-
StreamZoneSync StreamZoneSync
91+
StreamZoneSync *StreamZoneSync
9292
}
9393

9494
// NginxInfo contains general information about NGINX Plus.
@@ -764,7 +764,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
764764
StreamServerZones: *streamZones,
765765
Upstreams: *upstreams,
766766
StreamUpstreams: *streamUpstreams,
767-
StreamZoneSync: *streamZoneSync,
767+
StreamZoneSync: streamZoneSync,
768768
}, nil
769769
}
770770

@@ -855,9 +855,8 @@ func (client *NginxClient) getStreamZoneSync() (*StreamZoneSync, error) {
855855
err := client.get("stream/zone_sync", &streamZoneSync)
856856
if err != nil {
857857
if err, ok := err.(*internalError); ok {
858-
859858
if err.Code == pathNotFoundCode {
860-
return &streamZoneSync, nil
859+
return nil, nil
861860
}
862861
}
863862
return nil, fmt.Errorf("failed to get stream zone sync: %v", err)

tests/client_no_stream_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ func TestStatsNoStream(t *testing.T) {
3434
if len(stats.StreamUpstreams) != 0 {
3535
t.Error("No stream block should result in no StreamUpstreams")
3636
}
37+
38+
if stats.StreamZoneSync != nil {
39+
t.Error("No stream block should result in StreamZoneSync = `nil`")
40+
}
3741
}

tests/client_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@ func TestStreamZoneSync(t *testing.T) {
767767
t.Errorf("Error getting stats: %v", err)
768768
}
769769

770+
if statsC1.StreamZoneSync == nil {
771+
t.Errorf("Stream zone sync can't be nil if configured")
772+
}
773+
770774
if statsC1.StreamZoneSync.Status.NodesOnline == 0 {
771775
t.Errorf("At least 1 node must be online")
772776
}
@@ -803,6 +807,10 @@ func TestStreamZoneSync(t *testing.T) {
803807
t.Errorf("Error getting stats: %v", err)
804808
}
805809

810+
if statsC2.StreamZoneSync == nil {
811+
t.Errorf("Stream zone sync can't be nil if configured")
812+
}
813+
806814
if statsC2.StreamZoneSync.Status.NodesOnline == 0 {
807815
t.Errorf("At least 1 node must be online")
808816
}

0 commit comments

Comments
 (0)