Adding validatable to bus types.#321
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: n3wscott If they are not already assigned, you can assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Grant for LGTM: Evan for Approval: |
| ) | ||
|
|
||
| const ( | ||
| longName = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" |
There was a problem hiding this comment.
You can use strings.Repeat to avoid having to type this out yourself, and so its self documenting as to its length.
| } | ||
|
|
||
| func (current *Bus) CheckImmutableFields(og apis.Immutable) *apis.FieldError { | ||
| // TODO(n3wscott): Anything to check? |
| } | ||
|
|
||
| func (current *ClusterBus) CheckImmutableFields(og apis.Immutable) *apis.FieldError { | ||
| // TODO(n3wscott): Anything to check? |
|
/lgtm |
|
bad merge of lock file... will fix when at real computer |
|
|
||
| package v1alpha1 | ||
|
|
||
| func (b *Bus) SetDefaults() { |
There was a problem hiding this comment.
It's fine for these no-op methods to exist but I'd like to see a comment justifying their existence, otherwise someone will remove them unknowingly. Do we expect defaults to be added in the near future? Is this a demonstration of what's possible? A desire for consistency across all resource types? A need for all objects to implement the same interface?
There was a problem hiding this comment.
[n3wscott]: Note about #321 and other related Validatable stub PRs: This is staging work, the plan is another pass to bring up the test coverage, then remove unused after each type is stubbed.
There was a problem hiding this comment.
Makes sense. Can you add those words as a comment in this file? Just in case this work ends up taking longer than expected. 😸
| return nil | ||
| } | ||
|
|
||
| func (current *Bus) CheckImmutableFields(og apis.Immutable) *apis.FieldError { |
There was a problem hiding this comment.
Same as defaulters above. I'd like to see a comment justifying this method's no-op existence.
|
/lgtm |
|
[n3wscott]: Note about #321 and other related Validatable stub PRs: This is staging work, the plan is another pass to bring up the test coverage, then remove unused after each type is stubbed. |
| BacksChannel(channel *Channel) bool | ||
| GetSpec() *BusSpec | ||
| apis.Validatable | ||
| apis.Immutable |
There was a problem hiding this comment.
Should this be apis.Defaultable as well (since you have an implementation)?
Alternately, since there appear to be no defaults, you might be able to get rid of the _defaults.go files.
| }, | ||
| }, | ||
| }, | ||
| want: nil, |
There was a problem hiding this comment.
You don't need to specify want here.
| Subscription: &[]Parameter{ | ||
| { | ||
| Name: "foo", | ||
| Description: "bar", |
There was a problem hiding this comment.
Do you want to check that empty description is valid
?
| }, | ||
| }, | ||
| want: &apis.FieldError{ | ||
| Message: fmt.Sprintf("invalid key name %q", longName), |
There was a problem hiding this comment.
It would be nice if you could supply a "matcher" object here.
| }, | ||
| Details: "must be no more than 253 characters", | ||
| }, | ||
| }, { |
There was a problem hiding this comment.
Do you want to test any of:
- Multiple parameters to the same Bus.
- Two parameters with the same
Namein the same list. - Multiple errors in the same object.
There was a problem hiding this comment.
good thought, I added a todo to add those, this was just moving what tests existed.
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| got := test.bs.Validate() |
There was a problem hiding this comment.
It would be nice if you could actually put these specs into both a Bus and a ClusterBus for testing (to ensure that both are hooked up correctly).
There was a problem hiding this comment.
It looks like the webhook tests actually do this right now, so I'm less concerned about this.
| return err | ||
| } | ||
| if err := new.CheckImmutableFields(old); err != nil { | ||
| return err |
There was a problem hiding this comment.
It looks like we never call .SetDefaults() on new. Should we do that first, if it's going to be Defaultable? (Again, I question the value right now.)
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: evankanderson, n3wscott The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
The following is the coverage report on pkg/.
|
|
/lgtm Thanks @n3wscott! |
|
/test pull-knative-eventing-integration-tests /ISTIO |
This will be to support the webhook change.