Skip to content

Commit

Permalink
test(kubernetes): GetClusterRole
Browse files Browse the repository at this point in the history
Signed-off-by: Chin-Ya Huang <[email protected]>
  • Loading branch information
c3y1huang committed Apr 29, 2024
1 parent e5d2c54 commit 915ba9c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions kubernetes/clusterrole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,48 @@ func (s *TestSuite) TestDeleteClusterRole(c *C) {
c.Assert(apierrors.IsNotFound(err), Equals, true, Commentf(test.ErrResultFmt, testName))
}
}

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

type testCase struct {
clusterRole *rbacv1.ClusterRole
expectNotFound bool
}
testCases := map[string]testCase{
"GetClusterRole(...):": {
clusterRole: &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
},
},
"GetClusterRole(...): not found": {
clusterRole: &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
},
expectNotFound: true,
},
}
for testName, testCase := range testCases {
c.Logf("testing kubernetes.%v", testName)

kubeClient := fake.NewSimpleClientset()

if !testCase.expectNotFound {
_, err := kubeClient.RbacV1().ClusterRoles().Create(ctx, testCase.clusterRole, metav1.CreateOptions{})
c.Assert(err, IsNil, Commentf(test.ErrErrorFmt, testName))
}

clusterRole, err := GetClusterRole(kubeClient, testCase.clusterRole.Name)
if testCase.expectNotFound {
c.Assert(apierrors.IsNotFound(err), Equals, true, Commentf(test.ErrResultFmt, testName))
return
}
c.Assert(err, IsNil, Commentf(test.ErrErrorFmt, testName))
c.Assert(clusterRole.Name, Equals, testCase.clusterRole.Name, Commentf(test.ErrResultFmt, testName))
}
}

0 comments on commit 915ba9c

Please sign in to comment.