-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add test coverage of the Service controller code. #1216
Conversation
The following is the coverage report on pkg/. Say
*TestCoverage feature is being tested, do not rely on any info here yet |
pkg/controller/controller.go
Outdated
} | ||
} | ||
|
||
func Filter(resource string) func(obj interface{}) bool { |
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.
bit of a nit, but why not
func Filter(kind string)?
and maybe add comments on what this Filter can be used for
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.
Done
Name: "incomplete", | ||
Namespace: "foo", | ||
}, | ||
// No spec.{runLatest,pinned} => error |
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.
left over cruft?
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.
Clarified
|
||
for i := range tt.wantCreates { | ||
if i > len(actions)-1 { | ||
t.Fatalf("Reconcile() unexpected actions: %#v", client.Actions()) |
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.
Just curious why these are Fatals in some cases an errors in others.
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.
Copied from the OpenShift controller. Some are harder to continue from than others.
Unlike the other controllers, this follows the pattern of OpenShift's Ingress controller (thanks to @smarterclayton for the pointer). This enables us to have a largely table-driven approach to testing this, which makes adding tests surprisingly easy.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mattmoor, vaikas-google The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The following is the coverage report on pkg/. Say
*TestCoverage feature is being tested, do not rely on any info here yet |
1 similar comment
The following is the coverage report on pkg/. Say
*TestCoverage feature is being tested, do not rely on any info here yet |
pkg/controller/controller.go
Outdated
@@ -48,6 +49,27 @@ func init() { | |||
elascheme.AddToScheme(scheme.Scheme) | |||
} | |||
|
|||
func PassSecond(f func(interface{})) func(interface{}, interface{}) { |
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.
The name doesn't make it obvious I should use it with the UpdateFunc property
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 added a detailed comment (like Filter) and renamed this to PassNew
, since new
is the argument being forwarded to the function. Open to better naming suggestions?
c.Spec = service.Spec.Pinned.Configuration | ||
} else { | ||
return nil, errors.New("malformed Service: one of runLatest or pinned must be present.") |
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.
The controller bails out in this scenario with no error message visible to the user
I'd actually expect ServiceConditionConfigurationReady
to become false
with the reason being the configuration is not set in the Service's spec. This then causing the ServiceConditionReady
to become false
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'd actually prefer this to fail on admission though
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.
pkg/controller/testing/listers.go
Outdated
// Assert that our fake implements the interface it is faking. | ||
var _ listers.RevisionLister = (*RevisionLister)(nil) | ||
|
||
func (r *RevisionLister) List(selector labels.Selector) (ret []*v1alpha1.Revision, err error) { |
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.
not using the named returns ret
& err
throughout this file - probably worth getting rid of it
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.
Done
Dropped named returns from listers.go Rename and document the UpdateFunc helper.
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.
Should be RFAL
pkg/controller/controller.go
Outdated
@@ -48,6 +49,27 @@ func init() { | |||
elascheme.AddToScheme(scheme.Scheme) | |||
} | |||
|
|||
func PassSecond(f func(interface{})) func(interface{}, interface{}) { |
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 added a detailed comment (like Filter) and renamed this to PassNew
, since new
is the argument being forwarded to the function. Open to better naming suggestions?
pkg/controller/testing/listers.go
Outdated
// Assert that our fake implements the interface it is faking. | ||
var _ listers.RevisionLister = (*RevisionLister)(nil) | ||
|
||
func (r *RevisionLister) List(selector labels.Selector) (ret []*v1alpha1.Revision, err error) { |
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.
Done
The following is the coverage report on pkg/. Say
*TestCoverage feature is being tested, do not rely on any info here yet |
/lgtm |
Unlike the other controllers, this follows the pattern of OpenShift's Ingress controller (thanks to @smarterclayton for the pointer). This enables us to have a largely table-driven approach to testing this, which makes adding tests surprisingly easy.