File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ import (
24
24
"github.com/gobuffalo/flect"
25
25
)
26
26
27
+ const GroupMatchRegex = "^[a-z-]+$"
28
+
27
29
// Resource contains the information required to scaffold files for a resource.
28
30
type Resource struct {
29
31
// Namespaced is true if the resource is namespaced
@@ -64,9 +66,9 @@ func (r *Resource) Validate() error {
64
66
r .Resource = flect .Pluralize (strings .ToLower (r .Kind ))
65
67
}
66
68
67
- groupMatch := regexp .MustCompile ("^[a-z]+$" )
69
+ groupMatch := regexp .MustCompile (GroupMatchRegex )
68
70
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 )
70
72
}
71
73
72
74
versionMatch := regexp .MustCompile ("^v\\ d+(alpha\\ d+|beta\\ d+)?$" )
Original file line number Diff line number Diff line change @@ -30,13 +30,13 @@ var _ = Describe("Resource", func() {
30
30
It ("should fail if the Group is not all lowercase" , func () {
31
31
instance := & resource.Resource {Group : "Crew" , Version : "v1" , Kind : "FirstMate" }
32
32
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 ))
34
34
})
35
35
36
36
It ("should fail if the Group contains non-alpha characters" , func () {
37
37
instance := & resource.Resource {Group : "crew1" , Version : "v1" , Kind : "FirstMate" }
38
38
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 ))
40
40
})
41
41
42
42
It ("should fail if the Version is not specified" , func () {
You can’t perform that action at this time.
0 commit comments