Ejemplo n.º 1
0
func TestGetEndpointsMissingService(t *testing.T) {
	registry := &registrytest.ServiceRegistry{
		Err: apiserver.NewNotFoundErr("service", "foo"),
	}
	storage := NewStorage(registry)

	// returns service not found
	_, err := storage.Get("foo")
	if !apiserver.IsNotFound(err) || !reflect.DeepEqual(err, apiserver.NewNotFoundErr("service", "foo")) {
		t.Errorf("expected NotFound error, got %#v", err)
	}

	// returns empty endpoints
	registry.Err = nil
	registry.Service = &api.Service{
		JSONBase: api.JSONBase{ID: "foo"},
	}
	obj, err := storage.Get("foo")
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if obj.(*api.Endpoints).Endpoints != nil {
		t.Errorf("unexpected endpoints: %#v", obj)
	}
}
Ejemplo n.º 2
0
func TestServiceRegistryDelete(t *testing.T) {
	memory := MakeMemoryRegistry()
	fakeCloud := &cloudprovider.FakeCloud{}
	machines := []string{"foo", "bar", "baz"}

	storage := MakeServiceRegistryStorage(memory, fakeCloud, MakeMinionRegistry(machines))

	svc := api.Service{
		JSONBase: api.JSONBase{ID: "foo"},
		Selector: map[string]string{"bar": "baz"},
	}
	memory.CreateService(svc)

	c, _ := storage.Delete(svc.ID)
	<-c

	if len(fakeCloud.Calls) != 0 {
		t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls)
	}
	srv, err := memory.GetService(svc.ID)
	if !apiserver.IsNotFound(err) {
		if err != nil {
			t.Errorf("memory.GetService(%q) failed with %v; expected failure with not found error", svc.ID, err)
		} else {
			t.Errorf("memory.GetService(%q) = %v; expected failure with not found error", svc.ID, srv)
		}
	}
}
Ejemplo n.º 3
0
func TestServiceRegistryDeleteExternal(t *testing.T) {
	registry := memory.NewRegistry()
	fakeCloud := &cloudprovider.FakeCloud{}
	machines := []string{"foo", "bar", "baz"}
	storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
	svc := api.Service{
		JSONBase:                   api.JSONBase{ID: "foo"},
		Selector:                   map[string]string{"bar": "baz"},
		CreateExternalLoadBalancer: true,
	}
	registry.CreateService(svc)
	c, _ := storage.Delete(svc.ID)
	<-c
	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)
		}
	}
}
Ejemplo n.º 4
0
func TestServiceRegistryExternalServiceError(t *testing.T) {
	memory := MakeMemoryRegistry()
	fakeCloud := &cloudprovider.FakeCloud{
		Err: fmt.Errorf("test error"),
	}
	machines := []string{"foo", "bar", "baz"}

	storage := MakeServiceRegistryStorage(memory, fakeCloud, MakeMinionRegistry(machines))

	svc := &api.Service{
		JSONBase:                   api.JSONBase{ID: "foo"},
		Selector:                   map[string]string{"bar": "baz"},
		CreateExternalLoadBalancer: true,
	}
	c, _ := storage.Create(svc)
	<-c

	if len(fakeCloud.Calls) != 1 || fakeCloud.Calls[0] != "get-zone" {
		t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls)
	}
	srv, err := memory.GetService("foo")
	if !apiserver.IsNotFound(err) {
		if err != nil {
			t.Errorf("memory.GetService(%q) failed with %v; expected failure with not found error", svc.ID, err)
		} else {
			t.Errorf("memory.GetService(%q) = %v; expected failure with not found error", svc.ID, srv)
		}
	}
}
Ejemplo n.º 5
0
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)
		}
	}
}
Ejemplo n.º 6
0
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 TestMemoryGetService(t *testing.T) {
	registry := MakeMemoryRegistry()
	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 TestMemoryGetController(t *testing.T) {
	registry := MakeMemoryRegistry()
	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)
		}
	}
}
Ejemplo n.º 9
0
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)
		}
	}
}
Ejemplo n.º 10
0
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)
		}
	}
}
Ejemplo n.º 11
0
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)
		}
	}
}
Ejemplo n.º 12
0
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)
		}
	}
}
Ejemplo n.º 13
0
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)
		}
	}
}
Ejemplo n.º 14
0
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)
		}
	}
}