...
1
16
17 package certificates
18
19 import (
20 "testing"
21
22 "github.com/stretchr/testify/assert"
23
24 certificatesapi "k8s.io/api/certificates/v1"
25 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26 )
27
28 func TestIsCertificateRequestApproved(t *testing.T) {
29 testCases := []struct {
30 name string
31 conditions []certificatesapi.CertificateSigningRequestCondition
32 expectedIsApproved bool
33 }{
34 {
35 "Not any conditions exist",
36 nil,
37 false,
38 }, {
39 "Approved not exist and Denied exist",
40 []certificatesapi.CertificateSigningRequestCondition{
41 {
42 Type: certificatesapi.CertificateDenied,
43 },
44 },
45 false,
46 }, {
47 "Approved exist and Denied not exist",
48 []certificatesapi.CertificateSigningRequestCondition{
49 {
50 Type: certificatesapi.CertificateApproved,
51 },
52 },
53 true,
54 }, {
55 "Both of Approved and Denied exist",
56 []certificatesapi.CertificateSigningRequestCondition{
57 {
58 Type: certificatesapi.CertificateApproved,
59 },
60 {
61 Type: certificatesapi.CertificateDenied,
62 },
63 },
64 false,
65 },
66 }
67
68 for _, tc := range testCases {
69 csr := &certificatesapi.CertificateSigningRequest{
70 ObjectMeta: v1.ObjectMeta{
71 Name: "fake-csr",
72 },
73 Status: certificatesapi.CertificateSigningRequestStatus{
74 Conditions: tc.conditions,
75 },
76 }
77
78 assert.Equalf(t, tc.expectedIsApproved, IsCertificateRequestApproved(csr), "Failed to test: %s", tc.name)
79 }
80 }
81
View as plain text