diff --git a/cmd/apiserver/apiserver.go b/cmd/apiserver/apiserver.go index cbd03f9002..480e9b73ca 100644 --- a/cmd/apiserver/apiserver.go +++ b/cmd/apiserver/apiserver.go @@ -71,6 +71,10 @@ func main() { verflag.PrintAndExitIfRequested() verifyMinionFlags() + if len(etcdServerList) == 0 { + glog.Fatalf("-etcd_servers flag is required.") + } + var cloud cloudprovider.Interface switch *cloudProvider { case "gce": @@ -94,26 +98,16 @@ func main() { client := client.New("http://"+net.JoinHostPort(*address, strconv.Itoa(int(*port))), nil) - var m *master.Master - if len(etcdServerList) > 0 { - m = master.New(&master.Config{ - Client: client, - Cloud: cloud, - EtcdServers: etcdServerList, - HealthCheckMinions: *healthCheckMinions, - Minions: machineList, - MinionCacheTTL: *minionCacheTTL, - MinionRegexp: *minionRegexp, - PodInfoGetter: podInfoGetter, - }) - } else { - m = master.NewMemoryServer(&master.Config{ - Client: client, - Cloud: cloud, - Minions: machineList, - PodInfoGetter: podInfoGetter, - }) - } + m := master.New(&master.Config{ + Client: client, + Cloud: cloud, + EtcdServers: etcdServerList, + HealthCheckMinions: *healthCheckMinions, + Minions: machineList, + MinionCacheTTL: *minionCacheTTL, + MinionRegexp: *minionRegexp, + PodInfoGetter: podInfoGetter, + }) storage, codec := m.API_v1beta1() s := &http.Server{ diff --git a/pkg/master/master.go b/pkg/master/master.go index 917ec11408..341855072b 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -28,7 +28,6 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/controller" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/endpoint" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/etcd" - "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/memory" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/service" @@ -61,19 +60,6 @@ type Master struct { client *client.Client } -// NewMemoryServer returns a new instance of Master backed with memory (not etcd). -func NewMemoryServer(c *Config) *Master { - m := &Master{ - podRegistry: memory.NewRegistry(), - controllerRegistry: memory.NewRegistry(), - serviceRegistry: memory.NewRegistry(), - minionRegistry: minion.NewRegistry(c.Minions), - client: c.Client, - } - m.init(c.Cloud, c.PodInfoGetter) - return m -} - // New returns a new instance of Master connected to the given etcdServer. func New(c *Config) *Master { etcdClient := goetcd.NewClient(c.EtcdServers) diff --git a/pkg/registry/memory/memory.go b/pkg/registry/memory/memory.go deleted file mode 100644 index d74b037858..0000000000 --- a/pkg/registry/memory/memory.go +++ /dev/null @@ -1,191 +0,0 @@ -/* -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 memory - -import ( - "errors" - - "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" - "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" - "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" -) - -// An implementation of PodRegistry and ControllerRegistry that is backed -// by memory. Mainly used for testing. -type Registry struct { - podData map[string]api.Pod - controllerData map[string]api.ReplicationController - serviceData map[string]api.Service -} - -// NewRegistry returns a new Registry. -func NewRegistry() *Registry { - return &Registry{ - podData: map[string]api.Pod{}, - controllerData: map[string]api.ReplicationController{}, - serviceData: map[string]api.Service{}, - } -} - -// CreateController registers the given replication controller. -func (r *Registry) CreateController(controller api.ReplicationController) error { - r.controllerData[controller.ID] = controller - return nil -} - -// CreatePod registers the given pod. -func (r *Registry) CreatePod(machine string, pod api.Pod) error { - r.podData[pod.ID] = pod - return nil -} - -// CreateService registers the given service. -func (r *Registry) CreateService(svc api.Service) error { - r.serviceData[svc.ID] = svc - return nil -} - -// DeleteController deletes the named replication controller from the -// registry. -func (r *Registry) DeleteController(controllerID string) error { - if _, ok := r.controllerData[controllerID]; !ok { - return apiserver.NewNotFoundErr("replicationController", controllerID) - } - delete(r.controllerData, controllerID) - return nil -} - -// DeletePod deletes the named pod from the registry. -func (r *Registry) DeletePod(podID string) error { - if _, ok := r.podData[podID]; !ok { - return apiserver.NewNotFoundErr("pod", podID) - } - delete(r.podData, podID) - return nil -} - -// DeleteService deletes the named service from the registry. -// It returns an error if the service is not found in the registry. -func (r *Registry) DeleteService(name string) error { - if _, ok := r.serviceData[name]; !ok { - return apiserver.NewNotFoundErr("service", name) - } - delete(r.serviceData, name) - return nil -} - -// GetController returns an *api.ReplicationController for the name controller. -// It returns an error if the controller is not found in the registry. -func (r *Registry) GetController(controllerID string) (*api.ReplicationController, error) { - controller, found := r.controllerData[controllerID] - if found { - return &controller, nil - } else { - return nil, apiserver.NewNotFoundErr("replicationController", controllerID) - } -} - -// GetPod returns an *api.Pod for the named pod. -// It returns an error if the pod is not found in the registry. -func (r *Registry) GetPod(podID string) (*api.Pod, error) { - pod, found := r.podData[podID] - if found { - return &pod, nil - } else { - return nil, apiserver.NewNotFoundErr("pod", podID) - } -} - -// GetService returns an *api.Service for the named service. -// It returns an error if the service is not found in the registry. -func (r *Registry) GetService(name string) (*api.Service, error) { - svc, found := r.serviceData[name] - if !found { - return nil, apiserver.NewNotFoundErr("service", name) - } - return &svc, nil -} - -// ListControllers returns all registered replication controllers. -func (r *Registry) ListControllers() ([]api.ReplicationController, error) { - result := []api.ReplicationController{} - for _, value := range r.controllerData { - result = append(result, value) - } - return result, nil -} - -// ListPods returns all registered pods for the given selector. -func (r *Registry) ListPods(selector labels.Selector) ([]api.Pod, error) { - result := []api.Pod{} - for _, value := range r.podData { - if selector.Matches(labels.Set(value.Labels)) { - result = append(result, value) - } - } - return result, nil -} - -// ListServices returns all registered services. -func (r *Registry) ListServices() (api.ServiceList, error) { - var list []api.Service - for _, value := range r.serviceData { - list = append(list, value) - } - return api.ServiceList{Items: list}, nil -} - -// UpdateController updates the given controller in the registry. -// It returns an error if the controller is not found in the registry. -func (r *Registry) UpdateController(controller api.ReplicationController) error { - if _, ok := r.controllerData[controller.ID]; !ok { - return apiserver.NewNotFoundErr("replicationController", controller.ID) - } - r.controllerData[controller.ID] = controller - return nil -} - -// UpdateEndpoints always returns nil. -func (r *Registry) UpdateEndpoints(e api.Endpoints) error { - return nil -} - -// UpdatePod updates the given pod in the registry. -// It returns an error if the pod is not found in the registry. -func (r *Registry) UpdatePod(pod api.Pod) error { - if _, ok := r.podData[pod.ID]; !ok { - return apiserver.NewNotFoundErr("pod", pod.ID) - } - r.podData[pod.ID] = pod - return nil -} - -// UpdateService updates the given service in the registry. -// It returns an error if the service is not found in the registry. -func (r *Registry) UpdateService(svc api.Service) error { - if _, ok := r.serviceData[svc.ID]; !ok { - return apiserver.NewNotFoundErr("service", svc.ID) - } - return r.CreateService(svc) -} - -// WatchControllers always returns an error. -// It is not implemented. -func (r *Registry) WatchControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) { - return nil, errors.New("unimplemented") -} diff --git a/pkg/registry/memory/memory_test.go b/pkg/registry/memory/memory_test.go deleted file mode 100644 index e5f7c09356..0000000000 --- a/pkg/registry/memory/memory_test.go +++ /dev/null @@ -1,382 +0,0 @@ -/* -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 memory - -import ( - "testing" - - "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" - "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" -) - -func TestListPodsEmpty(t *testing.T) { - registry := NewRegistry() - pods, err := registry.ListPods(labels.Everything()) - if err != nil { - t.Errorf("unexpected error: %v", err) - } - if len(pods) != 0 { - t.Errorf("Unexpected pod list: %#v", pods) - } -} - -func TestMemoryListPods(t *testing.T) { - registry := NewRegistry() - registry.CreatePod("machine", api.Pod{JSONBase: api.JSONBase{ID: "foo"}}) - pods, err := registry.ListPods(labels.Everything()) - if err != nil { - t.Errorf("unexpected error: %v", err) - } - if len(pods) != 1 || pods[0].ID != "foo" { - t.Errorf("Unexpected pod list: %#v", pods) - } -} - -func TestMemoryGetPods(t *testing.T) { - registry := NewRegistry() - pod, err := registry.GetPod("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.GetPod(%q) failed with %v; expected failure with not found error", "foo", err) - } else { - t.Errorf("registry.GetPod(%q) = %v; expected failure with not found error", "foo", pod) - } - } -} - -func TestMemorySetGetPods(t *testing.T) { - registry := NewRegistry() - expectedPod := api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - registry.CreatePod("machine", expectedPod) - pod, err := registry.GetPod("foo") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if expectedPod.ID != pod.ID { - t.Errorf("Unexpected pod, expected %#v, actual %#v", expectedPod, pod) - } -} - -func TestMemoryUpdatePods(t *testing.T) { - registry := NewRegistry() - pod := api.Pod{ - JSONBase: api.JSONBase{ - ID: "foo", - }, - DesiredState: api.PodState{ - Host: "foo.com", - }, - } - err := registry.UpdatePod(pod) - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.UpdatePod(%q) failed with %v; expected failure with not found error", pod, err) - } else { - t.Errorf("registry.UpdatePod(%q) succeeded; expected failure with not found error", pod) - } - } -} - -func TestMemorySetUpdateGetPods(t *testing.T) { - registry := NewRegistry() - oldPod := api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - expectedPod := api.Pod{ - JSONBase: api.JSONBase{ - ID: "foo", - }, - DesiredState: api.PodState{ - Host: "foo.com", - }, - } - registry.CreatePod("machine", oldPod) - registry.UpdatePod(expectedPod) - pod, err := registry.GetPod("foo") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if expectedPod.ID != pod.ID || pod.DesiredState.Host != expectedPod.DesiredState.Host { - t.Errorf("Unexpected pod, expected %#v, actual %#v", expectedPod, pod) - } -} - -func TestMemoryDeletePods(t *testing.T) { - registry := NewRegistry() - err := registry.DeletePod("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.DeletePod(%q) failed with %v; expected failure with not found error", "foo", err) - } else { - t.Errorf("registry.DeletePod(%q) succeeded; expected failure with not found error", "foo") - } - } -} - -func TestMemorySetDeleteGetPods(t *testing.T) { - registry := NewRegistry() - expectedPod := api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - registry.CreatePod("machine", expectedPod) - registry.DeletePod("foo") - pod, err := registry.GetPod("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.GetPod(%q) failed with %v; expected failure with not found error", "foo", err) - } else { - t.Errorf("registry.GetPod(%q) = %v; expected failure with not found error", "foo", pod) - } - } -} - -func TestListControllersEmpty(t *testing.T) { - registry := NewRegistry() - ctls, err := registry.ListControllers() - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if len(ctls) != 0 { - t.Errorf("Unexpected controller list: %#v", ctls) - } -} - -func TestMemoryListControllers(t *testing.T) { - registry := NewRegistry() - registry.CreateController(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}) - ctls, err := registry.ListControllers() - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if len(ctls) != 1 || ctls[0].ID != "foo" { - t.Errorf("Unexpected controller list: %#v", ctls) - } -} - -func TestMemoryGetController(t *testing.T) { - registry := NewRegistry() - ctl, err := registry.GetController("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.GetController(%q) failed with %v; expected failure with not found error", "foo", err) - } else { - t.Errorf("registry.GetController(%q) = %v; expected failure with not found error", "foo", ctl) - } - } -} - -func TestMemorySetGetControllers(t *testing.T) { - registry := NewRegistry() - expectedController := api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}} - registry.CreateController(expectedController) - ctl, err := registry.GetController("foo") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if expectedController.ID != ctl.ID { - t.Errorf("Unexpected controller, expected %#v, actual %#v", expectedController, ctl) - } -} - -func TestMemoryUpdateController(t *testing.T) { - registry := NewRegistry() - ctl := api.ReplicationController{ - JSONBase: api.JSONBase{ - ID: "foo", - }, - DesiredState: api.ReplicationControllerState{ - Replicas: 2, - }, - } - err := registry.UpdateController(ctl) - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.UpdateController(%q) failed with %v; expected failure with not found error", ctl, err) - } else { - t.Errorf("registry.UpdateController(%q) succeeded; expected failure with not found error", ctl) - } - } -} - -func TestMemorySetUpdateGetControllers(t *testing.T) { - registry := NewRegistry() - oldController := api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}} - expectedController := api.ReplicationController{ - JSONBase: api.JSONBase{ - ID: "foo", - }, - DesiredState: api.ReplicationControllerState{ - Replicas: 2, - }, - } - registry.CreateController(oldController) - registry.UpdateController(expectedController) - ctl, err := registry.GetController("foo") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if expectedController.ID != ctl.ID || ctl.DesiredState.Replicas != expectedController.DesiredState.Replicas { - t.Errorf("Unexpected controller, expected %#v, actual %#v", expectedController, ctl) - } -} - -func TestMemoryDeleteController(t *testing.T) { - registry := NewRegistry() - err := registry.DeleteController("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.DeleteController(%q) failed with %v; expected failure with not found error", "foo", err) - } else { - t.Errorf("registry.DeleteController(%q) succeeded; expected failure with not found error", "foo") - } - } -} - -func TestMemorySetDeleteGetControllers(t *testing.T) { - registry := NewRegistry() - expectedController := api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}} - registry.CreateController(expectedController) - registry.DeleteController("foo") - ctl, err := registry.GetController("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.GetController(%q) failed with %v; expected failure with not found error", "foo", err) - } else { - t.Errorf("registry.GetController(%q) = %v; expected failure with not found error", "foo", ctl) - } - } -} - -func TestListServicesEmpty(t *testing.T) { - registry := NewRegistry() - svcs, err := registry.ListServices() - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if len(svcs.Items) != 0 { - t.Errorf("Unexpected service list: %#v", svcs) - } -} - -func TestMemoryListServices(t *testing.T) { - registry := NewRegistry() - registry.CreateService(api.Service{JSONBase: api.JSONBase{ID: "foo"}}) - svcs, err := registry.ListServices() - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if len(svcs.Items) != 1 || svcs.Items[0].ID != "foo" { - t.Errorf("Unexpected service list: %#v", svcs) - } -} - -func TestMemoryGetService(t *testing.T) { - registry := NewRegistry() - svc, err := registry.GetService("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.GetService(%q) failed with %v; expected failure with not found error", "foo", err) - } else { - t.Errorf("registry.GetService(%q) = %v; expected failure with not found error", "foo", svc) - } - } -} - -func TestMemorySetGetServices(t *testing.T) { - registry := NewRegistry() - expectedService := api.Service{JSONBase: api.JSONBase{ID: "foo"}} - registry.CreateService(expectedService) - svc, err := registry.GetService("foo") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if expectedService.ID != svc.ID { - t.Errorf("Unexpected service, expected %#v, actual %#v", expectedService, svc) - } -} - -func TestMemoryUpdateService(t *testing.T) { - registry := NewRegistry() - svc := api.Service{ - JSONBase: api.JSONBase{ - ID: "foo", - }, - Port: 9000, - } - err := registry.UpdateService(svc) - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.UpdateService(%q) failed with %v; expected failure with not found error", svc, err) - } else { - t.Errorf("registry.UpdateService(%q) succeeded; expected failure with not found error", svc) - } - } -} - -func TestMemorySetUpdateGetServices(t *testing.T) { - registry := NewRegistry() - oldService := api.Service{JSONBase: api.JSONBase{ID: "foo"}} - expectedService := api.Service{ - JSONBase: api.JSONBase{ - ID: "foo", - }, - Port: 9000, - } - registry.CreateService(oldService) - registry.UpdateService(expectedService) - svc, err := registry.GetService("foo") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if expectedService.ID != svc.ID || svc.Port != expectedService.Port { - t.Errorf("Unexpected service, expected %#v, actual %#v", expectedService, svc) - } -} - -func TestMemoryDeleteService(t *testing.T) { - registry := NewRegistry() - err := registry.DeleteService("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.DeleteService(%q) failed with %v; expected failure with not found error", "foo", err) - } else { - t.Errorf("registry.DeleteService(%q) succeeded; expected failure with not found error", "foo") - } - } -} - -func TestMemorySetDeleteGetServices(t *testing.T) { - registry := NewRegistry() - expectedService := api.Service{JSONBase: api.JSONBase{ID: "foo"}} - registry.CreateService(expectedService) - registry.DeleteService("foo") - svc, err := registry.GetService("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.GetService(%q) failed with %v; expected failure with not found error", "foo", err) - } else { - t.Errorf("registry.GetService(%q) = %v; expected failure with not found error", "foo", svc) - } - } -} diff --git a/pkg/registry/registrytest/service.go b/pkg/registry/registrytest/service.go index b637d9cb83..6ea691b02b 100644 --- a/pkg/registry/registrytest/service.go +++ b/pkg/registry/registrytest/service.go @@ -20,10 +20,18 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" ) +func NewServiceRegistry() *ServiceRegistry { + return &ServiceRegistry{} +} + type ServiceRegistry struct { List api.ServiceList + Service *api.Service Err error Endpoints api.Endpoints + + DeletedID string + GottenID string } func (r *ServiceRegistry) ListServices() (api.ServiceList, error) { @@ -31,14 +39,17 @@ func (r *ServiceRegistry) ListServices() (api.ServiceList, error) { } func (r *ServiceRegistry) CreateService(svc api.Service) error { + r.Service = &svc return r.Err } -func (r *ServiceRegistry) GetService(name string) (*api.Service, error) { - return nil, r.Err +func (r *ServiceRegistry) GetService(id string) (*api.Service, error) { + r.GottenID = id + return r.Service, r.Err } -func (r *ServiceRegistry) DeleteService(name string) error { +func (r *ServiceRegistry) DeleteService(id string) error { + r.DeletedID = id return r.Err } diff --git a/pkg/registry/service/storage_test.go b/pkg/registry/service/storage_test.go index bb61ab0dcc..92e2c1de79 100644 --- a/pkg/registry/service/storage_test.go +++ b/pkg/registry/service/storage_test.go @@ -21,15 +21,14 @@ import ( "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider" - "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/memory" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion" + "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) func TestRegistry(t *testing.T) { - registry := memory.NewRegistry() + registry := registrytest.NewServiceRegistry() fakeCloud := &cloudprovider.FakeCloud{} machines := []string{"foo", "bar", "baz"} storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) @@ -52,7 +51,7 @@ func TestRegistry(t *testing.T) { } func TestServiceStorageValidatesCreate(t *testing.T) { - registry := memory.NewRegistry() + registry := registrytest.NewServiceRegistry() storage := NewRegistryStorage(registry, nil, nil) failureCases := map[string]api.Service{ "empty ID": { @@ -76,7 +75,7 @@ func TestServiceStorageValidatesCreate(t *testing.T) { } func TestServiceStorageValidatesUpdate(t *testing.T) { - registry := memory.NewRegistry() + registry := registrytest.NewServiceRegistry() registry.CreateService(api.Service{ JSONBase: api.JSONBase{ID: "foo"}, Selector: map[string]string{"bar": "baz"}, @@ -104,7 +103,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) { } func TestServiceRegistryExternalService(t *testing.T) { - registry := memory.NewRegistry() + registry := registrytest.NewServiceRegistry() fakeCloud := &cloudprovider.FakeCloud{} machines := []string{"foo", "bar", "baz"} storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) @@ -128,7 +127,7 @@ func TestServiceRegistryExternalService(t *testing.T) { } func TestServiceRegistryExternalServiceError(t *testing.T) { - registry := memory.NewRegistry() + registry := registrytest.NewServiceRegistry() fakeCloud := &cloudprovider.FakeCloud{ Err: fmt.Errorf("test error"), } @@ -144,18 +143,13 @@ func TestServiceRegistryExternalServiceError(t *testing.T) { if len(fakeCloud.Calls) != 1 || fakeCloud.Calls[0] != "get-zone" { t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls) } - srv, err := registry.GetService("foo") - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.GetService(%q) failed with %v; expected failure with not found error", svc.ID, err) - } else { - t.Errorf("registry.GetService(%q) = %v; expected failure with not found error", svc.ID, srv) - } + if registry.Service != nil { + t.Errorf("expected registry.CreateService to not get called, but it got %#v", registry.Service) } } func TestServiceRegistryDelete(t *testing.T) { - registry := memory.NewRegistry() + registry := registrytest.NewServiceRegistry() fakeCloud := &cloudprovider.FakeCloud{} machines := []string{"foo", "bar", "baz"} storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) @@ -169,18 +163,13 @@ func TestServiceRegistryDelete(t *testing.T) { if len(fakeCloud.Calls) != 0 { t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls) } - srv, err := registry.GetService(svc.ID) - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.GetService(%q) failed with %v; expected failure with not found error", svc.ID, err) - } else { - t.Errorf("registry.GetService(%q) = %v; expected failure with not found error", svc.ID, srv) - } + if e, a := "foo", registry.DeletedID; e != a { + t.Errorf("expected %v, but got %v", e, a) } } func TestServiceRegistryDeleteExternal(t *testing.T) { - registry := memory.NewRegistry() + registry := registrytest.NewServiceRegistry() fakeCloud := &cloudprovider.FakeCloud{} machines := []string{"foo", "bar", "baz"} storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines)) @@ -195,13 +184,8 @@ func TestServiceRegistryDeleteExternal(t *testing.T) { if len(fakeCloud.Calls) != 2 || fakeCloud.Calls[0] != "get-zone" || fakeCloud.Calls[1] != "delete" { t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls) } - srv, err := registry.GetService(svc.ID) - if !apiserver.IsNotFound(err) { - if err != nil { - t.Errorf("registry.GetService(%q) failed with %v; expected failure with not found error", svc.ID, err) - } else { - t.Errorf("registry.GetService(%q) = %v; expected failure with not found error", svc.ID, srv) - } + if e, a := "foo", registry.DeletedID; e != a { + t.Errorf("expected %v, but got %v", e, a) } }