Make client use pointers

This commit is contained in:
Daniel Smith 2014-09-07 18:31:11 -07:00
parent 0d30a656ef
commit 48ce23ac91
7 changed files with 141 additions and 116 deletions

View File

@ -46,36 +46,36 @@ type Interface interface {
// PodInterface has methods to work with Pod resources. // PodInterface has methods to work with Pod resources.
type PodInterface interface { type PodInterface interface {
ListPods(selector labels.Selector) (api.PodList, error) ListPods(selector labels.Selector) (*api.PodList, error)
GetPod(id string) (api.Pod, error) GetPod(id string) (*api.Pod, error)
DeletePod(id string) error DeletePod(id string) error
CreatePod(api.Pod) (api.Pod, error) CreatePod(*api.Pod) (*api.Pod, error)
UpdatePod(api.Pod) (api.Pod, error) UpdatePod(*api.Pod) (*api.Pod, error)
} }
// ReplicationControllerInterface has methods to work with ReplicationController resources. // ReplicationControllerInterface has methods to work with ReplicationController resources.
type ReplicationControllerInterface interface { type ReplicationControllerInterface interface {
ListReplicationControllers(selector labels.Selector) (api.ReplicationControllerList, error) ListReplicationControllers(selector labels.Selector) (*api.ReplicationControllerList, error)
GetReplicationController(id string) (api.ReplicationController, error) GetReplicationController(id string) (*api.ReplicationController, error)
CreateReplicationController(api.ReplicationController) (api.ReplicationController, error) CreateReplicationController(*api.ReplicationController) (*api.ReplicationController, error)
UpdateReplicationController(api.ReplicationController) (api.ReplicationController, error) UpdateReplicationController(*api.ReplicationController) (*api.ReplicationController, error)
DeleteReplicationController(string) error DeleteReplicationController(string) error
WatchReplicationControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) WatchReplicationControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
} }
// ServiceInterface has methods to work with Service resources. // ServiceInterface has methods to work with Service resources.
type ServiceInterface interface { type ServiceInterface interface {
ListServices(selector labels.Selector) (api.ServiceList, error) ListServices(selector labels.Selector) (*api.ServiceList, error)
GetService(id string) (api.Service, error) GetService(id string) (*api.Service, error)
CreateService(api.Service) (api.Service, error) CreateService(*api.Service) (*api.Service, error)
UpdateService(api.Service) (api.Service, error) UpdateService(*api.Service) (*api.Service, error)
DeleteService(string) error DeleteService(string) error
WatchServices(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) WatchServices(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
} }
// EndpointsInterface has methods to work with Endpoints resources // EndpointsInterface has methods to work with Endpoints resources
type EndpointsInterface interface { type EndpointsInterface interface {
ListEndpoints(selector labels.Selector) (api.EndpointsList, error) ListEndpoints(selector labels.Selector) (*api.EndpointsList, error)
WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
} }
@ -85,7 +85,7 @@ type VersionInterface interface {
} }
type MinionInterface interface { type MinionInterface interface {
ListMinions() (api.MinionList, error) ListMinions() (*api.MinionList, error)
} }
// Client is the actual implementation of a Kubernetes client. // Client is the actual implementation of a Kubernetes client.
@ -247,14 +247,16 @@ func (c *RESTClient) doRequest(request *http.Request) ([]byte, error) {
} }
// ListPods takes a selector, and returns the list of pods that match that selector. // ListPods takes a selector, and returns the list of pods that match that selector.
func (c *Client) ListPods(selector labels.Selector) (result api.PodList, err error) { func (c *Client) ListPods(selector labels.Selector) (result *api.PodList, err error) {
err = c.Get().Path("pods").SelectorParam("labels", selector).Do().Into(&result) result = &api.PodList{}
err = c.Get().Path("pods").SelectorParam("labels", selector).Do().Into(result)
return return
} }
// GetPod takes the id of the pod, and returns the corresponding Pod object, and an error if it occurs // GetPod takes the id of the pod, and returns the corresponding Pod object, and an error if it occurs
func (c *Client) GetPod(id string) (result api.Pod, err error) { func (c *Client) GetPod(id string) (result *api.Pod, err error) {
err = c.Get().Path("pods").Path(id).Do().Into(&result) result = &api.Pod{}
err = c.Get().Path("pods").Path(id).Do().Into(result)
return return
} }
@ -264,46 +266,52 @@ func (c *Client) DeletePod(id string) error {
} }
// CreatePod takes the representation of a pod. Returns the server's representation of the pod, and an error, if it occurs. // CreatePod takes the representation of a pod. Returns the server's representation of the pod, and an error, if it occurs.
func (c *Client) CreatePod(pod api.Pod) (result api.Pod, err error) { func (c *Client) CreatePod(pod *api.Pod) (result *api.Pod, err error) {
err = c.Post().Path("pods").Body(pod).Do().Into(&result) result = &api.Pod{}
err = c.Post().Path("pods").Body(pod).Do().Into(result)
return return
} }
// UpdatePod takes the representation of a pod to update. Returns the server's representation of the pod, and an error, if it occurs. // UpdatePod takes the representation of a pod to update. Returns the server's representation of the pod, and an error, if it occurs.
func (c *Client) UpdatePod(pod api.Pod) (result api.Pod, err error) { func (c *Client) UpdatePod(pod *api.Pod) (result *api.Pod, err error) {
result = &api.Pod{}
if pod.ResourceVersion == 0 { if pod.ResourceVersion == 0 {
err = fmt.Errorf("invalid update object, missing resource version: %v", pod) err = fmt.Errorf("invalid update object, missing resource version: %v", pod)
return return
} }
err = c.Put().Path("pods").Path(pod.ID).Body(pod).Do().Into(&result) err = c.Put().Path("pods").Path(pod.ID).Body(pod).Do().Into(result)
return return
} }
// ListReplicationControllers takes a selector, and returns the list of replication controllers that match that selector. // ListReplicationControllers takes a selector, and returns the list of replication controllers that match that selector.
func (c *Client) ListReplicationControllers(selector labels.Selector) (result api.ReplicationControllerList, err error) { func (c *Client) ListReplicationControllers(selector labels.Selector) (result *api.ReplicationControllerList, err error) {
err = c.Get().Path("replicationControllers").SelectorParam("labels", selector).Do().Into(&result) result = &api.ReplicationControllerList{}
err = c.Get().Path("replicationControllers").SelectorParam("labels", selector).Do().Into(result)
return return
} }
// GetReplicationController returns information about a particular replication controller. // GetReplicationController returns information about a particular replication controller.
func (c *Client) GetReplicationController(id string) (result api.ReplicationController, err error) { func (c *Client) GetReplicationController(id string) (result *api.ReplicationController, err error) {
err = c.Get().Path("replicationControllers").Path(id).Do().Into(&result) result = &api.ReplicationController{}
err = c.Get().Path("replicationControllers").Path(id).Do().Into(result)
return return
} }
// CreateReplicationController creates a new replication controller. // CreateReplicationController creates a new replication controller.
func (c *Client) CreateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) { func (c *Client) CreateReplicationController(controller *api.ReplicationController) (result *api.ReplicationController, err error) {
err = c.Post().Path("replicationControllers").Body(controller).Do().Into(&result) result = &api.ReplicationController{}
err = c.Post().Path("replicationControllers").Body(controller).Do().Into(result)
return return
} }
// UpdateReplicationController updates an existing replication controller. // UpdateReplicationController updates an existing replication controller.
func (c *Client) UpdateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) { func (c *Client) UpdateReplicationController(controller *api.ReplicationController) (result *api.ReplicationController, err error) {
result = &api.ReplicationController{}
if controller.ResourceVersion == 0 { if controller.ResourceVersion == 0 {
err = fmt.Errorf("invalid update object, missing resource version: %v", controller) err = fmt.Errorf("invalid update object, missing resource version: %v", controller)
return return
} }
err = c.Put().Path("replicationControllers").Path(controller.ID).Body(controller).Do().Into(&result) err = c.Put().Path("replicationControllers").Path(controller.ID).Body(controller).Do().Into(result)
return return
} }
@ -324,30 +332,34 @@ func (c *Client) WatchReplicationControllers(label, field labels.Selector, resou
} }
// ListServices takes a selector, and returns the list of services that match that selector // ListServices takes a selector, and returns the list of services that match that selector
func (c *Client) ListServices(selector labels.Selector) (result api.ServiceList, err error) { func (c *Client) ListServices(selector labels.Selector) (result *api.ServiceList, err error) {
err = c.Get().Path("services").SelectorParam("labels", selector).Do().Into(&result) result = &api.ServiceList{}
err = c.Get().Path("services").SelectorParam("labels", selector).Do().Into(result)
return return
} }
// GetService returns information about a particular service. // GetService returns information about a particular service.
func (c *Client) GetService(id string) (result api.Service, err error) { func (c *Client) GetService(id string) (result *api.Service, err error) {
err = c.Get().Path("services").Path(id).Do().Into(&result) result = &api.Service{}
err = c.Get().Path("services").Path(id).Do().Into(result)
return return
} }
// CreateService creates a new service. // CreateService creates a new service.
func (c *Client) CreateService(svc api.Service) (result api.Service, err error) { func (c *Client) CreateService(svc *api.Service) (result *api.Service, err error) {
err = c.Post().Path("services").Body(svc).Do().Into(&result) result = &api.Service{}
err = c.Post().Path("services").Body(svc).Do().Into(result)
return return
} }
// UpdateService updates an existing service. // UpdateService updates an existing service.
func (c *Client) UpdateService(svc api.Service) (result api.Service, err error) { func (c *Client) UpdateService(svc *api.Service) (result *api.Service, err error) {
result = &api.Service{}
if svc.ResourceVersion == 0 { if svc.ResourceVersion == 0 {
err = fmt.Errorf("invalid update object, missing resource version: %v", svc) err = fmt.Errorf("invalid update object, missing resource version: %v", svc)
return return
} }
err = c.Put().Path("services").Path(svc.ID).Body(svc).Do().Into(&result) err = c.Put().Path("services").Path(svc.ID).Body(svc).Do().Into(result)
return return
} }
@ -368,8 +380,9 @@ func (c *Client) WatchServices(label, field labels.Selector, resourceVersion uin
} }
// ListEndpoints takes a selector, and returns the list of endpoints that match that selector // ListEndpoints takes a selector, and returns the list of endpoints that match that selector
func (c *Client) ListEndpoints(selector labels.Selector) (result api.EndpointsList, err error) { func (c *Client) ListEndpoints(selector labels.Selector) (result *api.EndpointsList, err error) {
err = c.Get().Path("endpoints").SelectorParam("labels", selector).Do().Into(&result) result = &api.EndpointsList{}
err = c.Get().Path("endpoints").SelectorParam("labels", selector).Do().Into(result)
return return
} }
@ -399,7 +412,8 @@ func (c *Client) ServerVersion() (*version.Info, error) {
} }
// ListMinions lists all the minions in the cluster. // ListMinions lists all the minions in the cluster.
func (c *Client) ListMinions() (minionList api.MinionList, err error) { func (c *Client) ListMinions() (result *api.MinionList, err error) {
err = c.Get().Path("minions").Do().Into(&minionList) result = &api.MinionList{}
err = c.Get().Path("minions").Do().Into(result)
return return
} }

