From b26979dc04fbe4d0aab4b8d7f5b72325beddf02d Mon Sep 17 00:00:00 2001 From: Minhan Xia Date: Wed, 2 Jan 2019 14:35:13 -0800 Subject: [PATCH] add unit test for GetZoneForNode helper func --- pkg/controller/translator/translator_test.go | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/controller/translator/translator_test.go b/pkg/controller/translator/translator_test.go index 24808b20a5..0815403fcb 100644 --- a/pkg/controller/translator/translator_test.go +++ b/pkg/controller/translator/translator_test.go @@ -527,6 +527,41 @@ func TestGatherEndpointPorts(t *testing.T) { } } +func TestGetZoneForNode(t *testing.T) { + nodeName := "node" + zone := "us-central1-a" + translator := fakeTranslator(true, false) + translator.ctx.NodeInformer.GetIndexer().Add(&apiv1.Node{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: nodeName, + Labels: map[string]string{ + annotations.ZoneKey: zone, + }, + }, + Spec: apiv1.NodeSpec{ + Unschedulable: false, + }, + Status: apiv1.NodeStatus{ + Conditions: []apiv1.NodeCondition{ + { + Type: apiv1.NodeReady, + Status: apiv1.ConditionFalse, + }, + }, + }, + }) + + ret, err := translator.GetZoneForNode(nodeName) + if err != nil { + t.Errorf("Expect error = nil, but got %v", err) + } + + if zone != ret { + t.Errorf("Expect zone = %q, but got %q", zone, ret) + } +} + func newDefaultEndpoint(name string) *apiv1.Endpoints { return &apiv1.Endpoints{ ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: "ns"},