Skip to content

Commit

Permalink
test(kubernetes): IsDaemonSetReady
Browse files Browse the repository at this point in the history
Signed-off-by: Chin-Ya Huang <[email protected]>
  • Loading branch information
c3y1huang committed Jun 12, 2024
1 parent 15070b8 commit b6872b9
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions kubernetes/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,51 @@ func (s *TestSuite) TestGetDaemonSet(c *C) {
c.Assert(daemonSet.Name, Equals, testCase.daemonSet.Name, Commentf(test.ErrResultFmt, testName))
}
}

func (s *TestSuite) TestIsDaemonSetReady(c *C) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

type testCase struct {
daemonSet *appsv1.DaemonSet
expectedReady bool
}
testCases := map[string]testCase{
"IsDaemonSetReady(...):": {
daemonSet: &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
},
Status: appsv1.DaemonSetStatus{
NumberReady: 1,
DesiredNumberScheduled: 1,
},
},
expectedReady: true,
},
"IsDaemonSetReady(...): not ready": {
daemonSet: &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
},
Status: appsv1.DaemonSetStatus{
NumberReady: 0,
DesiredNumberScheduled: 1,
},
},
expectedReady: false,
},
}
for testName, testCase := range testCases {
c.Logf("testing kubernetes.%v", testName)

kubeClient := fake.NewSimpleClientset()
_, err := kubeClient.AppsV1().DaemonSets(testCase.daemonSet.Namespace).Create(ctx, testCase.daemonSet, metav1.CreateOptions{})
c.Assert(err, IsNil, Commentf(test.ErrErrorFmt, testName))

ready := IsDaemonSetReady(testCase.daemonSet)
c.Assert(ready, Equals, testCase.expectedReady, Commentf(test.ErrResultFmt, testName))
}
}

0 comments on commit b6872b9

Please sign in to comment.