View File

@ -73,7 +73,7 @@ func TestValidatesHostParameter(t *testing.T) {
func TestListEmptyPods(t *testing.T) { func TestListEmptyPods(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods"}, Request: testRequest{Method: "GET", Path: "/pods"},
Response: Response{StatusCode: 200, Body: api.PodList{}}, Response: Response{StatusCode: 200, Body: &api.PodList{}},
} }
podList, err := c.Setup().ListPods(labels.Everything()) podList, err := c.Setup().ListPods(labels.Everything())
c.Validate(t, podList, err) c.Validate(t, podList, err)
@ -83,7 +83,7 @@ func TestListPods(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: "/pods"}, Request: testRequest{Method: "GET", Path: "/pods"},
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: api.PodList{ Body: &api.PodList{
Items: []api.Pod{ Items: []api.Pod{
{ {
CurrentState: api.PodState{ CurrentState: api.PodState{
@ -113,7 +113,7 @@ func TestListPodsLabels(t *testing.T) {
Request: testRequest{Method: "GET", Path: "/pods", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}}, Request: testRequest{Method: "GET", Path: "/pods", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: api.PodList{ Body: &api.PodList{
Items: []api.Pod{ Items: []api.Pod{
{ {
CurrentState: api.PodState{ CurrentState: api.PodState{
@ -140,7 +140,7 @@ func TestGetPod(t *testing.T) {
Request: testRequest{Method: "GET", Path: "/pods/foo"}, Request: testRequest{Method: "GET", Path: "/pods/foo"},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: api.Pod{ Body: &api.Pod{
CurrentState: api.PodState{ CurrentState: api.PodState{
Status: "Foobar", Status: "Foobar",
}, },
@ -165,7 +165,7 @@ func TestDeletePod(t *testing.T) {
} }
func TestCreatePod(t *testing.T) { func TestCreatePod(t *testing.T) {
requestPod := api.Pod{ requestPod := &api.Pod{
CurrentState: api.PodState{ CurrentState: api.PodState{
Status: "Foobar", Status: "Foobar",
}, },
@ -186,7 +186,7 @@ func TestCreatePod(t *testing.T) {
} }
func TestUpdatePod(t *testing.T) { func TestUpdatePod(t *testing.T) {
requestPod := api.Pod{ requestPod := &api.Pod{
JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1}, JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1},
CurrentState: api.PodState{ CurrentState: api.PodState{
Status: "Foobar", Status: "Foobar",
@ -208,7 +208,7 @@ func TestListControllers(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: "/replicationControllers"}, Request: testRequest{Method: "GET", Path: "/replicationControllers"},
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: api.ReplicationControllerList{ Body: &api.ReplicationControllerList{
Items: []api.ReplicationController{ Items: []api.ReplicationController{
{ {
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
@ -234,7 +234,7 @@ func TestGetController(t *testing.T) {
Request: testRequest{Method: "GET", Path: "/replicationControllers/foo"}, Request: testRequest{Method: "GET", Path: "/replicationControllers/foo"},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: api.ReplicationController{ Body: &api.ReplicationController{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 2, Replicas: 2,
@ -251,14 +251,14 @@ func TestGetController(t *testing.T) {
} }
func TestUpdateController(t *testing.T) { func TestUpdateController(t *testing.T) {
requestController := api.ReplicationController{ requestController := &api.ReplicationController{
JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1}, JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1},
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: "/replicationControllers/foo"}, Request: testRequest{Method: "PUT", Path: "/replicationControllers/foo"},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: api.ReplicationController{ Body: &api.ReplicationController{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 2, Replicas: 2,
@ -284,14 +284,14 @@ func TestDeleteController(t *testing.T) {
} }
func TestCreateController(t *testing.T) { func TestCreateController(t *testing.T) {
requestController := api.ReplicationController{ requestController := &api.ReplicationController{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "POST", Path: "/replicationControllers", Body: requestController}, Request: testRequest{Method: "POST", Path: "/replicationControllers", Body: requestController},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: api.ReplicationController{ Body: &api.ReplicationController{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
DesiredState: api.ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 2, Replicas: 2,
@ -307,7 +307,7 @@ func TestCreateController(t *testing.T) {
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
func body(obj interface{}, raw *string) *string { func body(obj runtime.Object, raw *string) *string {
if obj != nil { if obj != nil {
bs, _ := runtime.DefaultCodec.Encode(obj) bs, _ := runtime.DefaultCodec.Encode(obj)
body := string(bs) body := string(bs)
@ -321,13 +321,13 @@ type testRequest struct {
Path string Path string
Header string Header string
Query url.Values Query url.Values
Body interface{} Body runtime.Object
RawBody *string RawBody *string
} }
type Response struct { type Response struct {
StatusCode int StatusCode int
Body interface{} Body runtime.Object
RawBody *string RawBody *string
} }
@ -338,7 +338,6 @@ type testClient struct {
Error bool Error bool
server *httptest.Server server *httptest.Server
handler *util.FakeHandler handler *util.FakeHandler
Target interface{}
// For query args, an optional function to validate the contents // For query args, an optional function to validate the contents
// useful when the contents can change but still be correct. // useful when the contents can change but still be correct.
// Maps from query arg key to validator. // Maps from query arg key to validator.
@ -363,7 +362,23 @@ func (c *testClient) Setup() *testClient {
return c return c
} }
func (c *testClient) Validate(t *testing.T, received interface{}, err error) { func (c *testClient) Validate(t *testing.T, received runtime.Object, err error) {
c.ValidateCommon(t, err)
if c.Response.Body != nil && !reflect.DeepEqual(c.Response.Body, received) {
t.Errorf("bad response for request %#v: expected %s, got %s", c.Request, c.Response.Body, received)
}
}
func (c *testClient) ValidateRaw(t *testing.T, received []byte, err error) {
c.ValidateCommon(t, err)
if c.Response.Body != nil && !reflect.DeepEqual(c.Response.Body, received) {
t.Errorf("bad response for request %#v: expected %s, got %s", c.Request, c.Response.Body, received)
}
}
func (c *testClient) ValidateCommon(t *testing.T, err error) {
defer c.server.Close() defer c.server.Close()
if c.Error { if c.Error {
@ -401,17 +416,13 @@ func (c *testClient) Validate(t *testing.T, received interface{}, err error) {
if expected, received := requestBody, c.handler.RequestBody; expected != nil && *expected != received { if expected, received := requestBody, c.handler.RequestBody; expected != nil && *expected != received {
t.Errorf("bad body for request %#v: expected %s, got %s", c.Request, *expected, received) t.Errorf("bad body for request %#v: expected %s, got %s", c.Request, *expected, received)
} }
if c.Response.Body != nil && !reflect.DeepEqual(c.Response.Body, received) {
t.Errorf("bad response for request %#v: expected %s, got %s", c.Request, c.Response.Body, received)
}
} }
func TestListServices(t *testing.T) { func TestListServices(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: "/services"}, Request: testRequest{Method: "GET", Path: "/services"},
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: api.ServiceList{ Body: &api.ServiceList{
Items: []api.Service{ Items: []api.Service{
{ {
JSONBase: api.JSONBase{ID: "name"}, JSONBase: api.JSONBase{ID: "name"},
@ -435,7 +446,7 @@ func TestListServicesLabels(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: "/services", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}}, Request: testRequest{Method: "GET", Path: "/services", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}},
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: api.ServiceList{ Body: &api.ServiceList{
Items: []api.Service{ Items: []api.Service{
{ {
JSONBase: api.JSONBase{ID: "name"}, JSONBase: api.JSONBase{ID: "name"},
@ -464,7 +475,7 @@ func TestGetService(t *testing.T) {
Response: Response{StatusCode: 200, Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}}, Response: Response{StatusCode: 200, Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}},
} }
response, err := c.Setup().GetService("1") response, err := c.Setup().GetService("1")
c.Validate(t, &response, err) c.Validate(t, response, err)
} }
func TestCreateService(t *testing.T) { func TestCreateService(t *testing.T) {
@ -472,18 +483,18 @@ func TestCreateService(t *testing.T) {
Request: testRequest{Method: "POST", Path: "/services", Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}}, Request: testRequest{Method: "POST", Path: "/services", Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}},
Response: Response{StatusCode: 200, Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}}, Response: Response{StatusCode: 200, Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}},
}).Setup() }).Setup()
response, err := c.Setup().CreateService(api.Service{JSONBase: api.JSONBase{ID: "service-1"}}) response, err := c.Setup().CreateService(&api.Service{JSONBase: api.JSONBase{ID: "service-1"}})
c.Validate(t, &response, err) c.Validate(t, response, err)
} }
func TestUpdateService(t *testing.T) { func TestUpdateService(t *testing.T) {
svc := api.Service{JSONBase: api.JSONBase{ID: "service-1", ResourceVersion: 1}} svc := &api.Service{JSONBase: api.JSONBase{ID: "service-1", ResourceVersion: 1}}
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: &svc}, Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: svc},
Response: Response{StatusCode: 200, Body: &svc}, Response: Response{StatusCode: 200, Body: svc},
} }
response, err := c.Setup().UpdateService(svc) response, err := c.Setup().UpdateService(svc)
c.Validate(t, &response, err) c.Validate(t, response, err)
} }
func TestDeleteService(t *testing.T) { func TestDeleteService(t *testing.T) {
@ -503,8 +514,8 @@ func TestDoRequest(t *testing.T) {
{Client: NewOrDie("localhost", &AuthInfo{"foo", "bar"}), Request: testRequest{Method: "GET", Path: "auth", Header: "Authorization"}, Response: Response{StatusCode: 200}}, {Client: NewOrDie("localhost", &AuthInfo{"foo", "bar"}), Request: testRequest{Method: "GET", Path: "auth", Header: "Authorization"}, Response: Response{StatusCode: 200}},
{Client: &Client{&RESTClient{httpClient: http.DefaultClient}}, Request: testRequest{Method: "GET", Path: "nocertificate"}, Error: true}, {Client: &Client{&RESTClient{httpClient: http.DefaultClient}}, Request: testRequest{Method: "GET", Path: "nocertificate"}, Error: true},
{Request: testRequest{Method: "GET", Path: "error"}, Response: Response{StatusCode: 500}, Error: true}, {Request: testRequest{Method: "GET", Path: "error"}, Response: Response{StatusCode: 500}, Error: true},
{Request: testRequest{Method: "POST", Path: "faildecode"}, Response: Response{StatusCode: 200, RawBody: &invalid}, Target: &struct{}{}}, {Request: testRequest{Method: "POST", Path: "faildecode"}, Response: Response{StatusCode: 200, RawBody: &invalid}},
{Request: testRequest{Method: "GET", Path: "failread"}, Response: Response{StatusCode: 200, RawBody: &invalid}, Target: &struct{}{}}, {Request: testRequest{Method: "GET", Path: "failread"}, Response: Response{StatusCode: 200, RawBody: &invalid}},
} }
for _, c := range testClients { for _, c := range testClients {
client := c.Setup() client := c.Setup()
@ -516,12 +527,12 @@ func TestDoRequest(t *testing.T) {
URL: prefix, URL: prefix,
} }
response, err := client.doRequest(request) response, err := client.doRequest(request)
c.Validate(t, response, err) c.ValidateRaw(t, response, err)
} }
} }
func TestDoRequestAccepted(t *testing.T) { func TestDoRequestAccepted(t *testing.T) {
status := api.Status{Status: api.StatusWorking} status := &api.Status{Status: api.StatusWorking}
expectedBody, _ := runtime.DefaultCodec.Encode(status) expectedBody, _ := runtime.DefaultCodec.Encode(status)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 202, StatusCode: 202,
@ -548,7 +559,7 @@ func TestDoRequestAccepted(t *testing.T) {
t.Errorf("Unexpected kind of error: %#v", err) t.Errorf("Unexpected kind of error: %#v", err)
return return
} }
if !reflect.DeepEqual(se.Status, status) { if !reflect.DeepEqual(&se.Status, status) {
t.Errorf("Unexpected status: %#v", se.Status) t.Errorf("Unexpected status: %#v", se.Status)
} }
if body != nil { if body != nil {
@ -558,7 +569,7 @@ func TestDoRequestAccepted(t *testing.T) {
} }
func TestDoRequestAcceptedSuccess(t *testing.T) { func TestDoRequestAcceptedSuccess(t *testing.T) {
status := api.Status{Status: api.StatusSuccess} status := &api.Status{Status: api.StatusSuccess}
expectedBody, _ := runtime.DefaultCodec.Encode(status) expectedBody, _ := runtime.DefaultCodec.Encode(status)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 202, StatusCode: 202,
@ -583,7 +594,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
if !reflect.DeepEqual(&status, statusOut) { if !reflect.DeepEqual(status, statusOut) {
t.Errorf("Unexpected mis-match. Expected %#v. Saw %#v", status, statusOut) t.Errorf("Unexpected mis-match. Expected %#v. Saw %#v", status, statusOut)
} }
fakeHandler.ValidateRequest(t, "/foo/bar", "GET", nil) fakeHandler.ValidateRequest(t, "/foo/bar", "GET", nil)
@ -622,5 +633,5 @@ func TestListMinions(t *testing.T) {
Response: Response{StatusCode: 200, Body: &api.MinionList{JSONBase: api.JSONBase{ID: "minion-1"}}}, Response: Response{StatusCode: 200, Body: &api.MinionList{JSONBase: api.JSONBase{ID: "minion-1"}}},
} }
response, err := c.Setup().ListMinions() response, err := c.Setup().ListMinions()
c.Validate(t, &response, err) c.Validate(t, response, err)
} }

View File

@ -42,14 +42,14 @@ type Fake struct {
Watch watch.Interface Watch watch.Interface
} }
func (c *Fake) ListPods(selector labels.Selector) (api.PodList, error) { func (c *Fake) ListPods(selector labels.Selector) (*api.PodList, error) {
c.Actions = append(c.Actions, FakeAction{Action: "list-pods"}) c.Actions = append(c.Actions, FakeAction{Action: "list-pods"})
return *runtime.DefaultScheme.CopyOrDie(&c.Pods).(*api.PodList), nil return runtime.DefaultScheme.CopyOrDie(&c.Pods).(*api.PodList), nil
} }
func (c *Fake) GetPod(name string) (api.Pod, error) { func (c *Fake) GetPod(name string) (*api.Pod, error) {
c.Actions = append(c.Actions, FakeAction{Action: "get-pod", Value: name}) c.Actions = append(c.Actions, FakeAction{Action: "get-pod", Value: name})
return api.Pod{}, nil return &api.Pod{}, nil
} }
func (c *Fake) DeletePod(name string) error { func (c *Fake) DeletePod(name string) error {
@ -57,34 +57,34 @@ func (c *Fake) DeletePod(name string) error {
return nil return nil
} }
func (c *Fake) CreatePod(pod api.Pod) (api.Pod, error) { func (c *Fake) CreatePod(pod *api.Pod) (*api.Pod, error) {
c.Actions = append(c.Actions, FakeAction{Action: "create-pod"}) c.Actions = append(c.Actions, FakeAction{Action: "create-pod"})
return api.Pod{}, nil return &api.Pod{}, nil
} }
func (c *Fake) UpdatePod(pod api.Pod) (api.Pod, error) { func (c *Fake) UpdatePod(pod *api.Pod) (*api.Pod, error) {
c.Actions = append(c.Actions, FakeAction{Action: "update-pod", Value: pod.ID}) c.Actions = append(c.Actions, FakeAction{Action: "update-pod", Value: pod.ID})
return api.Pod{}, nil return &api.Pod{}, nil
} }
func (c *Fake) ListReplicationControllers(selector labels.Selector) (api.ReplicationControllerList, error) { func (c *Fake) ListReplicationControllers(selector labels.Selector) (*api.ReplicationControllerList, error) {
c.Actions = append(c.Actions, FakeAction{Action: "list-controllers"}) c.Actions = append(c.Actions, FakeAction{Action: "list-controllers"})
return api.ReplicationControllerList{}, nil return &api.ReplicationControllerList{}, nil
} }
func (c *Fake) GetReplicationController(name string) (api.ReplicationController, error) { func (c *Fake) GetReplicationController(name string) (*api.ReplicationController, error) {
c.Actions = append(c.Actions, FakeAction{Action: "get-controller", Value: name}) c.Actions = append(c.Actions, FakeAction{Action: "get-controller", Value: name})
return *runtime.DefaultScheme.CopyOrDie(&c.Ctrl).(*api.ReplicationController), nil return runtime.DefaultScheme.CopyOrDie(&c.Ctrl).(*api.ReplicationController), nil
} }
func (c *Fake) CreateReplicationController(controller api.ReplicationController) (api.ReplicationController, error) { func (c *Fake) CreateReplicationController(controller *api.ReplicationController) (*api.ReplicationController, error) {
c.Actions = append(c.Actions, FakeAction{Action: "create-controller", Value: controller}) c.Actions = append(c.Actions, FakeAction{Action: "create-controller", Value: controller})
return api.ReplicationController{}, nil return &api.ReplicationController{}, nil
} }
func (c *Fake) UpdateReplicationController(controller api.ReplicationController) (api.ReplicationController, error) { func (c *Fake) UpdateReplicationController(controller *api.ReplicationController) (*api.ReplicationController, error) {
c.Actions = append(c.Actions, FakeAction{Action: "update-controller", Value: controller}) c.Actions = append(c.Actions, FakeAction{Action: "update-controller", Value: controller})
return api.ReplicationController{}, nil return &api.ReplicationController{}, nil
} }
func (c *Fake) DeleteReplicationController(controller string) error { func (c *Fake) DeleteReplicationController(controller string) error {
@ -97,24 +97,24 @@ func (c *Fake) WatchReplicationControllers(label, field labels.Selector, resourc
return c.Watch, nil return c.Watch, nil
} }
func (c *Fake) ListServices(selector labels.Selector) (api.ServiceList, error) { func (c *Fake) ListServices(selector labels.Selector) (*api.ServiceList, error) {
c.Actions = append(c.Actions, FakeAction{Action: "list-services"}) c.Actions = append(c.Actions, FakeAction{Action: "list-services"})
return c.ServiceList, c.Err return &c.ServiceList, c.Err
} }
func (c *Fake) GetService(name string) (api.Service, error) { func (c *Fake) GetService(name string) (*api.Service, error) {
c.Actions = append(c.Actions, FakeAction{Action: "get-service", Value: name}) c.Actions = append(c.Actions, FakeAction{Action: "get-service", Value: name})
return api.Service{}, nil return &api.Service{}, nil
} }
func (c *Fake) CreateService(service api.Service) (api.Service, error) { func (c *Fake) CreateService(service *api.Service) (*api.Service, error) {
c.Actions = append(c.Actions, FakeAction{Action: "create-service", Value: service}) c.Actions = append(c.Actions, FakeAction{Action: "create-service", Value: service})
return api.Service{}, nil return &api.Service{}, nil
} }
func (c *Fake) UpdateService(service api.Service) (api.Service, error) { func (c *Fake) UpdateService(service *api.Service) (*api.Service, error) {
c.Actions = append(c.Actions, FakeAction{Action: "update-service", Value: service}) c.Actions = append(c.Actions, FakeAction{Action: "update-service", Value: service})
return api.Service{}, nil return &api.Service{}, nil
} }
func (c *Fake) DeleteService(service string) error { func (c *Fake) DeleteService(service string) error {
@ -127,9 +127,9 @@ func (c *Fake) WatchServices(label, field labels.Selector, resourceVersion uint6
return c.Watch, c.Err return c.Watch, c.Err
} }
func (c *Fake) ListEndpoints(selector labels.Selector) (api.EndpointsList, error) { func (c *Fake) ListEndpoints(selector labels.Selector) (*api.EndpointsList, error) {
c.Actions = append(c.Actions, FakeAction{Action: "list-endpoints"}) c.Actions = append(c.Actions, FakeAction{Action: "list-endpoints"})
return c.EndpointsList, c.Err return runtime.DefaultScheme.CopyOrDie(&c.EndpointsList).(*api.EndpointsList), nil
} }
func (c *Fake) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) { func (c *Fake) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
@ -143,7 +143,7 @@ func (c *Fake) ServerVersion() (*version.Info, error) {
return &versionInfo, nil return &versionInfo, nil
} }
func (c *Fake) ListMinions() (api.MinionList, error) { func (c *Fake) ListMinions() (*api.MinionList, error) {
c.Actions = append(c.Actions, FakeAction{Action: "list-minions", Value: nil}) c.Actions = append(c.Actions, FakeAction{Action: "list-minions", Value: nil})
return api.MinionList{}, nil return &api.MinionList{}, nil
} }

View File

@ -285,7 +285,7 @@ func TestSetPollPeriod(t *testing.T) {
} }
func TestPolling(t *testing.T) { func TestPolling(t *testing.T) {
objects := []interface{}{ objects := []runtime.Object{
&api.Status{Status: api.StatusWorking, Details: &api.StatusDetails{ID: "1234"}}, &api.Status{Status: api.StatusWorking, Details: &api.StatusDetails{ID: "1234"}},
&api.Status{Status: api.StatusWorking, Details: &api.StatusDetails{ID: "1234"}}, &api.Status{Status: api.StatusWorking, Details: &api.StatusDetails{ID: "1234"}},
&api.Status{Status: api.StatusWorking, Details: &api.StatusDetails{ID: "1234"}}, &api.Status{Status: api.StatusWorking, Details: &api.StatusDetails{ID: "1234"}},
@ -380,7 +380,7 @@ func checkAuth(t *testing.T, expect AuthInfo, r *http.Request) {
func TestWatch(t *testing.T) { func TestWatch(t *testing.T) {
var table = []struct { var table = []struct {
t watch.EventType t watch.EventType
obj interface{} obj runtime.Object
}{ }{
{watch.Added, &api.Pod{JSONBase: api.JSONBase{ID: "first"}}}, {watch.Added, &api.Pod{JSONBase: api.JSONBase{ID: "first"}}},
{watch.Modified, &api.Pod{JSONBase: api.JSONBase{ID: "second"}}}, {watch.Modified, &api.Pod{JSONBase: api.JSONBase{ID: "second"}}},

View File

@ -58,7 +58,7 @@ func (r RealPodControl) createReplica(controllerSpec api.ReplicationController)
if labels != nil { if labels != nil {
labels["replicationController"] = controllerSpec.ID labels["replicationController"] = controllerSpec.ID
} }
pod := api.Pod{ pod := &api.Pod{
DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState, DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState,
Labels: controllerSpec.DesiredState.PodTemplate.Labels, Labels: controllerSpec.DesiredState.PodTemplate.Labels,
} }

View File

@ -174,7 +174,7 @@ func portsFromString(spec string) []api.Port {
// RunController creates a new replication controller named 'name' which creates 'replicas' pods running 'image'. // RunController creates a new replication controller named 'name' which creates 'replicas' pods running 'image'.
func RunController(image, name string, replicas int, client client.Interface, portSpec string, servicePort int) error { func RunController(image, name string, replicas int, client client.Interface, portSpec string, servicePort int) error {
controller := api.ReplicationController{ controller := &api.ReplicationController{
JSONBase: api.JSONBase{ JSONBase: api.JSONBase{
ID: name, ID: name,
}, },
@ -227,8 +227,8 @@ func RunController(image, name string, replicas int, client client.Interface, po
return nil return nil
} }
func createService(name string, port int, client client.Interface) (api.Service, error) { func createService(name string, port int, client client.Interface) (*api.Service, error) {
svc := api.Service{ svc := &api.Service{
JSONBase: api.JSONBase{ID: name}, JSONBase: api.JSONBase{ID: name},
Port: port, Port: port,
Labels: map[string]string{ Labels: map[string]string{

View File

@ -29,8 +29,8 @@ import (
// Watcher is the interface needed to receive changes to services and endpoints. // Watcher is the interface needed to receive changes to services and endpoints.
type Watcher interface { type Watcher interface {
ListServices(label labels.Selector) (api.ServiceList, error) ListServices(label labels.Selector) (*api.ServiceList, error)
ListEndpoints(label labels.Selector) (api.EndpointsList, error) ListEndpoints(label labels.Selector) (*api.EndpointsList, error)
WatchServices(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) WatchServices(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
} }