...

Source file src/k8s.io/kubernetes/pkg/controller/certificates/certificate_controller_utils_test.go

Documentation: k8s.io/kubernetes/pkg/controller/certificates

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    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