2014-08-05 23:19:32 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
2014-08-21 21:14:06 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
2014-08-05 23:19:32 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
|
|
|
)
|
|
|
|
|
2014-08-15 21:15:03 +00:00
|
|
|
type FakeAction struct {
|
|
|
|
Action string
|
|
|
|
Value interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fake implements Interface. Meant to be embedded into a struct to get a default
|
2014-08-05 23:19:32 +00:00
|
|
|
// implementation. This makes faking out just the method you want to test easier.
|
2014-08-15 21:15:03 +00:00
|
|
|
type Fake struct {
|
|
|
|
// Fake by default keeps a simple list of the methods that have been called.
|
2014-08-29 02:31:41 +00:00
|
|
|
Actions []FakeAction
|
|
|
|
Pods api.PodList
|
|
|
|
Ctrl api.ReplicationController
|
|
|
|
ServiceList api.ServiceList
|
|
|
|
EndpointsList api.EndpointsList
|
2014-09-17 22:26:01 +00:00
|
|
|
Minions api.MinionList
|
2014-10-11 00:46:38 +00:00
|
|
|
Events api.EventList
|
2014-08-29 02:31:41 +00:00
|
|
|
Err error
|
|
|
|
Watch watch.Interface
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) ListPods(ctx api.Context, selector labels.Selector) (*api.PodList, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "list-pods"})
|
2014-09-11 17:02:53 +00:00
|
|
|
return api.Scheme.CopyOrDie(&c.Pods).(*api.PodList), nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) GetPod(ctx api.Context, name string) (*api.Pod, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "get-pod", Value: name})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &api.Pod{}, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) DeletePod(ctx api.Context, name string) error {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "delete-pod", Value: name})
|
2014-08-05 23:19:32 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) CreatePod(ctx api.Context, pod *api.Pod) (*api.Pod, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "create-pod"})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &api.Pod{}, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) UpdatePod(ctx api.Context, pod *api.Pod) (*api.Pod, error) {
|
2014-10-22 17:02:02 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "update-pod", Value: pod.Name})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &api.Pod{}, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) ListReplicationControllers(ctx api.Context, selector labels.Selector) (*api.ReplicationControllerList, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "list-controllers"})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &api.ReplicationControllerList{}, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) GetReplicationController(ctx api.Context, name string) (*api.ReplicationController, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "get-controller", Value: name})
|
2014-09-11 17:02:53 +00:00
|
|
|
return api.Scheme.CopyOrDie(&c.Ctrl).(*api.ReplicationController), nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) CreateReplicationController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "create-controller", Value: controller})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &api.ReplicationController{}, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) UpdateReplicationController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "update-controller", Value: controller})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &api.ReplicationController{}, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) DeleteReplicationController(ctx api.Context, controller string) error {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "delete-controller", Value: controller})
|
2014-08-05 23:19:32 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-10-07 20:51:28 +00:00
|
|
|
func (c *Fake) WatchReplicationControllers(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
|
2014-08-15 21:14:22 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "watch-controllers", Value: resourceVersion})
|
|
|
|
return c.Watch, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) ListServices(ctx api.Context, selector labels.Selector) (*api.ServiceList, error) {
|
2014-08-29 02:31:41 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "list-services"})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &c.ServiceList, c.Err
|
2014-08-29 02:31:41 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) GetService(ctx api.Context, name string) (*api.Service, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "get-service", Value: name})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &api.Service{}, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) CreateService(ctx api.Context, service *api.Service) (*api.Service, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "create-service", Value: service})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &api.Service{}, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) UpdateService(ctx api.Context, service *api.Service) (*api.Service, error) {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "update-service", Value: service})
|
2014-09-08 01:31:11 +00:00
|
|
|
return &api.Service{}, nil
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) DeleteService(ctx api.Context, service string) error {
|
2014-08-15 21:15:03 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "delete-service", Value: service})
|
2014-08-05 23:19:32 +00:00
|
|
|
return nil
|
|
|
|
}
|
2014-08-21 21:14:06 +00:00
|
|
|
|
2014-10-07 20:51:28 +00:00
|
|
|
func (c *Fake) WatchServices(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
|
2014-08-15 21:14:22 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "watch-services", Value: resourceVersion})
|
2014-08-29 02:31:41 +00:00
|
|
|
return c.Watch, c.Err
|
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) ListEndpoints(ctx api.Context, selector labels.Selector) (*api.EndpointsList, error) {
|
2014-08-29 02:31:41 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "list-endpoints"})
|
2014-09-11 17:02:53 +00:00
|
|
|
return api.Scheme.CopyOrDie(&c.EndpointsList).(*api.EndpointsList), c.Err
|
2014-08-15 21:14:22 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 16:51:36 +00:00
|
|
|
func (c *Fake) GetEndpoints(ctx api.Context, name string) (*api.Endpoints, error) {
|
2014-09-22 20:18:55 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "get-endpoints"})
|
|
|
|
return &api.Endpoints{}, nil
|
|
|
|
}
|
|
|
|
|
2014-10-07 20:51:28 +00:00
|
|
|
func (c *Fake) WatchEndpoints(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
|
2014-08-15 21:14:22 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "watch-endpoints", Value: resourceVersion})
|
2014-08-29 02:31:41 +00:00
|
|
|
return c.Watch, c.Err
|
2014-08-15 21:14:22 +00:00
|
|
|
}
|
|
|
|
|
2014-08-21 21:14:06 +00:00
|
|
|
func (c *Fake) ServerVersion() (*version.Info, error) {
|
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "get-version", Value: nil})
|
|
|
|
versionInfo := version.Get()
|
|
|
|
return &versionInfo, nil
|
|
|
|
}
|
2014-08-27 21:07:22 +00:00
|
|
|
|
2014-09-08 01:31:11 +00:00
|
|
|
func (c *Fake) ListMinions() (*api.MinionList, error) {
|
2014-08-27 21:07:22 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "list-minions", Value: nil})
|
2014-09-17 22:26:01 +00:00
|
|
|
return &c.Minions, nil
|
2014-10-22 01:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Fake) CreateMinion(minion *api.Minion) (*api.Minion, error) {
|
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "create-minion", Value: minion})
|
|
|
|
return &api.Minion{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Fake) DeleteMinion(id string) error {
|
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "delete-minion", Value: id})
|
|
|
|
return nil
|
2014-08-27 21:07:22 +00:00
|
|
|
}
|
2014-10-11 00:46:38 +00:00
|
|
|
|
|
|
|
// CreateEvent makes a new event. Returns the copy of the event the server returns, or an error.
|
|
|
|
func (c *Fake) CreateEvent(event *api.Event) (*api.Event, error) {
|
2014-10-22 17:02:02 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "get-event", Value: event.Name})
|
2014-10-11 00:46:38 +00:00
|
|
|
return &api.Event{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListEvents returns a list of events matching the selectors.
|
|
|
|
func (c *Fake) ListEvents(label, field labels.Selector) (*api.EventList, error) {
|
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "list-events"})
|
|
|
|
return &c.Events, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetEvent returns the given event, or an error.
|
|
|
|
func (c *Fake) GetEvent(id string) (*api.Event, error) {
|
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "get-event", Value: id})
|
|
|
|
return &api.Event{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// WatchEvents starts watching for events matching the given selectors.
|
|
|
|
func (c *Fake) WatchEvents(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
|
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "watch-events", Value: resourceVersion})
|
|
|
|
return c.Watch, c.Err
|
|
|
|
}
|