diff --git a/modules/common/webhook/rfc_test.go b/modules/common/webhook/rfc_test.go new file mode 100644 index 00000000..30779a02 --- /dev/null +++ b/modules/common/webhook/rfc_test.go @@ -0,0 +1,60 @@ +/* +Copyright 2024 Red Hat + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package webhook + +import ( + "testing" + + "k8s.io/apimachinery/pkg/util/validation/field" + + . "github.com/onsi/gomega" +) + +func TestValidateDNS1123Label(t *testing.T) { + tests := []struct { + name string + keys []string + want bool + }{ + { + name: "req is higher then min", + keys: []string{"123"}, + want: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + g := NewWithT(t) + + p := field.NewPath("foo") + + errs := ValidateDNS1123Label(p, tt.keys) + + if tt.wantWarn { + g.Expect(warns).To(HaveLen(1)) + } else { + g.Expect(warns).To(BeEmpty()) + } + if tt.wantErr { + g.Expect(errs).To(HaveLen(1)) + } else { + g.Expect(errs).To(BeEmpty()) + } + }) + } +}