...
1
16
17 package deny
18
19 import (
20 "context"
21 "testing"
22
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/apiserver/pkg/admission"
25 admissiontesting "k8s.io/apiserver/pkg/admission/testing"
26 api "k8s.io/kubernetes/pkg/apis/core"
27 )
28
29 func TestAdmission(t *testing.T) {
30 handler := admissiontesting.WithReinvocationTesting(t, NewAlwaysDeny().(*alwaysDeny))
31 err := handler.Admit(context.TODO(), admission.NewAttributesRecord(nil, nil, api.Kind("kind").WithVersion("version"), "namespace", "name", api.Resource("resource").WithVersion("version"), "subresource", admission.Create, &metav1.CreateOptions{}, false, nil), nil)
32 if err == nil {
33 t.Error("Expected error returned from admission handler")
34 }
35 }
36
37 func TestHandles(t *testing.T) {
38 handler := NewAlwaysDeny()
39 tests := []admission.Operation{admission.Create, admission.Connect, admission.Update, admission.Delete}
40
41 for _, test := range tests {
42 if !handler.Handles(test) {
43 t.Errorf("Expected handling all operations, including: %v", test)
44 }
45 }
46 }
47
View as plain text