Skip to content
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

Merged
merged 2 commits into from
Jun 15, 2018

Conversation

mattmoor
Copy link
Member

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.

@google-prow-robot google-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 14, 2018
@knative-metrics-robot
Copy link

The following is the coverage report on pkg/. Say /test pull-knative-serving-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/controller/configuration/configuration.go 75.8% 79.8% 4.0
pkg/controller/configuration/configuration_test.go 75.8% 79.8% 4.0
pkg/controller/service/service.go 0.0% 85.4% 85.4
pkg/controller/service/service_test.go 0.0% 85.4% 85.4

*TestCoverage feature is being tested, do not rely on any info here yet

}
}

func Filter(resource string) func(obj interface{}) bool {
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left over cruft?

Copy link
Member Author

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())
Copy link
Contributor

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.

Copy link
Member Author

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.
@vaikas
Copy link
Contributor

vaikas commented Jun 14, 2018

/lgtm
/approve

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 14, 2018
@google-prow-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/. Say /test pull-knative-serving-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/controller/configuration/configuration.go 75.8% 79.8% 4.0
pkg/controller/configuration/configuration_test.go 75.8% 79.8% 4.0
pkg/controller/service/service.go 0.0% 85.4% 85.4
pkg/controller/service/service_test.go 0.0% 85.4% 85.4

*TestCoverage feature is being tested, do not rely on any info here yet

1 similar comment
@knative-metrics-robot
Copy link

The following is the coverage report on pkg/. Say /test pull-knative-serving-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/controller/configuration/configuration.go 75.8% 79.8% 4.0
pkg/controller/configuration/configuration_test.go 75.8% 79.8% 4.0
pkg/controller/service/service.go 0.0% 85.4% 85.4
pkg/controller/service/service_test.go 0.0% 85.4% 85.4

*TestCoverage feature is being tested, do not rely on any info here yet

@@ -48,6 +49,27 @@ func init() {
elascheme.AddToScheme(scheme.Scheme)
}

func PassSecond(f func(interface{})) func(interface{}, interface{}) {
Copy link
Member

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

Copy link
Member Author

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.")
Copy link
Member

@dprotaso dprotaso Jun 15, 2018

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

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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) {
Copy link
Member

@dprotaso dprotaso Jun 15, 2018

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

Copy link
Member Author

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.
@google-prow-robot google-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 15, 2018
Copy link
Member Author

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be RFAL

@@ -48,6 +49,27 @@ func init() {
elascheme.AddToScheme(scheme.Scheme)
}

func PassSecond(f func(interface{})) func(interface{}, interface{}) {
Copy link
Member Author

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?

// 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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/. Say /test pull-knative-serving-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/controller/configuration/configuration.go 75.8% 79.8% 4.0
pkg/controller/configuration/configuration_test.go 75.8% 79.8% 4.0
pkg/controller/service/service.go 0.0% 85.4% 85.4
pkg/controller/service/service_test.go 0.0% 85.4% 85.4

*TestCoverage feature is being tested, do not rely on any info here yet

@dprotaso
Copy link
Member

/lgtm

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 15, 2018
@google-prow-robot google-prow-robot merged commit 1dc2c37 into knative:master Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants