diff --git a/pkg/controller/endpoint/endpoints_controller_test.go b/pkg/controller/endpoint/endpoints_controller_test.go index 5008b0a5ff7..c51a8abcac1 100644 --- a/pkg/controller/endpoint/endpoints_controller_test.go +++ b/pkg/controller/endpoint/endpoints_controller_test.go @@ -168,15 +168,28 @@ func TestSyncEndpointsProtocolTCP(t *testing.T) { // defer testServer.Close() client := client.NewOrDie(&client.Config{Host: testServer.URL, GroupVersion: testapi.Default.GroupVersion()}) endpoints := NewEndpointController(client, controller.NoResyncPeriodFunc) + addPods(endpoints.podStore.Store, ns, 1, 1, 0) endpoints.serviceStore.Store.Add(&api.Service{ ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns}, Spec: api.ServiceSpec{ Selector: map[string]string{}, - Ports: []api.ServicePort{{Port: 80}}, + Ports: []api.ServicePort{{Port: 80, TargetPort: intstr.FromInt(8080), Protocol: "TCP"}}, }, }) 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) { @@ -197,15 +210,28 @@ func TestSyncEndpointsProtocolUDP(t *testing.T) { // defer testServer.Close() client := client.NewOrDie(&client.Config{Host: testServer.URL, GroupVersion: testapi.Default.GroupVersion()}) endpoints := NewEndpointController(client, controller.NoResyncPeriodFunc) + addPods(endpoints.podStore.Store, ns, 1, 1, 0) endpoints.serviceStore.Store.Add(&api.Service{ ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: ns}, Spec: api.ServiceSpec{ Selector: map[string]string{}, - Ports: []api.ServicePort{{Port: 80}}, + Ports: []api.ServicePort{{Port: 80, TargetPort: intstr.FromInt(8080), Protocol: "UDP"}}, }, }) 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) { diff --git a/pkg/controller/replication/replication_controller_test.go b/pkg/controller/replication/replication_controller_test.go index 225872bb864..796b64d3652 100644 --- a/pkg/controller/replication/replication_controller_test.go +++ b/pkg/controller/replication/replication_controller_test.go @@ -295,7 +295,7 @@ func TestSyncReplicationControllerDormancy(t *testing.T) { // Setup a test server so we can lie about the current state of pods fakeHandler := utiltesting.FakeHandler{ StatusCode: 200, - ResponseBody: "", + ResponseBody: "{}", } testServer := httptest.NewServer(&fakeHandler) // TODO: Uncomment when fix #19254 diff --git a/pkg/util/testing/fake_handler.go b/pkg/util/testing/fake_handler.go index 3d3be4cd7f6..3fc9e3ed0aa 100644 --- a/pkg/util/testing/fake_handler.go +++ b/pkg/util/testing/fake_handler.go @@ -79,7 +79,7 @@ func (f *FakeHandler) ValidateRequestCount(t TestInterface, count int) bool { defer f.lock.Unlock() if f.requestCount != count { 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 return ok