Skip to content

Commit 27f7fca

Browse files
author
Irfan Ur Rehman
committed
[Federation] Unit tests updated for wait for control plane pods in kubefed init
1 parent aed7eed commit 27f7fca

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

federation/pkg/kubefed/init/init_test.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func TestInitFederation(t *testing.T) {
168168
want = fmt.Sprintf("Federation control plane runs (dry run)\n")
169169
}
170170

171-
if got := buf.String(); got != want {
171+
if got := buf.String(); !strings.Contains(got, want) {
172172
t.Errorf("[%d] unexpected output: got: %s, want: %s", i, got, want)
173173
if cmdErrMsg != "" {
174174
t.Errorf("[%d] unexpected error message: %s", i, cmdErrMsg)
@@ -693,6 +693,38 @@ func fakeInitHostFactory(federationName, namespaceName, ip, dnsZoneName, image,
693693
},
694694
}
695695

696+
podList := v1.PodList{}
697+
apiServerPod := v1.Pod{
698+
TypeMeta: metav1.TypeMeta{
699+
Kind: "Pod",
700+
APIVersion: testapi.Extensions.GroupVersion().String(),
701+
},
702+
ObjectMeta: v1.ObjectMeta{
703+
Name: svcName,
704+
Namespace: namespaceName,
705+
},
706+
Status: v1.PodStatus{
707+
Phase: "Running",
708+
},
709+
}
710+
711+
ctrlMgrPod := v1.Pod{
712+
TypeMeta: metav1.TypeMeta{
713+
Kind: "Pod",
714+
APIVersion: testapi.Extensions.GroupVersion().String(),
715+
},
716+
ObjectMeta: v1.ObjectMeta{
717+
Name: cmName,
718+
Namespace: namespaceName,
719+
},
720+
Status: v1.PodStatus{
721+
Phase: "Running",
722+
},
723+
}
724+
725+
podList.Items = append(podList.Items, apiServerPod)
726+
podList.Items = append(podList.Items, ctrlMgrPod)
727+
696728
f, tf, codec, _ := cmdtesting.NewAPIFactory()
697729
extCodec := testapi.Extensions.Codec()
698730
ns := dynamic.ContentConfig().NegotiatedSerializer
@@ -794,7 +826,11 @@ func fakeInitHostFactory(federationName, namespaceName, ip, dnsZoneName, image,
794826
return nil, fmt.Errorf("Unexpected deployment object\n\tDiff: %s", diff.ObjectGoPrintDiff(got, want))
795827
}
796828
return &http.Response{StatusCode: http.StatusCreated, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(extCodec, &want)}, nil
829+
case p == "/api/v1/namespaces/federation-system/pods" && m == http.MethodGet:
830+
return &http.Response{StatusCode: http.StatusOK, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &podList)}, nil
831+
797832
default:
833+
fmt.Println("Unknon api called %v\n", p)
798834
return nil, fmt.Errorf("unexpected request: %#v\n%#v", req.URL, req)
799835
}
800836
}),

0 commit comments

Comments
 (0)