github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/api/validation/generic_test.go (about) 1 /* 2 Copyright 2021 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 validation 18 19 import "testing" 20 21 func TestMaskTrailingDash(t *testing.T) { 22 testCases := []struct { 23 beforeMasking string 24 expectedAfterMasking string 25 description string 26 }{ 27 { 28 beforeMasking: "", 29 expectedAfterMasking: "", 30 description: "empty string", 31 }, 32 { 33 beforeMasking: "-", 34 expectedAfterMasking: "-", 35 description: "only a single dash", 36 }, 37 { 38 beforeMasking: "-foo", 39 expectedAfterMasking: "-foo", 40 description: "has leading dash", 41 }, 42 { 43 beforeMasking: "-foo-", 44 expectedAfterMasking: "-foa", 45 description: "has both leading and trailing dashes", 46 }, 47 { 48 beforeMasking: "b-", 49 expectedAfterMasking: "a", 50 description: "has trailing dash", 51 }, 52 { 53 beforeMasking: "ab", 54 expectedAfterMasking: "ab", 55 description: "has neither leading nor trailing dashes", 56 }, 57 } 58 59 for _, tc := range testCases { 60 afterMasking := maskTrailingDash(tc.beforeMasking) 61 if afterMasking != tc.expectedAfterMasking { 62 t.Errorf("error in test case: %s. expected: %s, actual: %s", tc.description, tc.expectedAfterMasking, afterMasking) 63 } 64 } 65 }