Skip to content

Add test coverage of the Service controller code.#1216

Merged
google-prow-robot merged 2 commits intoknative:masterfrom
mattmoor:steve-testing
Jun 15, 2018
Merged

Add test coverage of the Service controller code.#1216
google-prow-robot merged 2 commits intoknative:masterfrom
mattmoor:steve-testing

Conversation

@mattmoor
Copy link
Copy Markdown
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
Copy Markdown

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

Comment thread pkg/controller/controller.go Outdated
}
}

func Filter(resource string) func(obj interface{}) bool {
Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment thread pkg/controller/service/service_test.go Outdated
Name: "incomplete",
Namespace: "foo",
},
// No spec.{runLatest,pinned} => error
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

[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

Details 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
Copy Markdown

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
Copy Markdown

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

Comment thread pkg/controller/controller.go Outdated
elascheme.AddToScheme(scheme.Scheme)
}

func PassSecond(f func(interface{})) func(interface{}, interface{}) {
Copy link
Copy Markdown
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
Copy Markdown
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?

} else if service.Spec.Pinned != nil {
c.Spec = service.Spec.Pinned.Configuration
} else {
return nil, errors.New("malformed Service: one of runLatest or pinned must be present.")
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread 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) {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread pkg/controller/controller.go Outdated
elascheme.AddToScheme(scheme.Scheme)
}

func PassSecond(f func(interface{})) func(interface{}, interface{}) {
Copy link
Copy Markdown
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?

Comment thread 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) {
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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