From 372e7b772761ac349780c2bcc4bc4b0b3ec465f6 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Tue, 17 Jun 2014 18:33:51 -0700 Subject: [PATCH] Ensure that MockPodRegistry verifies the query it's passed. --- pkg/registry/endpoints_test.go | 3 +++ pkg/registry/pod_registry_test.go | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/registry/endpoints_test.go b/pkg/registry/endpoints_test.go index 584e7d16576..af34ff23b7d 100644 --- a/pkg/registry/endpoints_test.go +++ b/pkg/registry/endpoints_test.go @@ -72,6 +72,9 @@ func TestSyncEndpointsItems(t *testing.T) { }, }, }, + Labels: map[string]string{ + "foo": "bar", + }, }, }, } diff --git a/pkg/registry/pod_registry_test.go b/pkg/registry/pod_registry_test.go index 3e6bda6208f..ab3223ef938 100644 --- a/pkg/registry/pod_registry_test.go +++ b/pkg/registry/pod_registry_test.go @@ -36,8 +36,17 @@ func expectNoError(t *testing.T, err error) { } } -func (registry *MockPodRegistry) ListPods(labels.Query) ([]api.Pod, error) { - return registry.pods, registry.err +func (registry *MockPodRegistry) ListPods(query labels.Query) ([]api.Pod, error) { + if registry.err != nil { + return registry.pods, registry.err + } + var filtered []api.Pod + for _, pod := range registry.pods { + if query.Matches(labels.Set(pod.Labels)) { + filtered = append(filtered, pod) + } + } + return filtered, nil } func (registry *MockPodRegistry) GetPod(podId string) (*api.Pod, error) { @@ -62,7 +71,7 @@ func TestListPodsError(t *testing.T) { storage := PodRegistryStorage{ registry: &mockRegistry, } - pods, err := storage.List(nil) + pods, err := storage.List(labels.Everything()) if err != mockRegistry.err { t.Errorf("Expected %#v, Got %#v", mockRegistry.err, err) } @@ -76,7 +85,7 @@ func TestListEmptyPodList(t *testing.T) { storage := PodRegistryStorage{ registry: &mockRegistry, } - pods, err := storage.List(nil) + pods, err := storage.List(labels.Everything()) expectNoError(t, err) if len(pods.(api.PodList).Items) != 0 { t.Errorf("Unexpected non-zero pod list: %#v", pods) @@ -101,7 +110,7 @@ func TestListPodList(t *testing.T) { storage := PodRegistryStorage{ registry: &mockRegistry, } - podsObj, err := storage.List(nil) + podsObj, err := storage.List(labels.Everything()) pods := podsObj.(api.PodList) expectNoError(t, err) if len(pods.Items) != 2 {