|
1 | 1 | package resource_test
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "strings" |
| 5 | + |
4 | 6 | . "github.com/onsi/ginkgo"
|
| 7 | + . "github.com/onsi/ginkgo/extensions/table" |
5 | 8 | . "github.com/onsi/gomega"
|
6 | 9 |
|
7 | 10 | . "sigs.k8s.io/kubebuilder/pkg/model/resource"
|
@@ -73,24 +76,38 @@ var _ = Describe("Resource Options", func() {
|
73 | 76 | Expect(options.Validate().Error()).To(ContainSubstring("kind cannot be empty"))
|
74 | 77 | })
|
75 | 78 |
|
76 |
| - It("should fail if the Kind is not pascal cased", func() { |
77 |
| - // Base case |
78 |
| - options := &Options{Group: "crew", Version: "v1", Kind: "FirstMate"} |
79 |
| - Expect(options.Validate()).To(Succeed()) |
80 |
| - |
81 |
| - // Can't detect this case :( |
82 |
| - options = &Options{Group: "crew", Version: "v1", Kind: "Firstmate"} |
83 |
| - Expect(options.Validate()).To(Succeed()) |
84 |
| - |
85 |
| - options = &Options{Group: "crew", Version: "v1", Kind: "firstMate"} |
86 |
| - Expect(options.Validate()).NotTo(Succeed()) |
87 |
| - Expect(options.Validate().Error()).To(ContainSubstring( |
88 |
| - `kind must be PascalCase (expected FirstMate was firstMate)`)) |
| 79 | + DescribeTable("valid Kind values-according to core Kubernetes", |
| 80 | + func(kind string) { |
| 81 | + options := &Options{Group: "crew", Kind: kind, Version: "v1"} |
| 82 | + Expect(options.Validate()).To(Succeed()) |
| 83 | + }, |
| 84 | + Entry("should pass validation if Kind is camelcase", "FirstMate"), |
| 85 | + Entry("should pass validation if Kind has more than one caps at the start", "FIRSTMate"), |
| 86 | + ) |
| 87 | + |
| 88 | + It("should fail if Kind is too long", func() { |
| 89 | + kind := strings.Repeat("a", 64) |
| 90 | + |
| 91 | + options := &Options{Group: "crew", Kind: kind, Version: "v1"} |
| 92 | + err := options.Validate() |
| 93 | + Expect(err).To(MatchError(ContainSubstring("must be no more than 63 characters"))) |
| 94 | + }) |
89 | 95 |
|
90 |
| - options = &Options{Group: "crew", Version: "v1", Kind: "firstmate"} |
91 |
| - Expect(options.Validate()).NotTo(Succeed()) |
92 |
| - Expect(options.Validate().Error()).To(ContainSubstring( |
93 |
| - `kind must be PascalCase (expected Firstmate was firstmate)`)) |
| 96 | + DescribeTable("invalid Kind values-according to core Kubernetes", |
| 97 | + func(kind string) { |
| 98 | + options := &Options{Group: "crew", Kind: kind, Version: "v1"} |
| 99 | + Expect(options.Validate()).To(MatchError( |
| 100 | + ContainSubstring("a DNS-1035 label must consist of lower case alphanumeric characters"))) |
| 101 | + }, |
| 102 | + Entry("should fail validation if Kind contains whitespaces", "Something withSpaces"), |
| 103 | + Entry("should fail validation if Kind ends in -", "KindEndingIn-"), |
| 104 | + Entry("should fail validation if Kind starts with number", "0ValidityKind"), |
| 105 | + ) |
| 106 | + |
| 107 | + It("should fail if Kind starts with a lowercase character", func() { |
| 108 | + options := &Options{Group: "crew", Kind: "lOWERCASESTART", Version: "v1"} |
| 109 | + err := options.Validate() |
| 110 | + Expect(err).To(MatchError(ContainSubstring("Kind must start with an uppercase character"))) |
94 | 111 | })
|
95 | 112 | })
|
96 | 113 | })
|
0 commit comments