-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
👻 Enhance regex patterns #1745
👻 Enhance regex patterns #1745
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,27 +47,27 @@ var _ = Describe("Resource Options", func() { | |
options := &Options{Group: "crew", Version: "1", Kind: "FirstMate"} | ||
Expect(options.Validate()).NotTo(Succeed()) | ||
Expect(options.Validate().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was 1)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was 1)`)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we not use fmt.String and have the regex as a const arg of it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also thought of that to prevent having it hardcoded a dozen times the thing is that the string is not exported from its package. I think the better approach would be to create an expecific error instead a generic one and test if this yields this kind of error. But I just wanted to do the less changes to get it to pass Travis for now. |
||
|
||
options = &Options{Group: "crew", Version: "1beta1", Kind: "FirstMate"} | ||
Expect(options.Validate()).NotTo(Succeed()) | ||
Expect(options.Validate().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was 1beta1)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was 1beta1)`)) | ||
|
||
options = &Options{Group: "crew", Version: "a1beta1", Kind: "FirstMate"} | ||
Expect(options.Validate()).NotTo(Succeed()) | ||
Expect(options.Validate().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was a1beta1)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was a1beta1)`)) | ||
|
||
options = &Options{Group: "crew", Version: "v1beta", Kind: "FirstMate"} | ||
Expect(options.Validate()).NotTo(Succeed()) | ||
Expect(options.Validate().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was v1beta)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was v1beta)`)) | ||
|
||
options = &Options{Group: "crew", Version: "v1beta1alpha1", Kind: "FirstMate"} | ||
Expect(options.Validate()).NotTo(Succeed()) | ||
Expect(options.Validate().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was v1beta1alpha1)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was v1beta1alpha1)`)) | ||
}) | ||
|
||
It("should fail if the Kind is not specified", func() { | ||
|
@@ -149,27 +149,27 @@ var _ = Describe("Resource Options", func() { | |
options := &Options{Group: "crew", Version: "1", Kind: "FirstMate"} | ||
Expect(options.ValidateV2()).NotTo(Succeed()) | ||
Expect(options.ValidateV2().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was 1)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was 1)`)) | ||
|
||
options = &Options{Group: "crew", Version: "1beta1", Kind: "FirstMate"} | ||
Expect(options.ValidateV2()).NotTo(Succeed()) | ||
Expect(options.ValidateV2().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was 1beta1)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was 1beta1)`)) | ||
|
||
options = &Options{Group: "crew", Version: "a1beta1", Kind: "FirstMate"} | ||
Expect(options.ValidateV2()).NotTo(Succeed()) | ||
Expect(options.ValidateV2().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was a1beta1)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was a1beta1)`)) | ||
|
||
options = &Options{Group: "crew", Version: "v1beta", Kind: "FirstMate"} | ||
Expect(options.ValidateV2()).NotTo(Succeed()) | ||
Expect(options.ValidateV2().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was v1beta)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was v1beta)`)) | ||
|
||
options = &Options{Group: "crew", Version: "v1beta1alpha1", Kind: "FirstMate"} | ||
Expect(options.ValidateV2()).NotTo(Succeed()) | ||
Expect(options.ValidateV2().Error()).To(ContainSubstring( | ||
`version must match ^v\d+(alpha\d+|beta\d+)?$ (was v1beta1alpha1)`)) | ||
`version must match ^v\d+(?:alpha\d+|beta\d+)?$ (was v1beta1alpha1)`)) | ||
}) | ||
|
||
It("should fail if the Kind is not specified for V2", func() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Adirio,
For we not add ore one dependency to the project we decided to copy and paste the implementation to validate.
We should not change this file unless it was changed in the
k8s.io/apimachinery
See:
kubebuilder/pkg/internal/validation/dns.go
Lines 24 to 26 in 1759529
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please revert the changes here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree with you if the code was copy-pasted, but it has been already modified. You can check it. So Convering that capture group into a non-capture group tells the future us reading the code that we are not using that capture group to take a substring out of the regex. It also avoid having to allocate some variables but the performance increase will be very small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catcher. I would prefer if possible we keep a copy and paste of https://github.com/kubernetes/apimachinery/blob/v0.18.6/pkg/util/validation/validation.go whcih would allow us to move to use the dependency if we wish without breaking changes. However, I will let it up to you and @estroz.