Skip to content

Make zone sync struct optional #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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