Skip to content

Commit 78de0ea

Browse files
Allow group names with dash
1 parent b46a3c2 commit 78de0ea

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pkg/scaffold/v1/resource/resource.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/gobuffalo/flect"
2525
)
2626

27+
const GroupMatchRegex = "^[a-z-]+$"
28+
2729
// Resource contains the information required to scaffold files for a resource.
2830
type Resource struct {
2931
// Namespaced is true if the resource is namespaced
@@ -64,9 +66,9 @@ func (r *Resource) Validate() error {
6466
r.Resource = flect.Pluralize(strings.ToLower(r.Kind))
6567
}
6668

67-
groupMatch := regexp.MustCompile("^[a-z]+$")
69+
groupMatch := regexp.MustCompile(GroupMatchRegex)
6870
if !groupMatch.MatchString(r.Group) {
69-
return fmt.Errorf("group must match ^[a-z]+$ (was %s)", r.Group)
71+
return fmt.Errorf("group must match %s (was %s)", GroupMatchRegex, r.Group)
7072
}
7173

7274
versionMatch := regexp.MustCompile("^v\\d+(alpha\\d+|beta\\d+)?$")

pkg/scaffold/v1/resource/resource_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ var _ = Describe("Resource", func() {
3030
It("should fail if the Group is not all lowercase", func() {
3131
instance := &resource.Resource{Group: "Crew", Version: "v1", Kind: "FirstMate"}
3232
Expect(instance.Validate()).NotTo(Succeed())
33-
Expect(instance.Validate().Error()).To(ContainSubstring("group must match ^[a-z]+$ (was Crew)"))
33+
Expect(instance.Validate().Error()).To(ContainSubstring("group must match %s (was Crew)", resource.GroupMatchRegex))
3434
})
3535

3636
It("should fail if the Group contains non-alpha characters", func() {
3737
instance := &resource.Resource{Group: "crew1", Version: "v1", Kind: "FirstMate"}
3838
Expect(instance.Validate()).NotTo(Succeed())
39-
Expect(instance.Validate().Error()).To(ContainSubstring("group must match ^[a-z]+$ (was crew1)"))
39+
Expect(instance.Validate().Error()).To(ContainSubstring("group must match %s (was crew1)", resource.GroupMatchRegex))
4040
})
4141

4242
It("should fail if the Version is not specified", func() {

0 commit comments

Comments
 (0)