From 7c662ff0650ca48a0a51eb5fa2b720584816f6fb Mon Sep 17 00:00:00 2001 From: Abhishek Gupta Date: Mon, 22 Sep 2014 13:18:55 -0700 Subject: [PATCH 1/2] Adding GetEndpoints method to the client EndpointsInterface --- pkg/client/client.go | 8 ++++++++ pkg/client/fake.go | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/pkg/client/client.go b/pkg/client/client.go index 6cecf36cc69..0ca6da7bad1 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -78,6 +78,7 @@ type ServiceInterface interface { // EndpointsInterface has methods to work with Endpoints resources type EndpointsInterface interface { ListEndpoints(selector labels.Selector) (*api.EndpointsList, error) + GetEndpoints(id string) (*api.Endpoints, error) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) } @@ -429,6 +430,13 @@ func (c *Client) ListEndpoints(selector labels.Selector) (result *api.EndpointsL return } +// GetEndpoints returns information about the endpoints for a particular service. +func (c *Client) GetEndpoints(id string) (result *api.Endpoints, err error) { + result = &api.Endpoints{} + err = c.Get().Path("endpoints").Path(id).Do().Into(result) + return +} + // WatchEndpoints returns a watch.Interface that watches the requested endpoints for a service. func (c *Client) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) { return c.Get(). diff --git a/pkg/client/fake.go b/pkg/client/fake.go index 618b28d9c57..b172cd5294f 100644 --- a/pkg/client/fake.go +++ b/pkg/client/fake.go @@ -132,6 +132,11 @@ func (c *Fake) ListEndpoints(selector labels.Selector) (*api.EndpointsList, erro return api.Scheme.CopyOrDie(&c.EndpointsList).(*api.EndpointsList), c.Err } +func (c *Fake) GetEndpoints(name string) (*api.Endpoints, error) { + c.Actions = append(c.Actions, FakeAction{Action: "get-endpoints"}) + return &api.Endpoints{}, nil +} + func (c *Fake) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) { c.Actions = append(c.Actions, FakeAction{Action: "watch-endpoints", Value: resourceVersion}) return c.Watch, c.Err From 002a5c6c291424618d466c4ded6a3da21fef45e7 Mon Sep 17 00:00:00 2001 From: Abhishek Gupta Date: Mon, 22 Sep 2014 17:39:47 -0700 Subject: [PATCH 2/2] Added test case --- pkg/client/client_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index abfdaa241e3..547d56afdf3 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -541,6 +541,33 @@ func TestDeleteService(t *testing.T) { c.Validate(t, nil, err) } +func TestListEndpooints(t *testing.T) { + c := &testClient{ + Request: testRequest{Method: "GET", Path: "/endpoints"}, + Response: Response{StatusCode: 200, + Body: &api.EndpointsList{ + Items: []api.Endpoints{ + { + JSONBase: api.JSONBase{ID: "endpoint-1"}, + Endpoints: []string{"10.245.1.2:8080", "10.245.1.3:8080"}, + }, + }, + }, + }, + } + receivedEndpointsList, err := c.Setup().ListEndpoints(labels.Everything()) + c.Validate(t, receivedEndpointsList, err) +} + +func TestGetEndpoints(t *testing.T) { + c := &testClient{ + Request: testRequest{Method: "GET", Path: "/endpoints/endpoint-1"}, + Response: Response{StatusCode: 200, Body: &api.Endpoints{JSONBase: api.JSONBase{ID: "endpoint-1"}}}, + } + response, err := c.Setup().GetEndpoints("endpoint-1") + c.Validate(t, response, err) +} + func TestDoRequest(t *testing.T) { invalid := "aaaaa" testClients := []testClient{