sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/machinery/marker_test.go (about) 1 /* 2 Copyright 2022 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 machinery 18 19 import ( 20 . "github.com/onsi/ginkgo/v2" 21 . "github.com/onsi/gomega" 22 ) 23 24 var _ = Describe("NerMarkerFor", func() { 25 DescribeTable("should create valid markers for known extensions", 26 func(path, comment string) { Expect(NewMarkerFor(path, "").comment).To(Equal(comment)) }, 27 Entry("for go files", "file.go", "//"), 28 Entry("for yaml files", "file.yaml", "#"), 29 Entry("for yaml files (short version)", "file.yml", "#"), 30 ) 31 32 It("should panic for unknown extensions", func() { 33 // testing panics require to use a function with no arguments 34 Expect(func() { NewMarkerFor("file.unkownext", "") }).To(Panic()) 35 }) 36 }) 37 38 var _ = Describe("Marker", func() { 39 Context("String", func() { 40 DescribeTable("should return the right string representation", 41 func(marker Marker, str string) { Expect(marker.String()).To(Equal(str)) }, 42 Entry("for go files", Marker{comment: "//", value: "test"}, "//+kubebuilder:scaffold:test"), 43 Entry("for yaml files", Marker{comment: "#", value: "test"}, "#+kubebuilder:scaffold:test"), 44 ) 45 }) 46 })