mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Add context object in test cases flows
This commit is contained in:
parent
3e685674e7
commit
be85ad7a3d
@ -30,6 +30,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
apierrs "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
@ -88,18 +89,18 @@ type SimpleRESTStorage struct {
|
||||
injectedFunction func(obj runtime.Object) (returnObj runtime.Object, err error)
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) List(label, field labels.Selector) (runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) List(ctx context.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||
result := &SimpleList{
|
||||
Items: storage.list,
|
||||
}
|
||||
return result, storage.errors["list"]
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Get(id string) (runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Get(ctx context.Context, id string) (runtime.Object, error) {
|
||||
return api.Scheme.CopyOrDie(&storage.item), storage.errors["get"]
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Delete(id string) (<-chan runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Delete(ctx context.Context, id string) (<-chan runtime.Object, error) {
|
||||
storage.deleted = id
|
||||
if err := storage.errors["delete"]; err != nil {
|
||||
return nil, err
|
||||
@ -116,7 +117,7 @@ func (storage *SimpleRESTStorage) New() runtime.Object {
|
||||
return &Simple{}
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Create(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
storage.created = obj.(*Simple)
|
||||
if err := storage.errors["create"]; err != nil {
|
||||
return nil, err
|
||||
@ -129,7 +130,7 @@ func (storage *SimpleRESTStorage) Create(obj runtime.Object) (<-chan runtime.Obj
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
func (storage *SimpleRESTStorage) Update(ctx context.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||
storage.updated = obj.(*Simple)
|
||||
if err := storage.errors["update"]; err != nil {
|
||||
return nil, err
|
||||
@ -143,7 +144,7 @@ func (storage *SimpleRESTStorage) Update(obj runtime.Object) (<-chan runtime.Obj
|
||||
}
|
||||
|
||||
// Implement ResourceWatcher.
|
||||
func (storage *SimpleRESTStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
func (storage *SimpleRESTStorage) Watch(ctx context.Context, label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
storage.requestedLabelSelector = label
|
||||
storage.requestedFieldSelector = field
|
||||
storage.requestedResourceVersion = resourceVersion
|
||||
@ -155,7 +156,7 @@ func (storage *SimpleRESTStorage) Watch(label, field labels.Selector, resourceVe
|
||||
}
|
||||
|
||||
// Implement Redirector.
|
||||
func (storage *SimpleRESTStorage) ResourceLocation(id string) (string, error) {
|
||||
func (storage *SimpleRESTStorage) ResourceLocation(ctx context.Context, id string) (string, error) {
|
||||
storage.requestedResourceLocationID = id
|
||||
if err := storage.errors["resourceLocation"]; err != nil {
|
||||
return "", err
|
||||
|
@ -22,6 +22,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
@ -52,24 +54,25 @@ func TestNewREST(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRESTUnsupported(t *testing.T) {
|
||||
var ctx context.Context
|
||||
mockRegistry := MockRegistry{
|
||||
OnApplyBinding: func(b *api.Binding) error { return nil },
|
||||
}
|
||||
b := NewREST(mockRegistry)
|
||||
if _, err := b.Delete("binding id"); err == nil {
|
||||
if _, err := b.Delete(ctx, "binding id"); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if _, err := b.Update(&api.Binding{PodID: "foo", Host: "new machine"}); err == nil {
|
||||
if _, err := b.Update(ctx, &api.Binding{PodID: "foo", Host: "new machine"}); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if _, err := b.Get("binding id"); err == nil {
|
||||
if _, err := b.Get(ctx, "binding id"); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if _, err := b.List(labels.Set{"name": "foo"}.AsSelector(), labels.Everything()); err == nil {
|
||||
if _, err := b.List(ctx, labels.Set{"name": "foo"}.AsSelector(), labels.Everything()); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
// Try sending wrong object just to get 100% coverage
|
||||
if _, err := b.Create(&api.Pod{}); err == nil {
|
||||
if _, err := b.Create(ctx, &api.Pod{}); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
}
|
||||
@ -93,8 +96,9 @@ func TestRESTPost(t *testing.T) {
|
||||
return item.err
|
||||
},
|
||||
}
|
||||
ctx := api.NewContext()
|
||||
b := NewREST(mockRegistry)
|
||||
resultChan, err := b.Create(item.b)
|
||||
resultChan, err := b.Create(ctx, item.b)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %v", err)
|
||||
continue
|
||||
|
@ -24,6 +24,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
@ -39,7 +41,8 @@ func TestListControllersError(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: &mockRegistry,
|
||||
}
|
||||
controllers, err := storage.List(labels.Everything(), labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
controllers, err := storage.List(ctx, labels.Everything(), labels.Everything())
|
||||
if err != mockRegistry.Err {
|
||||
t.Errorf("Expected %#v, Got %#v", mockRegistry.Err, err)
|
||||
}
|
||||
@ -53,7 +56,8 @@ func TestListEmptyControllerList(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: &mockRegistry,
|
||||
}
|
||||
controllers, err := storage.List(labels.Everything(), labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
controllers, err := storage.List(ctx, labels.Everything(), labels.Everything())
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@ -86,7 +90,8 @@ func TestListControllerList(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: &mockRegistry,
|
||||
}
|
||||
controllersObj, err := storage.List(labels.Everything(), labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
controllersObj, err := storage.List(ctx, labels.Everything(), labels.Everything())
|
||||
controllers := controllersObj.(*api.ReplicationControllerList)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
@ -240,7 +245,8 @@ func TestCreateController(t *testing.T) {
|
||||
PodTemplate: validPodTemplate,
|
||||
},
|
||||
}
|
||||
channel, err := storage.Create(controller)
|
||||
ctx := api.NewContext()
|
||||
channel, err := storage.Create(ctx, controller)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
@ -263,7 +269,6 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
|
||||
podLister: nil,
|
||||
pollPeriod: time.Millisecond * 1,
|
||||
}
|
||||
|
||||
failureCases := map[string]api.ReplicationController{
|
||||
"empty ID": {
|
||||
JSONBase: api.JSONBase{ID: ""},
|
||||
@ -277,7 +282,8 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, failureCase := range failureCases {
|
||||
c, err := storage.Create(&failureCase)
|
||||
ctx := api.NewContext()
|
||||
c, err := storage.Create(ctx, &failureCase)
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
@ -307,7 +313,8 @@ func TestControllerStorageValidatesUpdate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, failureCase := range failureCases {
|
||||
c, err := storage.Update(&failureCase)
|
||||
ctx := api.NewContext()
|
||||
c, err := storage.Update(ctx, &failureCase)
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
@ -323,7 +330,7 @@ type fakePodLister struct {
|
||||
s labels.Selector
|
||||
}
|
||||
|
||||
func (f *fakePodLister) ListPods(s labels.Selector) (*api.PodList, error) {
|
||||
func (f *fakePodLister) ListPods(ctx context.Context, s labels.Selector) (*api.PodList, error) {
|
||||
f.s = s
|
||||
return &f.l, f.e
|
||||
}
|
||||
@ -349,7 +356,8 @@ func TestFillCurrentState(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage.fillCurrentState(&controller)
|
||||
ctx := api.NewContext()
|
||||
storage.fillCurrentState(ctx, &controller)
|
||||
if controller.CurrentState.Replicas != 2 {
|
||||
t.Errorf("expected 2, got: %d", controller.CurrentState.Replicas)
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ func TestGetEndpoints(t *testing.T) {
|
||||
},
|
||||
}
|
||||
storage := NewREST(registry)
|
||||
obj, err := storage.Get("foo")
|
||||
ctx := api.NewContext()
|
||||
obj, err := storage.Get(ctx, "foo")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %#v", err)
|
||||
}
|
||||
@ -48,9 +49,9 @@ func TestGetEndpointsMissingService(t *testing.T) {
|
||||
Err: errors.NewNotFound("service", "foo"),
|
||||
}
|
||||
storage := NewREST(registry)
|
||||
|
||||
ctx := api.NewContext()
|
||||
// returns service not found
|
||||
_, err := storage.Get("foo")
|
||||
_, err := storage.Get(ctx, "foo")
|
||||
if !errors.IsNotFound(err) || !reflect.DeepEqual(err, errors.NewNotFound("service", "foo")) {
|
||||
t.Errorf("expected NotFound error, got %#v", err)
|
||||
}
|
||||
@ -60,7 +61,7 @@ func TestGetEndpointsMissingService(t *testing.T) {
|
||||
registry.Service = &api.Service{
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
}
|
||||
obj, err := storage.Get("foo")
|
||||
obj, err := storage.Get(ctx, "foo")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@ -79,7 +80,8 @@ func TestEndpointsRegistryList(t *testing.T) {
|
||||
{JSONBase: api.JSONBase{ID: "bar"}},
|
||||
},
|
||||
}
|
||||
s, _ := storage.List(labels.Everything(), labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
s, _ := storage.List(ctx, labels.Everything(), labels.Everything())
|
||||
sl := s.(*api.EndpointsList)
|
||||
if len(sl.Items) != 2 {
|
||||
t.Fatalf("Expected 2 endpoints, but got %v", len(sl.Items))
|
||||
|
@ -410,7 +410,8 @@ func TestEtcdEmptyListPods(t *testing.T) {
|
||||
E: nil,
|
||||
}
|
||||
registry := NewTestEtcdRegistry(fakeClient)
|
||||
pods, err := registry.ListPods(labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
pods, err := registry.ListPods(ctx, labels.Everything())
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@ -428,7 +429,8 @@ func TestEtcdListPodsNotFound(t *testing.T) {
|
||||
E: tools.EtcdErrorNotFound,
|
||||
}
|
||||
registry := NewTestEtcdRegistry(fakeClient)
|
||||
pods, err := registry.ListPods(labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
pods, err := registry.ListPods(ctx, labels.Everything())
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@ -463,7 +465,8 @@ func TestEtcdListPods(t *testing.T) {
|
||||
E: nil,
|
||||
}
|
||||
registry := NewTestEtcdRegistry(fakeClient)
|
||||
pods, err := registry.ListPods(labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
pods, err := registry.ListPods(ctx, labels.Everything())
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -27,18 +27,18 @@ import (
|
||||
func TestMinionREST(t *testing.T) {
|
||||
m := NewRegistry([]string{"foo", "bar"})
|
||||
ms := NewREST(m)
|
||||
|
||||
if obj, err := ms.Get("foo"); err != nil || obj.(*api.Minion).ID != "foo" {
|
||||
ctx := api.NewContext()
|
||||
if obj, err := ms.Get(ctx, "foo"); err != nil || obj.(*api.Minion).ID != "foo" {
|
||||
t.Errorf("missing expected object")
|
||||
}
|
||||
if obj, err := ms.Get("bar"); err != nil || obj.(*api.Minion).ID != "bar" {
|
||||
if obj, err := ms.Get(ctx, "bar"); err != nil || obj.(*api.Minion).ID != "bar" {
|
||||
t.Errorf("missing expected object")
|
||||
}
|
||||
if _, err := ms.Get("baz"); err != ErrDoesNotExist {
|
||||
if _, err := ms.Get(ctx, "baz"); err != ErrDoesNotExist {
|
||||
t.Errorf("has unexpected object")
|
||||
}
|
||||
|
||||
c, err := ms.Create(&api.Minion{JSONBase: api.JSONBase{ID: "baz"}})
|
||||
c, err := ms.Create(ctx, &api.Minion{JSONBase: api.JSONBase{ID: "baz"}})
|
||||
if err != nil {
|
||||
t.Errorf("insert failed")
|
||||
}
|
||||
@ -46,11 +46,11 @@ func TestMinionREST(t *testing.T) {
|
||||
if m, ok := obj.(*api.Minion); !ok || m.ID != "baz" {
|
||||
t.Errorf("insert return value was weird: %#v", obj)
|
||||
}
|
||||
if obj, err := ms.Get("baz"); err != nil || obj.(*api.Minion).ID != "baz" {
|
||||
if obj, err := ms.Get(ctx, "baz"); err != nil || obj.(*api.Minion).ID != "baz" {
|
||||
t.Errorf("insert didn't actually insert")
|
||||
}
|
||||
|
||||
c, err = ms.Delete("bar")
|
||||
c, err = ms.Delete(ctx, "bar")
|
||||
if err != nil {
|
||||
t.Errorf("delete failed")
|
||||
}
|
||||
@ -58,16 +58,16 @@ func TestMinionREST(t *testing.T) {
|
||||
if s, ok := obj.(*api.Status); !ok || s.Status != api.StatusSuccess {
|
||||
t.Errorf("delete return value was weird: %#v", obj)
|
||||
}
|
||||
if _, err := ms.Get("bar"); err != ErrDoesNotExist {
|
||||
if _, err := ms.Get(ctx, "bar"); err != ErrDoesNotExist {
|
||||
t.Errorf("delete didn't actually delete")
|
||||
}
|
||||
|
||||
_, err = ms.Delete("bar")
|
||||
_, err = ms.Delete(ctx, "bar")
|
||||
if err != ErrDoesNotExist {
|
||||
t.Errorf("delete returned wrong error")
|
||||
}
|
||||
|
||||
list, err := ms.List(labels.Everything(), labels.Everything())
|
||||
list, err := ms.List(ctx, labels.Everything(), labels.Everything())
|
||||
if err != nil {
|
||||
t.Errorf("got error calling List")
|
||||
}
|
||||
|
@ -69,7 +69,8 @@ func TestCreatePodRegistryError(t *testing.T) {
|
||||
},
|
||||
}
|
||||
pod := &api.Pod{DesiredState: desiredState}
|
||||
ch, err := storage.Create(pod)
|
||||
ctx := api.NewContext()
|
||||
ch, err := storage.Create(ctx, pod)
|
||||
if err != nil {
|
||||
t.Errorf("Expected %#v, Got %#v", nil, err)
|
||||
}
|
||||
@ -88,7 +89,8 @@ func TestCreatePodSetsIds(t *testing.T) {
|
||||
},
|
||||
}
|
||||
pod := &api.Pod{DesiredState: desiredState}
|
||||
ch, err := storage.Create(pod)
|
||||
ctx := api.NewContext()
|
||||
ch, err := storage.Create(ctx, pod)
|
||||
if err != nil {
|
||||
t.Errorf("Expected %#v, Got %#v", nil, err)
|
||||
}
|
||||
@ -114,7 +116,8 @@ func TestCreatePodSetsUUIDs(t *testing.T) {
|
||||
},
|
||||
}
|
||||
pod := &api.Pod{DesiredState: desiredState}
|
||||
ch, err := storage.Create(pod)
|
||||
ctx := api.NewContext()
|
||||
ch, err := storage.Create(ctx, pod)
|
||||
if err != nil {
|
||||
t.Errorf("Expected %#v, Got %#v", nil, err)
|
||||
}
|
||||
@ -131,7 +134,8 @@ func TestListPodsError(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: podRegistry,
|
||||
}
|
||||
pods, err := storage.List(labels.Everything(), labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
pods, err := storage.List(ctx, labels.Everything(), labels.Everything())
|
||||
if err != podRegistry.Err {
|
||||
t.Errorf("Expected %#v, Got %#v", podRegistry.Err, err)
|
||||
}
|
||||
@ -145,7 +149,8 @@ func TestListEmptyPodList(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: podRegistry,
|
||||
}
|
||||
pods, err := storage.List(labels.Everything(), labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
pods, err := storage.List(ctx, labels.Everything(), labels.Everything())
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@ -177,7 +182,8 @@ func TestListPodList(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: podRegistry,
|
||||
}
|
||||
podsObj, err := storage.List(labels.Everything(), labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
podsObj, err := storage.List(ctx, labels.Everything(), labels.Everything())
|
||||
pods := podsObj.(*api.PodList)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
@ -217,6 +223,7 @@ func TestListPodListSelection(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: podRegistry,
|
||||
}
|
||||
ctx := api.NewContext()
|
||||
|
||||
table := []struct {
|
||||
label, field string
|
||||
@ -256,7 +263,7 @@ func TestListPodListSelection(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
continue
|
||||
}
|
||||
podsObj, err := storage.List(label, field)
|
||||
podsObj, err := storage.List(ctx, label, field)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@ -305,7 +312,8 @@ func TestGetPod(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: podRegistry,
|
||||
}
|
||||
obj, err := storage.Get("foo")
|
||||
ctx := api.NewContext()
|
||||
obj, err := storage.Get(ctx, "foo")
|
||||
pod := obj.(*api.Pod)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
@ -324,7 +332,8 @@ func TestGetPodCloud(t *testing.T) {
|
||||
registry: podRegistry,
|
||||
cloudProvider: fakeCloud,
|
||||
}
|
||||
obj, err := storage.Get("foo")
|
||||
ctx := api.NewContext()
|
||||
obj, err := storage.Get(ctx, "foo")
|
||||
pod := obj.(*api.Pod)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
@ -487,8 +496,9 @@ func TestPodStorageValidatesCreate(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: podRegistry,
|
||||
}
|
||||
ctx := api.NewContext()
|
||||
pod := &api.Pod{}
|
||||
c, err := storage.Create(pod)
|
||||
c, err := storage.Create(ctx, pod)
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
@ -503,8 +513,9 @@ func TestPodStorageValidatesUpdate(t *testing.T) {
|
||||
storage := REST{
|
||||
registry: podRegistry,
|
||||
}
|
||||
ctx := api.NewContext()
|
||||
pod := &api.Pod{}
|
||||
c, err := storage.Update(pod)
|
||||
c, err := storage.Update(ctx, pod)
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
@ -534,7 +545,8 @@ func TestCreatePod(t *testing.T) {
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
DesiredState: desiredState,
|
||||
}
|
||||
channel, err := storage.Create(pod)
|
||||
ctx := api.NewContext()
|
||||
channel, err := storage.Create(ctx, pod)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
type PodRegistry struct {
|
||||
@ -57,7 +59,7 @@ func (r *PodRegistry) ListPodsPredicate(filter func(*api.Pod) bool) (*api.PodLis
|
||||
return &pods, nil
|
||||
}
|
||||
|
||||
func (r *PodRegistry) ListPods(selector labels.Selector) (*api.PodList, error) {
|
||||
func (r *PodRegistry) ListPods(ctx context.Context, selector labels.Selector) (*api.PodList, error) {
|
||||
return r.ListPodsPredicate(func(pod *api.Pod) bool {
|
||||
return selector.Matches(labels.Set(pod.Labels))
|
||||
})
|
||||
|
@ -40,7 +40,8 @@ func TestServiceRegistryCreate(t *testing.T) {
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
}
|
||||
c, _ := storage.Create(svc)
|
||||
ctx := api.NewContext()
|
||||
c, _ := storage.Create(ctx, svc)
|
||||
created_svc := <-c
|
||||
created_service := created_svc.(*api.Service)
|
||||
if created_service.ID != "foo" {
|
||||
@ -75,8 +76,9 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
|
||||
Selector: map[string]string{},
|
||||
},
|
||||
}
|
||||
ctx := api.NewContext()
|
||||
for _, failureCase := range failureCases {
|
||||
c, err := storage.Create(&failureCase)
|
||||
c, err := storage.Create(ctx, &failureCase)
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
@ -95,7 +97,8 @@ func TestServiceRegistryUpdate(t *testing.T) {
|
||||
Selector: map[string]string{"bar": "baz1"},
|
||||
})
|
||||
storage := NewREST(registry, nil, nil)
|
||||
c, err := storage.Update(&api.Service{
|
||||
ctx := api.NewContext()
|
||||
c, err := storage.Update(ctx, &api.Service{
|
||||
Port: 6502,
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
Selector: map[string]string{"bar": "baz2"},
|
||||
@ -136,8 +139,9 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
|
||||
Selector: map[string]string{},
|
||||
},
|
||||
}
|
||||
ctx := api.NewContext()
|
||||
for _, failureCase := range failureCases {
|
||||
c, err := storage.Update(&failureCase)
|
||||
c, err := storage.Update(ctx, &failureCase)
|
||||
if c != nil {
|
||||
t.Errorf("Expected nil channel")
|
||||
}
|
||||
@ -158,7 +162,8 @@ func TestServiceRegistryExternalService(t *testing.T) {
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
CreateExternalLoadBalancer: true,
|
||||
}
|
||||
c, _ := storage.Create(svc)
|
||||
ctx := api.NewContext()
|
||||
c, _ := storage.Create(ctx, svc)
|
||||
<-c
|
||||
if len(fakeCloud.Calls) != 2 || fakeCloud.Calls[0] != "get-zone" || fakeCloud.Calls[1] != "create" {
|
||||
t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls)
|
||||
@ -185,7 +190,8 @@ func TestServiceRegistryExternalServiceError(t *testing.T) {
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
CreateExternalLoadBalancer: true,
|
||||
}
|
||||
c, _ := storage.Create(svc)
|
||||
ctx := api.NewContext()
|
||||
c, _ := storage.Create(ctx, svc)
|
||||
<-c
|
||||
if len(fakeCloud.Calls) != 1 || fakeCloud.Calls[0] != "get-zone" {
|
||||
t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls)
|
||||
@ -204,8 +210,9 @@ func TestServiceRegistryDelete(t *testing.T) {
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
}
|
||||
ctx := api.NewContext()
|
||||
registry.CreateService(svc)
|
||||
c, _ := storage.Delete(svc.ID)
|
||||
c, _ := storage.Delete(ctx, svc.ID)
|
||||
<-c
|
||||
if len(fakeCloud.Calls) != 0 {
|
||||
t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls)
|
||||
@ -225,8 +232,9 @@ func TestServiceRegistryDeleteExternal(t *testing.T) {
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
CreateExternalLoadBalancer: true,
|
||||
}
|
||||
ctx := api.NewContext()
|
||||
registry.CreateService(svc)
|
||||
c, _ := storage.Delete(svc.ID)
|
||||
c, _ := storage.Delete(ctx, 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)
|
||||
@ -309,7 +317,8 @@ func TestServiceRegistryGet(t *testing.T) {
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
})
|
||||
storage.Get("foo")
|
||||
ctx := api.NewContext()
|
||||
storage.Get(ctx, "foo")
|
||||
if len(fakeCloud.Calls) != 0 {
|
||||
t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls)
|
||||
}
|
||||
@ -324,12 +333,13 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
|
||||
ctx := api.NewContext()
|
||||
registry.CreateService(&api.Service{
|
||||
JSONBase: api.JSONBase{ID: "foo"},
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
})
|
||||
redirector := apiserver.Redirector(storage)
|
||||
location, err := redirector.ResourceLocation("foo")
|
||||
location, err := redirector.ResourceLocation(ctx, "foo")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
@ -342,7 +352,7 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
|
||||
|
||||
// Test error path
|
||||
registry.Err = fmt.Errorf("fake error")
|
||||
if _, err = redirector.ResourceLocation("foo"); err == nil {
|
||||
if _, err = redirector.ResourceLocation(ctx, "foo"); err == nil {
|
||||
t.Errorf("unexpected nil error")
|
||||
}
|
||||
}
|
||||
@ -361,7 +371,8 @@ func TestServiceRegistryList(t *testing.T) {
|
||||
Selector: map[string]string{"bar2": "baz2"},
|
||||
})
|
||||
registry.List.ResourceVersion = 1
|
||||
s, _ := storage.List(labels.Everything(), labels.Everything())
|
||||
ctx := api.NewContext()
|
||||
s, _ := storage.List(ctx, labels.Everything(), labels.Everything())
|
||||
sl := s.(*api.ServiceList)
|
||||
if len(fakeCloud.Calls) != 0 {
|
||||
t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls)
|
||||
|
Loading…
Reference in New Issue
Block a user