mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	test: make ValidateCount throw an error instead of a log
We can either fix it here or at every callsite. Every callsite is currently using this method incorrectly. Signed-off-by: Mike Danese <mikedanese@google.com>
This commit is contained in:
		@@ -168,15 +168,28 @@ func TestSyncEndpointsProtocolTCP(t *testing.T) {
 | 
				
			|||||||
	// defer testServer.Close()
 | 
						// defer testServer.Close()
 | 
				
			||||||
	client := client.NewOrDie(&client.Config{Host: testServer.URL, GroupVersion: testapi.Default.GroupVersion()})
 | 
						client := client.NewOrDie(&client.Config{Host: testServer.URL, GroupVersion: testapi.Default.GroupVersion()})
 | 
				
			||||||
	endpoints := NewEndpointController(client, controller.NoResyncPeriodFunc)
 | 
						endpoints := NewEndpointController(client, controller.NoResyncPeriodFunc)
 | 
				
			||||||
 | 
						addPods(endpoints.podStore.Store, ns, 1, 1, 0)
 | 
				
			||||||
	endpoints.serviceStore.Store.Add(&api.Service{
 | 
						endpoints.serviceStore.Store.Add(&api.Service{
 | 
				
			||||||
		ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns},
 | 
							ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns},
 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
							Spec: api.ServiceSpec{
 | 
				
			||||||
			Selector: map[string]string{},
 | 
								Selector: map[string]string{},
 | 
				
			||||||
			Ports:    []api.ServicePort{{Port: 80}},
 | 
								Ports:    []api.ServicePort{{Port: 80, TargetPort: intstr.FromInt(8080), Protocol: "TCP"}},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	endpoints.syncService(ns + "/foo")
 | 
						endpoints.syncService(ns + "/foo")
 | 
				
			||||||
	endpointsHandler.ValidateRequestCount(t, 0)
 | 
						endpointsHandler.ValidateRequestCount(t, 2)
 | 
				
			||||||
 | 
						data := runtime.EncodeOrDie(testapi.Default.Codec(), &api.Endpoints{
 | 
				
			||||||
 | 
							ObjectMeta: api.ObjectMeta{
 | 
				
			||||||
 | 
								Name:            "foo",
 | 
				
			||||||
 | 
								Namespace:       ns,
 | 
				
			||||||
 | 
								ResourceVersion: "1",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							Subsets: []api.EndpointSubset{{
 | 
				
			||||||
 | 
								Addresses: []api.EndpointAddress{{IP: "1.2.3.4", TargetRef: &api.ObjectReference{Kind: "Pod", Name: "pod0", Namespace: ns}}},
 | 
				
			||||||
 | 
								Ports:     []api.EndpointPort{{Port: 8080, Protocol: "TCP"}},
 | 
				
			||||||
 | 
							}},
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						endpointsHandler.ValidateRequest(t, testapi.Default.ResourcePath("endpoints", ns, "foo"), "PUT", &data)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestSyncEndpointsProtocolUDP(t *testing.T) {
 | 
					func TestSyncEndpointsProtocolUDP(t *testing.T) {
 | 
				
			||||||
@@ -197,15 +210,28 @@ func TestSyncEndpointsProtocolUDP(t *testing.T) {
 | 
				
			|||||||
	// defer testServer.Close()
 | 
						// defer testServer.Close()
 | 
				
			||||||
	client := client.NewOrDie(&client.Config{Host: testServer.URL, GroupVersion: testapi.Default.GroupVersion()})
 | 
						client := client.NewOrDie(&client.Config{Host: testServer.URL, GroupVersion: testapi.Default.GroupVersion()})
 | 
				
			||||||
	endpoints := NewEndpointController(client, controller.NoResyncPeriodFunc)
 | 
						endpoints := NewEndpointController(client, controller.NoResyncPeriodFunc)
 | 
				
			||||||
 | 
						addPods(endpoints.podStore.Store, ns, 1, 1, 0)
 | 
				
			||||||
	endpoints.serviceStore.Store.Add(&api.Service{
 | 
						endpoints.serviceStore.Store.Add(&api.Service{
 | 
				
			||||||
		ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns},
 | 
							ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns},
 | 
				
			||||||
		Spec: api.ServiceSpec{
 | 
							Spec: api.ServiceSpec{
 | 
				
			||||||
			Selector: map[string]string{},
 | 
								Selector: map[string]string{},
 | 
				
			||||||
			Ports:    []api.ServicePort{{Port: 80}},
 | 
								Ports:    []api.ServicePort{{Port: 80, TargetPort: intstr.FromInt(8080), Protocol: "UDP"}},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	endpoints.syncService(ns + "/foo")
 | 
						endpoints.syncService(ns + "/foo")
 | 
				
			||||||
	endpointsHandler.ValidateRequestCount(t, 0)
 | 
						endpointsHandler.ValidateRequestCount(t, 2)
 | 
				
			||||||
 | 
						data := runtime.EncodeOrDie(testapi.Default.Codec(), &api.Endpoints{
 | 
				
			||||||
 | 
							ObjectMeta: api.ObjectMeta{
 | 
				
			||||||
 | 
								Name:            "foo",
 | 
				
			||||||
 | 
								Namespace:       ns,
 | 
				
			||||||
 | 
								ResourceVersion: "1",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							Subsets: []api.EndpointSubset{{
 | 
				
			||||||
 | 
								Addresses: []api.EndpointAddress{{IP: "1.2.3.4", TargetRef: &api.ObjectReference{Kind: "Pod", Name: "pod0", Namespace: ns}}},
 | 
				
			||||||
 | 
								Ports:     []api.EndpointPort{{Port: 8080, Protocol: "UDP"}},
 | 
				
			||||||
 | 
							}},
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						endpointsHandler.ValidateRequest(t, testapi.Default.ResourcePath("endpoints", ns, "foo"), "PUT", &data)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
 | 
					func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -295,7 +295,7 @@ func TestSyncReplicationControllerDormancy(t *testing.T) {
 | 
				
			|||||||
	// Setup a test server so we can lie about the current state of pods
 | 
						// Setup a test server so we can lie about the current state of pods
 | 
				
			||||||
	fakeHandler := utiltesting.FakeHandler{
 | 
						fakeHandler := utiltesting.FakeHandler{
 | 
				
			||||||
		StatusCode:   200,
 | 
							StatusCode:   200,
 | 
				
			||||||
		ResponseBody: "",
 | 
							ResponseBody: "{}",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	testServer := httptest.NewServer(&fakeHandler)
 | 
						testServer := httptest.NewServer(&fakeHandler)
 | 
				
			||||||
	// TODO: Uncomment when fix #19254
 | 
						// TODO: Uncomment when fix #19254
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,7 +79,7 @@ func (f *FakeHandler) ValidateRequestCount(t TestInterface, count int) bool {
 | 
				
			|||||||
	defer f.lock.Unlock()
 | 
						defer f.lock.Unlock()
 | 
				
			||||||
	if f.requestCount != count {
 | 
						if f.requestCount != count {
 | 
				
			||||||
		ok = false
 | 
							ok = false
 | 
				
			||||||
		t.Logf("Expected %d call, but got %d. Only the last call is recorded and checked.", count, f.requestCount)
 | 
							t.Errorf("Expected %d call, but got %d. Only the last call is recorded and checked.", count, f.requestCount)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	f.hasBeenChecked = true
 | 
						f.hasBeenChecked = true
 | 
				
			||||||
	return ok
 | 
						return ok
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user