Skip to content

Commit

Permalink
Make zone sync struct optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul Marrero authored and Rulox committed Jun 7, 2019
1 parent 8f20f67 commit bb9e3de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 3 additions & 4 deletions client/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Stats struct {
Upstreams Upstreams
StreamServerZones StreamServerZones
StreamUpstreams StreamUpstreams
StreamZoneSync StreamZoneSync
StreamZoneSync *StreamZoneSync
}

// NginxInfo contains general information about NGINX Plus.
Expand Down Expand Up @@ -764,7 +764,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
StreamServerZones: *streamZones,
Upstreams: *upstreams,
StreamUpstreams: *streamUpstreams,
StreamZoneSync: *streamZoneSync,
StreamZoneSync: streamZoneSync,
}, nil
}

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/client_no_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`")
}
}
8 changes: 8 additions & 0 deletions tests/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit bb9e3de

Please sign in to comment.