mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-04 07:49:35 +00:00 
			
		
		
		
	Ensure that MockPodRegistry verifies the query it's passed.
This commit is contained in:
		@@ -72,6 +72,9 @@ func TestSyncEndpointsItems(t *testing.T) {
 | 
				
			|||||||
						},
 | 
											},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
 | 
									Labels: map[string]string{
 | 
				
			||||||
 | 
										"foo": "bar",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,8 +36,17 @@ func expectNoError(t *testing.T, err error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (registry *MockPodRegistry) ListPods(labels.Query) ([]api.Pod, error) {
 | 
					func (registry *MockPodRegistry) ListPods(query labels.Query) ([]api.Pod, error) {
 | 
				
			||||||
	return registry.pods, registry.err
 | 
						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) {
 | 
					func (registry *MockPodRegistry) GetPod(podId string) (*api.Pod, error) {
 | 
				
			||||||
@@ -62,7 +71,7 @@ func TestListPodsError(t *testing.T) {
 | 
				
			|||||||
	storage := PodRegistryStorage{
 | 
						storage := PodRegistryStorage{
 | 
				
			||||||
		registry: &mockRegistry,
 | 
							registry: &mockRegistry,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	pods, err := storage.List(nil)
 | 
						pods, err := storage.List(labels.Everything())
 | 
				
			||||||
	if err != mockRegistry.err {
 | 
						if err != mockRegistry.err {
 | 
				
			||||||
		t.Errorf("Expected %#v, Got %#v", mockRegistry.err, err)
 | 
							t.Errorf("Expected %#v, Got %#v", mockRegistry.err, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -76,7 +85,7 @@ func TestListEmptyPodList(t *testing.T) {
 | 
				
			|||||||
	storage := PodRegistryStorage{
 | 
						storage := PodRegistryStorage{
 | 
				
			||||||
		registry: &mockRegistry,
 | 
							registry: &mockRegistry,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	pods, err := storage.List(nil)
 | 
						pods, err := storage.List(labels.Everything())
 | 
				
			||||||
	expectNoError(t, err)
 | 
						expectNoError(t, err)
 | 
				
			||||||
	if len(pods.(api.PodList).Items) != 0 {
 | 
						if len(pods.(api.PodList).Items) != 0 {
 | 
				
			||||||
		t.Errorf("Unexpected non-zero pod list: %#v", pods)
 | 
							t.Errorf("Unexpected non-zero pod list: %#v", pods)
 | 
				
			||||||
@@ -101,7 +110,7 @@ func TestListPodList(t *testing.T) {
 | 
				
			|||||||
	storage := PodRegistryStorage{
 | 
						storage := PodRegistryStorage{
 | 
				
			||||||
		registry: &mockRegistry,
 | 
							registry: &mockRegistry,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	podsObj, err := storage.List(nil)
 | 
						podsObj, err := storage.List(labels.Everything())
 | 
				
			||||||
	pods := podsObj.(api.PodList)
 | 
						pods := podsObj.(api.PodList)
 | 
				
			||||||
	expectNoError(t, err)
 | 
						expectNoError(t, err)
 | 
				
			||||||
	if len(pods.Items) != 2 {
 | 
						if len(pods.Items) != 2 {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user