Skip to content

Commit

Permalink
Merge pull request #594 from freehan/bug-fix
Browse files Browse the repository at this point in the history
add unit test for GetZoneForNode helper func
  • Loading branch information
k8s-ci-robot authored Jan 2, 2019
2 parents 875e037 + b26979d commit a968d49
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/controller/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit a968d49

Please sign in to comment.