mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 04:27:54 +00:00
Fixup unit tests
This commit is contained in:
parent
341e404290
commit
c6eb371c93
@ -146,17 +146,17 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestListEmptyPods(t *testing.T) {
|
func TestListEmptyPods(t *testing.T) {
|
||||||
ctx := api.NewContext()
|
ns := api.NamespaceDefault
|
||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "GET", Path: "/pods"},
|
Request: testRequest{Method: "GET", Path: "/pods"},
|
||||||
Response: Response{StatusCode: 200, Body: &api.PodList{}},
|
Response: Response{StatusCode: 200, Body: &api.PodList{}},
|
||||||
}
|
}
|
||||||
podList, err := c.Setup().ListPods(ctx, labels.Everything())
|
podList, err := c.Setup().Pods(ns).List(labels.Everything())
|
||||||
c.Validate(t, podList, err)
|
c.Validate(t, podList, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListPods(t *testing.T) {
|
func TestListPods(t *testing.T) {
|
||||||
ctx := api.NewDefaultContext()
|
ns := api.NamespaceDefault
|
||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "GET", Path: "/pods"},
|
Request: testRequest{Method: "GET", Path: "/pods"},
|
||||||
Response: Response{StatusCode: 200,
|
Response: Response{StatusCode: 200,
|
||||||
@ -177,7 +177,7 @@ func TestListPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedPodList, err := c.Setup().ListPods(ctx, labels.Everything())
|
receivedPodList, err := c.Setup().Pods(ns).List(labels.Everything())
|
||||||
c.Validate(t, receivedPodList, err)
|
c.Validate(t, receivedPodList, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ func validateLabels(a, b string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestListPodsLabels(t *testing.T) {
|
func TestListPodsLabels(t *testing.T) {
|
||||||
ctx := api.NewDefaultContext()
|
ns := api.NamespaceDefault
|
||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "GET", Path: "/pods", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}},
|
Request: testRequest{Method: "GET", Path: "/pods", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}},
|
||||||
Response: Response{
|
Response: Response{
|
||||||
@ -213,12 +213,12 @@ func TestListPodsLabels(t *testing.T) {
|
|||||||
c.Setup()
|
c.Setup()
|
||||||
c.QueryValidator["labels"] = validateLabels
|
c.QueryValidator["labels"] = validateLabels
|
||||||
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
||||||
receivedPodList, err := c.ListPods(ctx, selector)
|
receivedPodList, err := c.Pods(ns).List(selector)
|
||||||
c.Validate(t, receivedPodList, err)
|
c.Validate(t, receivedPodList, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetPod(t *testing.T) {
|
func TestGetPod(t *testing.T) {
|
||||||
ctx := api.NewDefaultContext()
|
ns := api.NamespaceDefault
|
||||||
c := &testClient{
|
c := &testClient{
|
||||||
Request: testRequest{Method: "GET", Path: "/pods/foo"},
|
Request: testRequest{Method: "GET", Path: "/pods/foo"},
|
||||||
Response: Response{
|
Response: Response{
|
||||||
@ -236,7 +236,7 @@ func TestGetPod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedPod, err := c.Setup().GetPod(ctx, "foo")
|
receivedPod, err := c.Setup().Pods(ns).Get("foo")
|
||||||
c.Validate(t, receivedPod, err)
|
c.Validate(t, receivedPod, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ func TestDeletePod(t *testing.T) {
|
|||||||
Request: testRequest{Method: "DELETE", Path: "/pods/foo"},
|
Request: testRequest{Method: "DELETE", Path: "/pods/foo"},
|
||||||
Response: Response{StatusCode: 200},
|
Response: Response{StatusCode: 200},
|
||||||
}
|
}
|
||||||
err := c.Setup().DeletePod(api.NewDefaultContext(), "foo")
|
err := c.Setup().Pods(api.NamespaceDefault).Delete("foo")
|
||||||
c.Validate(t, nil, err)
|
c.Validate(t, nil, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ func TestCreatePod(t *testing.T) {
|
|||||||
Body: requestPod,
|
Body: requestPod,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedPod, err := c.Setup().CreatePod(api.NewDefaultContext(), requestPod)
|
receivedPod, err := c.Setup().Pods(api.NamespaceDefault).Create(requestPod)
|
||||||
c.Validate(t, receivedPod, err)
|
c.Validate(t, receivedPod, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ func TestUpdatePod(t *testing.T) {
|
|||||||
Request: testRequest{Method: "PUT", Path: "/pods/foo"},
|
Request: testRequest{Method: "PUT", Path: "/pods/foo"},
|
||||||
Response: Response{StatusCode: 200, Body: requestPod},
|
Response: Response{StatusCode: 200, Body: requestPod},
|
||||||
}
|
}
|
||||||
receivedPod, err := c.Setup().UpdatePod(api.NewDefaultContext(), requestPod)
|
receivedPod, err := c.Setup().Pods(api.NamespaceDefault).Update(requestPod)
|
||||||
c.Validate(t, receivedPod, err)
|
c.Validate(t, receivedPod, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +316,7 @@ func TestListControllers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedControllerList, err := c.Setup().ListReplicationControllers(api.NewContext(), labels.Everything())
|
receivedControllerList, err := c.Setup().ReplicationControllers(api.NamespaceAll).List(labels.Everything())
|
||||||
c.Validate(t, receivedControllerList, err)
|
c.Validate(t, receivedControllerList, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ func TestGetController(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedController, err := c.Setup().GetReplicationController(api.NewDefaultContext(), "foo")
|
receivedController, err := c.Setup().ReplicationControllers(api.NamespaceDefault).Get("foo")
|
||||||
c.Validate(t, receivedController, err)
|
c.Validate(t, receivedController, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +366,7 @@ func TestUpdateController(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedController, err := c.Setup().UpdateReplicationController(api.NewDefaultContext(), requestController)
|
receivedController, err := c.Setup().ReplicationControllers(api.NamespaceDefault).Update(requestController)
|
||||||
c.Validate(t, receivedController, err)
|
c.Validate(t, receivedController, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ func TestDeleteController(t *testing.T) {
|
|||||||
Request: testRequest{Method: "DELETE", Path: "/replicationControllers/foo"},
|
Request: testRequest{Method: "DELETE", Path: "/replicationControllers/foo"},
|
||||||
Response: Response{StatusCode: 200},
|
Response: Response{StatusCode: 200},
|
||||||
}
|
}
|
||||||
err := c.Setup().DeleteReplicationController(api.NewDefaultContext(), "foo")
|
err := c.Setup().ReplicationControllers(api.NamespaceDefault).Delete("foo")
|
||||||
c.Validate(t, nil, err)
|
c.Validate(t, nil, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ func TestCreateController(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedController, err := c.Setup().CreateReplicationController(api.NewDefaultContext(), requestController)
|
receivedController, err := c.Setup().ReplicationControllers(api.NamespaceDefault).Create(requestController)
|
||||||
c.Validate(t, receivedController, err)
|
c.Validate(t, receivedController, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,7 +436,7 @@ func TestListServices(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedServiceList, err := c.Setup().ListServices(api.NewDefaultContext(), labels.Everything())
|
receivedServiceList, err := c.Setup().Services(api.NamespaceDefault).List(labels.Everything())
|
||||||
t.Logf("received services: %v %#v", err, receivedServiceList)
|
t.Logf("received services: %v %#v", err, receivedServiceList)
|
||||||
c.Validate(t, receivedServiceList, err)
|
c.Validate(t, receivedServiceList, err)
|
||||||
}
|
}
|
||||||
@ -466,7 +466,7 @@ func TestListServicesLabels(t *testing.T) {
|
|||||||
c.Setup()
|
c.Setup()
|
||||||
c.QueryValidator["labels"] = validateLabels
|
c.QueryValidator["labels"] = validateLabels
|
||||||
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
|
||||||
receivedServiceList, err := c.ListServices(api.NewDefaultContext(), selector)
|
receivedServiceList, err := c.Services(api.NamespaceDefault).List(selector)
|
||||||
c.Validate(t, receivedServiceList, err)
|
c.Validate(t, receivedServiceList, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ func TestGetService(t *testing.T) {
|
|||||||
Request: testRequest{Method: "GET", Path: "/services/1"},
|
Request: testRequest{Method: "GET", Path: "/services/1"},
|
||||||
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
||||||
}
|
}
|
||||||
response, err := c.Setup().GetService(api.NewDefaultContext(), "1")
|
response, err := c.Setup().Services(api.NamespaceDefault).Get("1")
|
||||||
c.Validate(t, response, err)
|
c.Validate(t, response, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,7 +484,7 @@ func TestCreateService(t *testing.T) {
|
|||||||
Request: testRequest{Method: "POST", Path: "/services", Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
Request: testRequest{Method: "POST", Path: "/services", Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
||||||
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
|
||||||
}
|
}
|
||||||
response, err := c.Setup().CreateService(api.NewDefaultContext(), &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}})
|
response, err := c.Setup().Services(api.NamespaceDefault).Create(&api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}})
|
||||||
c.Validate(t, response, err)
|
c.Validate(t, response, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,7 +494,7 @@ func TestUpdateService(t *testing.T) {
|
|||||||
Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: svc},
|
Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: svc},
|
||||||
Response: Response{StatusCode: 200, Body: svc},
|
Response: Response{StatusCode: 200, Body: svc},
|
||||||
}
|
}
|
||||||
response, err := c.Setup().UpdateService(api.NewDefaultContext(), svc)
|
response, err := c.Setup().Services(api.NamespaceDefault).Update(svc)
|
||||||
c.Validate(t, response, err)
|
c.Validate(t, response, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,7 +503,7 @@ func TestDeleteService(t *testing.T) {
|
|||||||
Request: testRequest{Method: "DELETE", Path: "/services/1"},
|
Request: testRequest{Method: "DELETE", Path: "/services/1"},
|
||||||
Response: Response{StatusCode: 200},
|
Response: Response{StatusCode: 200},
|
||||||
}
|
}
|
||||||
err := c.Setup().DeleteService(api.NewDefaultContext(), "1")
|
err := c.Setup().Services(api.NamespaceDefault).Delete("1")
|
||||||
c.Validate(t, nil, err)
|
c.Validate(t, nil, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +521,7 @@ func TestListEndpooints(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedEndpointsList, err := c.Setup().ListEndpoints(api.NewDefaultContext(), labels.Everything())
|
receivedEndpointsList, err := c.Setup().Endpoints(api.NamespaceDefault).List(labels.Everything())
|
||||||
c.Validate(t, receivedEndpointsList, err)
|
c.Validate(t, receivedEndpointsList, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,7 +530,7 @@ func TestGetEndpoints(t *testing.T) {
|
|||||||
Request: testRequest{Method: "GET", Path: "/endpoints/endpoint-1"},
|
Request: testRequest{Method: "GET", Path: "/endpoints/endpoint-1"},
|
||||||
Response: Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}},
|
Response: Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}},
|
||||||
}
|
}
|
||||||
response, err := c.Setup().GetEndpoints(api.NewDefaultContext(), "endpoint-1")
|
response, err := c.Setup().Endpoints(api.NamespaceDefault).Get("endpoint-1")
|
||||||
c.Validate(t, response, err)
|
c.Validate(t, response, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,7 +566,7 @@ func TestListMinions(t *testing.T) {
|
|||||||
Request: testRequest{Method: "GET", Path: "/minions"},
|
Request: testRequest{Method: "GET", Path: "/minions"},
|
||||||
Response: Response{StatusCode: 200, Body: &api.MinionList{ListMeta: api.ListMeta{ResourceVersion: "1"}}},
|
Response: Response{StatusCode: 200, Body: &api.MinionList{ListMeta: api.ListMeta{ResourceVersion: "1"}}},
|
||||||
}
|
}
|
||||||
response, err := c.Setup().ListMinions()
|
response, err := c.Setup().Minions().List()
|
||||||
c.Validate(t, response, err)
|
c.Validate(t, response, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,7 +590,7 @@ func TestCreateMinion(t *testing.T) {
|
|||||||
Body: requestMinion,
|
Body: requestMinion,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
receivedMinion, err := c.Setup().CreateMinion(requestMinion)
|
receivedMinion, err := c.Setup().Minions().Create(requestMinion)
|
||||||
c.Validate(t, receivedMinion, err)
|
c.Validate(t, receivedMinion, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,6 +599,6 @@ func TestDeleteMinion(t *testing.T) {
|
|||||||
Request: testRequest{Method: "DELETE", Path: "/minions/foo"},
|
Request: testRequest{Method: "DELETE", Path: "/minions/foo"},
|
||||||
Response: Response{StatusCode: 200},
|
Response: Response{StatusCode: 200},
|
||||||
}
|
}
|
||||||
err := c.Setup().DeleteMinion("foo")
|
err := c.Setup().Minions().Delete("foo")
|
||||||
c.Validate(t, nil, err)
|
c.Validate(t, nil, err)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ type testEventRecorder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateEvent records the event for testing.
|
// CreateEvent records the event for testing.
|
||||||
func (t *testEventRecorder) CreateEvent(e *api.Event) (*api.Event, error) {
|
func (t *testEventRecorder) Create(e *api.Event) (*api.Event, error) {
|
||||||
if t.OnEvent != nil {
|
if t.OnEvent != nil {
|
||||||
return t.OnEvent(e)
|
return t.OnEvent(e)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
@ -44,20 +43,20 @@ func makeURL(suffix string) string {
|
|||||||
|
|
||||||
type FakePodControl struct {
|
type FakePodControl struct {
|
||||||
controllerSpec []api.ReplicationController
|
controllerSpec []api.ReplicationController
|
||||||
deletePodID []string
|
deletePodName []string
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakePodControl) createReplica(ctx api.Context, spec api.ReplicationController) {
|
func (f *FakePodControl) createReplica(namespace string, spec api.ReplicationController) {
|
||||||
f.lock.Lock()
|
f.lock.Lock()
|
||||||
defer f.lock.Unlock()
|
defer f.lock.Unlock()
|
||||||
f.controllerSpec = append(f.controllerSpec, spec)
|
f.controllerSpec = append(f.controllerSpec, spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakePodControl) deletePod(ctx api.Context, podID string) error {
|
func (f *FakePodControl) deletePod(namespace string, podName string) error {
|
||||||
f.lock.Lock()
|
f.lock.Lock()
|
||||||
defer f.lock.Unlock()
|
defer f.lock.Unlock()
|
||||||
f.deletePodID = append(f.deletePodID, podID)
|
f.deletePodName = append(f.deletePodName, podName)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,8 +101,8 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
|
|||||||
if len(fakePodControl.controllerSpec) != expectedCreates {
|
if len(fakePodControl.controllerSpec) != expectedCreates {
|
||||||
t.Errorf("Unexpected number of creates. Expected %d, saw %d\n", expectedCreates, len(fakePodControl.controllerSpec))
|
t.Errorf("Unexpected number of creates. Expected %d, saw %d\n", expectedCreates, len(fakePodControl.controllerSpec))
|
||||||
}
|
}
|
||||||
if len(fakePodControl.deletePodID) != expectedDeletes {
|
if len(fakePodControl.deletePodName) != expectedDeletes {
|
||||||
t.Errorf("Unexpected number of deletes. Expected %d, saw %d\n", expectedDeletes, len(fakePodControl.deletePodID))
|
t.Errorf("Unexpected number of deletes. Expected %d, saw %d\n", expectedDeletes, len(fakePodControl.deletePodName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +167,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateReplica(t *testing.T) {
|
func TestCreateReplica(t *testing.T) {
|
||||||
ctx := api.NewDefaultContext()
|
ns := api.NamespaceDefault
|
||||||
body := runtime.EncodeOrDie(testapi.Codec(), &api.Pod{})
|
body := runtime.EncodeOrDie(testapi.Codec(), &api.Pod{})
|
||||||
fakeHandler := util.FakeHandler{
|
fakeHandler := util.FakeHandler{
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
@ -205,7 +204,7 @@ func TestCreateReplica(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
podControl.createReplica(ctx, controllerSpec)
|
podControl.createReplica(ns, controllerSpec)
|
||||||
|
|
||||||
expectedPod := api.Pod{
|
expectedPod := api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
@ -322,12 +321,9 @@ type FakeWatcher struct {
|
|||||||
*client.Fake
|
*client.Fake
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fw FakeWatcher) WatchReplicationControllers(ctx api.Context, l, f labels.Selector, rv string) (watch.Interface, error) {
|
|
||||||
return fw.w, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWatchControllers(t *testing.T) {
|
func TestWatchControllers(t *testing.T) {
|
||||||
client := FakeWatcher{watch.NewFake(), &client.Fake{}}
|
fakeWatch := watch.NewFake()
|
||||||
|
client := &client.Fake{Watch: fakeWatch}
|
||||||
manager := NewReplicationManager(client)
|
manager := NewReplicationManager(client)
|
||||||
var testControllerSpec api.ReplicationController
|
var testControllerSpec api.ReplicationController
|
||||||
received := make(chan struct{})
|
received := make(chan struct{})
|
||||||
@ -344,7 +340,8 @@ func TestWatchControllers(t *testing.T) {
|
|||||||
|
|
||||||
// Test normal case
|
// Test normal case
|
||||||
testControllerSpec.Name = "foo"
|
testControllerSpec.Name = "foo"
|
||||||
client.w.Add(&testControllerSpec)
|
|
||||||
|
fakeWatch.Add(&testControllerSpec)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-received:
|
case <-received:
|
||||||
|
@ -36,7 +36,7 @@ func validateAction(expectedAction, actualAction client.FakeAction, t *testing.T
|
|||||||
|
|
||||||
func TestUpdateWithPods(t *testing.T) {
|
func TestUpdateWithPods(t *testing.T) {
|
||||||
fakeClient := client.Fake{
|
fakeClient := client.Fake{
|
||||||
Pods: api.PodList{
|
PodsList: api.PodList{
|
||||||
Items: []api.Pod{
|
Items: []api.Pod{
|
||||||
{ObjectMeta: api.ObjectMeta{Name: "pod-1"}},
|
{ObjectMeta: api.ObjectMeta{Name: "pod-1"}},
|
||||||
{ObjectMeta: api.ObjectMeta{Name: "pod-2"}},
|
{ObjectMeta: api.ObjectMeta{Name: "pod-2"}},
|
||||||
@ -67,7 +67,7 @@ func TestUpdateNoPods(t *testing.T) {
|
|||||||
|
|
||||||
func TestUpdateWithNewImage(t *testing.T) {
|
func TestUpdateWithNewImage(t *testing.T) {
|
||||||
fakeClient := client.Fake{
|
fakeClient := client.Fake{
|
||||||
Pods: api.PodList{
|
PodsList: api.PodList{
|
||||||
Items: []api.Pod{
|
Items: []api.Pod{
|
||||||
{ObjectMeta: api.ObjectMeta{Name: "pod-1"}},
|
{ObjectMeta: api.ObjectMeta{Name: "pod-1"}},
|
||||||
{ObjectMeta: api.ObjectMeta{Name: "pod-2"}},
|
{ObjectMeta: api.ObjectMeta{Name: "pod-2"}},
|
||||||
|
@ -32,7 +32,7 @@ func TestServices(t *testing.T) {
|
|||||||
fakeWatch := watch.NewFake()
|
fakeWatch := watch.NewFake()
|
||||||
fakeClient := &client.Fake{Watch: fakeWatch}
|
fakeClient := &client.Fake{Watch: fakeWatch}
|
||||||
services := make(chan ServiceUpdate)
|
services := make(chan ServiceUpdate)
|
||||||
source := SourceAPI{client: fakeClient, services: services}
|
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), services: services}
|
||||||
resourceVersion := "1"
|
resourceVersion := "1"
|
||||||
go func() {
|
go func() {
|
||||||
// called twice
|
// called twice
|
||||||
@ -84,7 +84,7 @@ func TestServicesFromZero(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
services := make(chan ServiceUpdate)
|
services := make(chan ServiceUpdate)
|
||||||
source := SourceAPI{client: fakeClient, services: services}
|
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), services: services}
|
||||||
resourceVersion := ""
|
resourceVersion := ""
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
@ -112,7 +112,7 @@ func TestServicesFromZero(t *testing.T) {
|
|||||||
func TestServicesError(t *testing.T) {
|
func TestServicesError(t *testing.T) {
|
||||||
fakeClient := &client.Fake{Err: errors.New("test")}
|
fakeClient := &client.Fake{Err: errors.New("test")}
|
||||||
services := make(chan ServiceUpdate)
|
services := make(chan ServiceUpdate)
|
||||||
source := SourceAPI{client: fakeClient, services: services}
|
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), services: services}
|
||||||
resourceVersion := "1"
|
resourceVersion := "1"
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
@ -133,7 +133,7 @@ func TestServicesError(t *testing.T) {
|
|||||||
func TestServicesFromZeroError(t *testing.T) {
|
func TestServicesFromZeroError(t *testing.T) {
|
||||||
fakeClient := &client.Fake{Err: errors.New("test")}
|
fakeClient := &client.Fake{Err: errors.New("test")}
|
||||||
services := make(chan ServiceUpdate)
|
services := make(chan ServiceUpdate)
|
||||||
source := SourceAPI{client: fakeClient, services: services}
|
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), services: services}
|
||||||
resourceVersion := ""
|
resourceVersion := ""
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
@ -157,7 +157,7 @@ func TestEndpoints(t *testing.T) {
|
|||||||
fakeWatch := watch.NewFake()
|
fakeWatch := watch.NewFake()
|
||||||
fakeClient := &client.Fake{Watch: fakeWatch}
|
fakeClient := &client.Fake{Watch: fakeWatch}
|
||||||
endpoints := make(chan EndpointsUpdate)
|
endpoints := make(chan EndpointsUpdate)
|
||||||
source := SourceAPI{client: fakeClient, endpoints: endpoints}
|
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), endpoints: endpoints}
|
||||||
resourceVersion := "1"
|
resourceVersion := "1"
|
||||||
go func() {
|
go func() {
|
||||||
// called twice
|
// called twice
|
||||||
@ -209,7 +209,7 @@ func TestEndpointsFromZero(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
endpoints := make(chan EndpointsUpdate)
|
endpoints := make(chan EndpointsUpdate)
|
||||||
source := SourceAPI{client: fakeClient, endpoints: endpoints}
|
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), endpoints: endpoints}
|
||||||
resourceVersion := ""
|
resourceVersion := ""
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
@ -237,7 +237,7 @@ func TestEndpointsFromZero(t *testing.T) {
|
|||||||
func TestEndpointsError(t *testing.T) {
|
func TestEndpointsError(t *testing.T) {
|
||||||
fakeClient := &client.Fake{Err: errors.New("test")}
|
fakeClient := &client.Fake{Err: errors.New("test")}
|
||||||
endpoints := make(chan EndpointsUpdate)
|
endpoints := make(chan EndpointsUpdate)
|
||||||
source := SourceAPI{client: fakeClient, endpoints: endpoints}
|
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), endpoints: endpoints}
|
||||||
resourceVersion := "1"
|
resourceVersion := "1"
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
@ -258,7 +258,7 @@ func TestEndpointsError(t *testing.T) {
|
|||||||
func TestEndpointsFromZeroError(t *testing.T) {
|
func TestEndpointsFromZeroError(t *testing.T) {
|
||||||
fakeClient := &client.Fake{Err: errors.New("test")}
|
fakeClient := &client.Fake{Err: errors.New("test")}
|
||||||
endpoints := make(chan EndpointsUpdate)
|
endpoints := make(chan EndpointsUpdate)
|
||||||
source := SourceAPI{client: fakeClient, endpoints: endpoints}
|
source := SourceAPI{servicesWatcher: fakeClient.Services(api.NamespaceAll), endpointsWatcher: fakeClient.Endpoints(api.NamespaceAll), endpoints: endpoints}
|
||||||
resourceVersion := ""
|
resourceVersion := ""
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -385,7 +385,7 @@ func TestGetPodCloud(t *testing.T) {
|
|||||||
|
|
||||||
func TestMakePodStatus(t *testing.T) {
|
func TestMakePodStatus(t *testing.T) {
|
||||||
fakeClient := client.Fake{
|
fakeClient := client.Fake{
|
||||||
Minions: api.MinionList{
|
MinionsList: api.MinionList{
|
||||||
Items: []api.Minion{
|
Items: []api.Minion{
|
||||||
{
|
{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "machine"},
|
ObjectMeta: api.ObjectMeta{Name: "machine"},
|
||||||
@ -517,7 +517,7 @@ func TestMakePodStatus(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if status, err := getPodStatus(test.pod, &fakeClient); status != test.status {
|
if status, err := getPodStatus(test.pod, fakeClient.Minions()); status != test.status {
|
||||||
t.Errorf("In test %s, expected %v, got %v", test.test, test.status, status)
|
t.Errorf("In test %s, expected %v, got %v", test.test, test.status, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("In test %s, unexpected error: %v", test.test, err)
|
t.Errorf("In test %s, unexpected error: %v", test.test, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user