mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Make client use pointers
This commit is contained in:
parent
0d30a656ef
commit
48ce23ac91
@ -46,36 +46,36 @@ type Interface interface {
|
||||
|
||||
// PodInterface has methods to work with Pod resources.
|
||||
type PodInterface interface {
|
||||
ListPods(selector labels.Selector) (api.PodList, error)
|
||||
GetPod(id string) (api.Pod, error)
|
||||
ListPods(selector labels.Selector) (*api.PodList, error)
|
||||
GetPod(id string) (*api.Pod, error)
|
||||
DeletePod(id string) error
|
||||
CreatePod(api.Pod) (api.Pod, error)
|
||||
UpdatePod(api.Pod) (api.Pod, error)
|
||||
CreatePod(*api.Pod) (*api.Pod, error)
|
||||
UpdatePod(*api.Pod) (*api.Pod, error)
|
||||
}
|
||||
|
||||
// ReplicationControllerInterface has methods to work with ReplicationController resources.
|
||||
type ReplicationControllerInterface interface {
|
||||
ListReplicationControllers(selector labels.Selector) (api.ReplicationControllerList, error)
|
||||
GetReplicationController(id string) (api.ReplicationController, error)
|
||||
CreateReplicationController(api.ReplicationController) (api.ReplicationController, error)
|
||||
UpdateReplicationController(api.ReplicationController) (api.ReplicationController, error)
|
||||
ListReplicationControllers(selector labels.Selector) (*api.ReplicationControllerList, error)
|
||||
GetReplicationController(id string) (*api.ReplicationController, error)
|
||||
CreateReplicationController(*api.ReplicationController) (*api.ReplicationController, error)
|
||||
UpdateReplicationController(*api.ReplicationController) (*api.ReplicationController, error)
|
||||
DeleteReplicationController(string) error
|
||||
WatchReplicationControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
|
||||
}
|
||||
|
||||
// ServiceInterface has methods to work with Service resources.
|
||||
type ServiceInterface interface {
|
||||
ListServices(selector labels.Selector) (api.ServiceList, error)
|
||||
GetService(id string) (api.Service, error)
|
||||
CreateService(api.Service) (api.Service, error)
|
||||
UpdateService(api.Service) (api.Service, error)
|
||||
ListServices(selector labels.Selector) (*api.ServiceList, error)
|
||||
GetService(id string) (*api.Service, error)
|
||||
CreateService(*api.Service) (*api.Service, error)
|
||||
UpdateService(*api.Service) (*api.Service, error)
|
||||
DeleteService(string) error
|
||||
WatchServices(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
|
||||
}
|
||||
|
||||
// EndpointsInterface has methods to work with Endpoints resources
|
||||
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)
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ type VersionInterface interface {
|
||||
}
|
||||
|
||||
type MinionInterface interface {
|
||||
ListMinions() (api.MinionList, error)
|
||||
ListMinions() (*api.MinionList, error)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (c *Client) ListPods(selector labels.Selector) (result api.PodList, err error) {
|
||||
err = c.Get().Path("pods").SelectorParam("labels", selector).Do().Into(&result)
|
||||
func (c *Client) ListPods(selector labels.Selector) (result *api.PodList, err error) {
|
||||
result = &api.PodList{}
|
||||
err = c.Get().Path("pods").SelectorParam("labels", selector).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// 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) {
|
||||
err = c.Get().Path("pods").Path(id).Do().Into(&result)
|
||||
func (c *Client) GetPod(id string) (result *api.Pod, err error) {
|
||||
result = &api.Pod{}
|
||||
err = c.Get().Path("pods").Path(id).Do().Into(result)
|
||||
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.
|
||||
func (c *Client) CreatePod(pod api.Pod) (result api.Pod, err error) {
|
||||
err = c.Post().Path("pods").Body(pod).Do().Into(&result)
|
||||
func (c *Client) CreatePod(pod *api.Pod) (result *api.Pod, err error) {
|
||||
result = &api.Pod{}
|
||||
err = c.Post().Path("pods").Body(pod).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// 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 {
|
||||
err = fmt.Errorf("invalid update object, missing resource version: %v", pod)
|
||||
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
|
||||
}
|
||||
|
||||
// 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) {
|
||||
err = c.Get().Path("replicationControllers").SelectorParam("labels", selector).Do().Into(&result)
|
||||
func (c *Client) ListReplicationControllers(selector labels.Selector) (result *api.ReplicationControllerList, err error) {
|
||||
result = &api.ReplicationControllerList{}
|
||||
err = c.Get().Path("replicationControllers").SelectorParam("labels", selector).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// GetReplicationController returns information about a particular replication controller.
|
||||
func (c *Client) GetReplicationController(id string) (result api.ReplicationController, err error) {
|
||||
err = c.Get().Path("replicationControllers").Path(id).Do().Into(&result)
|
||||
func (c *Client) GetReplicationController(id string) (result *api.ReplicationController, err error) {
|
||||
result = &api.ReplicationController{}
|
||||
err = c.Get().Path("replicationControllers").Path(id).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// CreateReplicationController creates a new replication controller.
|
||||
func (c *Client) CreateReplicationController(controller api.ReplicationController) (result api.ReplicationController, err error) {
|
||||
err = c.Post().Path("replicationControllers").Body(controller).Do().Into(&result)
|
||||
func (c *Client) CreateReplicationController(controller *api.ReplicationController) (result *api.ReplicationController, err error) {
|
||||
result = &api.ReplicationController{}
|
||||
err = c.Post().Path("replicationControllers").Body(controller).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// 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 {
|
||||
err = fmt.Errorf("invalid update object, missing resource version: %v", controller)
|
||||
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
|
||||
}
|
||||
|
||||
@ -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
|
||||
func (c *Client) ListServices(selector labels.Selector) (result api.ServiceList, err error) {
|
||||
err = c.Get().Path("services").SelectorParam("labels", selector).Do().Into(&result)
|
||||
func (c *Client) ListServices(selector labels.Selector) (result *api.ServiceList, err error) {
|
||||
result = &api.ServiceList{}
|
||||
err = c.Get().Path("services").SelectorParam("labels", selector).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// GetService returns information about a particular service.
|
||||
func (c *Client) GetService(id string) (result api.Service, err error) {
|
||||
err = c.Get().Path("services").Path(id).Do().Into(&result)
|
||||
func (c *Client) GetService(id string) (result *api.Service, err error) {
|
||||
result = &api.Service{}
|
||||
err = c.Get().Path("services").Path(id).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// CreateService creates a new service.
|
||||
func (c *Client) CreateService(svc api.Service) (result api.Service, err error) {
|
||||
err = c.Post().Path("services").Body(svc).Do().Into(&result)
|
||||
func (c *Client) CreateService(svc *api.Service) (result *api.Service, err error) {
|
||||
result = &api.Service{}
|
||||
err = c.Post().Path("services").Body(svc).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// 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 {
|
||||
err = fmt.Errorf("invalid update object, missing resource version: %v", svc)
|
||||
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
|
||||
}
|
||||
|
||||
@ -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
|
||||
func (c *Client) ListEndpoints(selector labels.Selector) (result api.EndpointsList, err error) {
|
||||
err = c.Get().Path("endpoints").SelectorParam("labels", selector).Do().Into(&result)
|
||||
func (c *Client) ListEndpoints(selector labels.Selector) (result *api.EndpointsList, err error) {
|
||||
result = &api.EndpointsList{}
|
||||
err = c.Get().Path("endpoints").SelectorParam("labels", selector).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
@ -399,7 +412,8 @@ func (c *Client) ServerVersion() (*version.Info, error) {
|
||||
}
|
||||
|
||||
// ListMinions lists all the minions in the cluster.
|
||||
func (c *Client) ListMinions() (minionList api.MinionList, err error) {
|
||||
err = c.Get().Path("minions").Do().Into(&minionList)
|
||||
func (c *Client) ListMinions() (result *api.MinionList, err error) {
|
||||
result = &api.MinionList{}
|
||||
err = c.Get().Path("minions").Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func TestValidatesHostParameter(t *testing.T) {
|
||||
func TestListEmptyPods(t *testing.T) {
|
||||
c := &testClient{
|
||||
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())
|
||||
c.Validate(t, podList, err)
|
||||
@ -83,7 +83,7 @@ func TestListPods(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/pods"},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: api.PodList{
|
||||
Body: &api.PodList{
|
||||
Items: []api.Pod{
|
||||
{
|
||||
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"}}},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: api.PodList{
|
||||
Body: &api.PodList{
|
||||
Items: []api.Pod{
|
||||
{
|
||||
CurrentState: api.PodState{
|
||||
@ -140,7 +140,7 @@ func TestGetPod(t *testing.T) {
|
||||
Request: testRequest{Method: "GET", Path: "/pods/foo"},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: api.Pod{
|
||||
Body: &api.Pod{
|
||||
CurrentState: api.PodState{
|
||||
Status: "Foobar",
|
||||
},
|
||||
@ -165,7 +165,7 @@ func TestDeletePod(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreatePod(t *testing.T) {
|
||||
requestPod := api.Pod{
|
||||
requestPod := &api.Pod{
|
||||
CurrentState: api.PodState{
|
||||
Status: "Foobar",
|
||||
},
|
||||
@ -186,7 +186,7 @@ func TestCreatePod(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdatePod(t *testing.T) {
|
||||
requestPod := api.Pod{
|
||||
requestPod := &api.Pod{
|
||||
JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1},
|
||||
CurrentState: api.PodState{
|
||||
Status: "Foobar",
|
||||
@ -208,7 +208,7 @@ func TestListControllers(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/replicationControllers"},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: api.ReplicationControllerList{
|
||||
Body: &api.ReplicationControllerList{
|
||||
Items: []api.ReplicationController{
|
||||
{
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
@ -234,7 +234,7 @@ func TestGetController(t *testing.T) {
|
||||
Request: testRequest{Method: "GET", Path: "/replicationControllers/foo"},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: api.ReplicationController{
|
||||
Body: &api.ReplicationController{
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
DesiredState: api.ReplicationControllerState{
|
||||
Replicas: 2,
|
||||
@ -251,14 +251,14 @@ func TestGetController(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateController(t *testing.T) {
|
||||
requestController := api.ReplicationController{
|
||||
requestController := &api.ReplicationController{
|
||||
JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: "/replicationControllers/foo"},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: api.ReplicationController{
|
||||
Body: &api.ReplicationController{
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
DesiredState: api.ReplicationControllerState{
|
||||
Replicas: 2,
|
||||
@ -284,14 +284,14 @@ func TestDeleteController(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateController(t *testing.T) {
|
||||
requestController := api.ReplicationController{
|
||||
requestController := &api.ReplicationController{
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "POST", Path: "/replicationControllers", Body: requestController},
|
||||
Response: Response{
|
||||
StatusCode: 200,
|
||||
Body: api.ReplicationController{
|
||||
Body: &api.ReplicationController{
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
DesiredState: api.ReplicationControllerState{
|
||||
Replicas: 2,
|
||||
@ -307,7 +307,7 @@ func TestCreateController(t *testing.T) {
|
||||
c.Validate(t, receivedController, err)
|
||||
}
|
||||
|
||||
func body(obj interface{}, raw *string) *string {
|
||||
func body(obj runtime.Object, raw *string) *string {
|
||||
if obj != nil {
|
||||
bs, _ := runtime.DefaultCodec.Encode(obj)
|
||||
body := string(bs)
|
||||
@ -321,13 +321,13 @@ type testRequest struct {
|
||||
Path string
|
||||
Header string
|
||||
Query url.Values
|
||||
Body interface{}
|
||||
Body runtime.Object
|
||||
RawBody *string
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
StatusCode int
|
||||
Body interface{}
|
||||
Body runtime.Object
|
||||
RawBody *string
|
||||
}
|
||||
|
||||
@ -338,7 +338,6 @@ type testClient struct {
|
||||
Error bool
|
||||
server *httptest.Server
|
||||
handler *util.FakeHandler
|
||||
Target interface{}
|
||||
// For query args, an optional function to validate the contents
|
||||
// useful when the contents can change but still be correct.
|
||||
// Maps from query arg key to validator.
|
||||
@ -363,7 +362,23 @@ func (c *testClient) Setup() *testClient {
|
||||
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()
|
||||
|
||||
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 {
|
||||
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) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/services"},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: api.ServiceList{
|
||||
Body: &api.ServiceList{
|
||||
Items: []api.Service{
|
||||
{
|
||||
JSONBase: api.JSONBase{ID: "name"},
|
||||
@ -435,7 +446,7 @@ func TestListServicesLabels(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "GET", Path: "/services", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}},
|
||||
Response: Response{StatusCode: 200,
|
||||
Body: api.ServiceList{
|
||||
Body: &api.ServiceList{
|
||||
Items: []api.Service{
|
||||
{
|
||||
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, err := c.Setup().GetService("1")
|
||||
c.Validate(t, &response, err)
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
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"}}},
|
||||
Response: Response{StatusCode: 200, Body: &api.Service{JSONBase: api.JSONBase{ID: "service-1"}}},
|
||||
}).Setup()
|
||||
response, err := c.Setup().CreateService(api.Service{JSONBase: api.JSONBase{ID: "service-1"}})
|
||||
c.Validate(t, &response, err)
|
||||
response, err := c.Setup().CreateService(&api.Service{JSONBase: api.JSONBase{ID: "service-1"}})
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
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{
|
||||
Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: &svc},
|
||||
Response: Response{StatusCode: 200, Body: &svc},
|
||||
Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: svc},
|
||||
Response: Response{StatusCode: 200, Body: svc},
|
||||
}
|
||||
response, err := c.Setup().UpdateService(svc)
|
||||
c.Validate(t, &response, err)
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
||||
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: &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: "POST", Path: "faildecode"}, Response: Response{StatusCode: 200, RawBody: &invalid}, Target: &struct{}{}},
|
||||
{Request: testRequest{Method: "GET", Path: "failread"}, 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}},
|
||||
}
|
||||
for _, c := range testClients {
|
||||
client := c.Setup()
|
||||
@ -516,12 +527,12 @@ func TestDoRequest(t *testing.T) {
|
||||
URL: prefix,
|
||||
}
|
||||
response, err := client.doRequest(request)
|
||||
c.Validate(t, response, err)
|
||||
c.ValidateRaw(t, response, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoRequestAccepted(t *testing.T) {
|
||||
status := api.Status{Status: api.StatusWorking}
|
||||
status := &api.Status{Status: api.StatusWorking}
|
||||
expectedBody, _ := runtime.DefaultCodec.Encode(status)
|
||||
fakeHandler := util.FakeHandler{
|
||||
StatusCode: 202,
|
||||
@ -548,7 +559,7 @@ func TestDoRequestAccepted(t *testing.T) {
|
||||
t.Errorf("Unexpected kind of error: %#v", err)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(se.Status, status) {
|
||||
if !reflect.DeepEqual(&se.Status, status) {
|
||||
t.Errorf("Unexpected status: %#v", se.Status)
|
||||
}
|
||||
if body != nil {
|
||||
@ -558,7 +569,7 @@ func TestDoRequestAccepted(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)
|
||||
fakeHandler := util.FakeHandler{
|
||||
StatusCode: 202,
|
||||
@ -583,7 +594,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) {
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
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, err := c.Setup().ListMinions()
|
||||
c.Validate(t, &response, err)
|
||||
c.Validate(t, response, err)
|
||||
}
|
||||
|
@ -42,14 +42,14 @@ type Fake struct {
|
||||
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"})
|
||||
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})
|
||||
return api.Pod{}, nil
|
||||
return &api.Pod{}, nil
|
||||
}
|
||||
|
||||
func (c *Fake) DeletePod(name string) error {
|
||||
@ -57,34 +57,34 @@ func (c *Fake) DeletePod(name string) error {
|
||||
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"})
|
||||
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})
|
||||
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"})
|
||||
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})
|
||||
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})
|
||||
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})
|
||||
return api.ReplicationController{}, nil
|
||||
return &api.ReplicationController{}, nil
|
||||
}
|
||||
|
||||
func (c *Fake) DeleteReplicationController(controller string) error {
|
||||
@ -97,24 +97,24 @@ func (c *Fake) WatchReplicationControllers(label, field labels.Selector, resourc
|
||||
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"})
|
||||
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})
|
||||
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})
|
||||
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})
|
||||
return api.Service{}, nil
|
||||
return &api.Service{}, nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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"})
|
||||
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) {
|
||||
@ -143,7 +143,7 @@ func (c *Fake) ServerVersion() (*version.Info, error) {
|
||||
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})
|
||||
return api.MinionList{}, nil
|
||||
return &api.MinionList{}, nil
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ func TestSetPollPeriod(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"}},
|
||||
@ -380,7 +380,7 @@ func checkAuth(t *testing.T, expect AuthInfo, r *http.Request) {
|
||||
func TestWatch(t *testing.T) {
|
||||
var table = []struct {
|
||||
t watch.EventType
|
||||
obj interface{}
|
||||
obj runtime.Object
|
||||
}{
|
||||
{watch.Added, &api.Pod{JSONBase: api.JSONBase{ID: "first"}}},
|
||||
{watch.Modified, &api.Pod{JSONBase: api.JSONBase{ID: "second"}}},
|
||||
|
@ -58,7 +58,7 @@ func (r RealPodControl) createReplica(controllerSpec api.ReplicationController)
|
||||
if labels != nil {
|
||||
labels["replicationController"] = controllerSpec.ID
|
||||
}
|
||||
pod := api.Pod{
|
||||
pod := &api.Pod{
|
||||
DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState,
|
||||
Labels: controllerSpec.DesiredState.PodTemplate.Labels,
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ func portsFromString(spec string) []api.Port {
|
||||
|
||||
// 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 {
|
||||
controller := api.ReplicationController{
|
||||
controller := &api.ReplicationController{
|
||||
JSONBase: api.JSONBase{
|
||||
ID: name,
|
||||
},
|
||||
@ -227,8 +227,8 @@ func RunController(image, name string, replicas int, client client.Interface, po
|
||||
return nil
|
||||
}
|
||||
|
||||
func createService(name string, port int, client client.Interface) (api.Service, error) {
|
||||
svc := api.Service{
|
||||
func createService(name string, port int, client client.Interface) (*api.Service, error) {
|
||||
svc := &api.Service{
|
||||
JSONBase: api.JSONBase{ID: name},
|
||||
Port: port,
|
||||
Labels: map[string]string{
|
||||
|
@ -29,8 +29,8 @@ import (
|
||||
|
||||
// Watcher is the interface needed to receive changes to services and endpoints.
|
||||
type Watcher interface {
|
||||
ListServices(label labels.Selector) (api.ServiceList, error)
|
||||
ListEndpoints(label labels.Selector) (api.EndpointsList, error)
|
||||
ListServices(label labels.Selector) (*api.ServiceList, error)
|
||||
ListEndpoints(label labels.Selector) (*api.EndpointsList, error)
|
||||
WatchServices(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
|
||||
WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user