client: return ErrNoEndpoint when none available

In certain cases (for example, if a cluster peer is accessible but it
has no members listed), the httpClusterClient could have an empty set of
endpoints as a result of the Sync. This means that its Do function could
potentially return a nil response and nil error, with catastrophic
consequences for callers.

To be safe (particularly about this latter behaviour), this change
errors in both Sync and Do if no endpoints are available.
This commit is contained in:
Jonathan Boulle
2014-11-04 12:51:43 -08:00
parent 915f8f4822
commit 45b7c9a4ac
2 changed files with 15 additions and 0 deletions

View File

@ -234,6 +234,14 @@ func TestHTTPClusterClientDo(t *testing.T) {
wantErr: ErrCanceled,
},
// return err if there are no endpoints
{
client: &httpClusterClient{
endpoints: []HTTPClient{},
},
wantErr: ErrNoEndpoints,
},
// return err if all endpoints return arbitrary errors
{
client: &httpClusterClient{