Skip to content

Fixture builders for Subscription reconcile tests#659

Merged
knative-prow-robot merged 3 commits into
knative:masterfrom
grantr:test-builders
Dec 4, 2018
Merged

Fixture builders for Subscription reconcile tests#659
knative-prow-robot merged 3 commits into
knative:masterfrom
grantr:test-builders

Conversation

@grantr
Copy link
Copy Markdown
Contributor

@grantr grantr commented Dec 3, 2018

The existing fixture builders in the Subscription reconciler tests aren't terrible, but they don't compose well. Every case needs its own fixture method like getNewSubscriptionWithReferencesResolvedAndPhysicalReplyAndNoSubscriber.

@dprotaso experimented with builders in knative/serving#1762 and knative/serving#1924, but apparently moved on to other things before getting to a satisfactory state.

This is my attempt at a builder interface satisfying the following:

  • minimal code for both framework and test authors to write and understand
  • Flexible for test authors to define their own builder function signatures
  • No runtime typing (more than what's already used by the controller-runtime client)
  • As clear (or clearer) to read as the existing fixtures

I chose the Subscription reconcile tests for this PoC because they use more complex combinations. The diffstats are probably a best case scenario for this kind of refactor.

Here's the diff for the above fixture invocation:

   WantPresent: []runtime.Object{
-    getNewSubscriptionWithReferencesResolvedAndPhysicalSubscriberAndNoReply(),
+    Subscription().ReferencesResolved().PhysicalSubscriber(targetDNS).EmptyNonNilReply(),
   },

And an example of one of the builder methods:

func (s *SubscriptionBuilder) EmptyNonNilSubscriber() *SubscriptionBuilder {
	s.Spec.Subscriber = &eventingv1alpha1.SubscriberSpec{}
	return s
}

@mattmoor

The Buildable interface allows test fixtures to use the builder pattern.
The table test runner will call Build() on any Buildable objects and use
the result as the test fixture.
Unused for comparison with existing fixture methods.
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Dec 3, 2018
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 3, 2018
@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: grantr

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-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 3, 2018
@grantr grantr removed the request for review from mattmoor December 3, 2018 23:36
@grantr
Copy link
Copy Markdown
Contributor Author

grantr commented Dec 3, 2018

/cc @vaikas-google @Harwayne

Copy link
Copy Markdown
Contributor

@Harwayne Harwayne left a comment

Choose a reason for hiding this comment

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

/lgtm

Looks much nicer.

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2018
@knative-prow-robot knative-prow-robot merged commit a632a9c into knative:master Dec 4, 2018
@grantr grantr deleted the test-builders branch December 4, 2018 00:44
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants