Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Add core Reconciler testing and fake resolver framework functions #51

Merged
merged 1 commit into from
Jun 1, 2022

Conversation

abayer
Copy link
Contributor

@abayer abayer commented May 18, 2022

Add core Reconciler testing and fake resolver framework functions

Fixes #39

Tests are added for pkg/resolver/framework/reconciler.go and pkg/reconciler/resolutionrequest/resolution.request.go, as well as the new framework for testing Resolvers in pkg/resolver/framework/testing, with tests using that in gitresolver/pkg/git/resolver_test.go and docs/resolver-template/cmd/demoresolver/main_test.go.

I didn't add Resolver tests for the bundle resolver, because the tooling to actually do so with fake bundles etc already exists in Pipeline, and it's not worth copy-pasting that tooling over here when we're gonna move over to Pipeline soon enough anyway!

In addition, e2e tests are reorganized a bit, and I added some other tooling derived from what we've got in Pipeline.

@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 18, 2022
@tekton-robot tekton-robot requested review from dibyom and a user May 18, 2022 20:57
@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 18, 2022
limitations under the License.
*/

package framework
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to put the fake controller/resolver stuff in this package in order to use them in reconciler_test.go thanks to the eternal fun of circular dependencies, but the fake controller in particular is intended to be used by real Resolver implementations, and the fake resolver will (eventually!) end up being used in Pipeline's unit tests once we merge Resolution into Pipeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, @chitrangpatel, I think this and fakeresolver.go may be helpful in writing tests for pkg/resource/crd_resource.go.

// in a consistent format for reuse across all of our tests. This
// func assumes that the order of arguments passed to cmp.Diff was
// (want, got) or, in other words, the expectedResult then the actualResult.
func PrintWantGot(diff string) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This and test/names/generate.go are copy-pasted directly from Pipeline, and will go away once we've folded Resolution into Pipeline.

// SeedTestData returns Clients and Informers populated with the
// given Data.
// nolint: revive
func SeedTestData(t *testing.T, ctx context.Context, d Data) (Clients, Informers) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically a stripped down copy of Pipeline's test/controller.go, and will go away once we combine the repos.

@@ -0,0 +1,200 @@
MODULE = $(shell env GO111MODULE=on $(GO) list -m)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What can I say, I like consistent Makefiles across projects I'm working on. =) This, like a number of other things I've called out, will go away once we merge Resolution into Pipeline.

@abayer
Copy link
Contributor Author

abayer commented May 18, 2022

cc @chitrangpatel, @dibyom, @vdemeester, @lbernick

I've got more I'm going to add to this - an "acceptance test" for Resolver implementations to make sure they correctly satisfy the Resolver interface and refining what's in pkg/resolver/framework/reconciler_test.go into a helper function that Resolver implementations can use for their own testing are what comes to mind currently, but this is a start.

Oh, and my apologies for the size of the PR - that's basically all vendor going a bit bananas.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/retest

@abayer abayer force-pushed the reconciler-tests branch from bf83c04 to 5f111d0 Compare May 19, 2022 14:19
@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 19, 2022
@@ -31,8 +33,9 @@ import (
const timeoutDuration = time.Minute

func main() {
sharedmain.Main("controller",
framework.NewController(context.Background(), &resolver{}),
ctx := filteredinformerfactory.WithSelectors(context.Background(), v1alpha1.ManagedByLabelKey)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why this didn't barf with Unable to fetch labelkey from context previously, but it started doing that in this PR until I added this and changed the next lines here and in the other Resolver main.gos.

@abayer abayer force-pushed the reconciler-tests branch 3 times, most recently from 653919d to 666b136 Compare May 19, 2022 17:49
_ "knative.dev/pkg/system/testing" // Setup system.Namespace()
)

func TestReconcile(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so...this is in pkg/resolver/framework/testing because fakecontroller.go makes the Resolver binaries barf with /ko-app/bundleresolver flag redefined: cluster if fakecontroller.go is in pkg/resolver/framework - some Knative testing magic ends up in the resulting Resolver binary, calling ClientConfig.InitFlags(flag.CommandLine) at init time via, well, magic, resulting in the later call via sharedmain.MainWithContext failing.

So if I wanted to use the fake reconciler framework elsewhere - i.e., in tests for bundleresolver etc - I have to have the fake controller/reconciler tooling exported (so not in _test.go) but not in the same package as stuff the Resolver main.gos import. I could just switch this reconciler_test.go to not use the fake framework but instead its own copy-pasted equivalent, but...yeah. I'm waiting for someone else to come up with ideas. =)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, 6721eae seems to fix it, at least at first glance - moving pkg/clients.go to pkg/clients_test.go got rid of the import chain that led to knative.dev/pkg/test ending up in the Resolver binaries, and I am pretty sure it won't break anything in the integration tests...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it did break something in the integration tests... =)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I gave up, at least for now, and copy-pasted the testing framework code around. Ah well.

@abayer
Copy link
Contributor Author

abayer commented May 24, 2022

/retest

@abayer abayer force-pushed the reconciler-tests branch from cb3e55e to 137e577 Compare May 25, 2022 15:45
@chitrangpatel
Copy link
Contributor

chitrangpatel commented May 25, 2022

nice to see all the tests pass 😄 . Is this still a WIP @abayer ? I wanted to write some tests for resources but wanted to pull in this work first.

Part of tektoncd#39

Tests are added for `pkg/resolver/framework/reconciler.go` and `pkg/reconciler/resolutionrequest/resolution.request.go`, as well as the new framework for testing `Resolver`s in `pkg/resolver/framework/testing`, with tests using that in `gitresolver/pkg/git/resolver_test.go` and `docs/resolver-template/cmd/demoresolver/main_test.go`.

In addition, e2e tests are reorganized a bit, and I added some other tooling derived from what we've got in Pipeline.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
@abayer abayer force-pushed the reconciler-tests branch from a5a308e to 8723c6f Compare May 31, 2022 17:04
@abayer abayer changed the title WIP: Add core Reconciler testing and fake resolver framework functions Add core Reconciler testing and fake resolver framework functions May 31, 2022
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 31, 2022
@abayer
Copy link
Contributor Author

abayer commented May 31, 2022

Ok, took this out of WIP. @vdemeester, @jerop, @dibyom, @chitrangpatel - I'd really appreciate reviews. =)

@chitrangpatel
Copy link
Contributor

/approved

limitations under the License.
*/

package names
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the same package as tektoncd/pipeline/pkg/names ?
My guess is to duplicate here and just remove once we merge the repository back into pipeline ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly!

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester

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

@abayer
Copy link
Contributor Author

abayer commented Jun 1, 2022

@jerop @chitrangpatel - I could use an /lgtm. =)

@chitrangpatel
Copy link
Contributor

/lgtm

@tekton-robot
Copy link

@chitrangpatel: changing LGTM is restricted to collaborators

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@chitrangpatel
Copy link
Contributor

@jerop @chitrangpatel - I could use an /lgtm. =)

I'm unable to give it. I get the message: @chitrangpatel: changing LGTM is restricted to collaborators

@vdemeester
Copy link
Member

@jerop @chitrangpatel - I could use an /lgtm. =)

I'm unable to give it. I get the message: @chitrangpatel: changing LGTM is restricted to collaborators

Hum, something might have failed with the org sync.. Let's me check… In the meantime…
/lgtm

@chitrangpatel
Copy link
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 1, 2022
@tekton-robot tekton-robot merged commit d93542e into tektoncd:main Jun 1, 2022
QuanZhang-William added a commit to QuanZhang-William/pipeline that referenced this pull request Jul 29, 2022
Part of TEP-0110

Update Git Resolver example to use ```revision``` and ```pathInRepo``` fields to reflect the changes in [TEP-0110: Add git revision resolution suppot in Git Resolver](tektoncd/resolution#75) and [Add core Reconciler testing and fake resolver framework functions](tektoncd/resolution#51)
QuanZhang-William added a commit to QuanZhang-William/pipeline that referenced this pull request Jul 29, 2022
Part of TEP-0115

Update Git Resolver example to use ```revision``` and ```pathInRepo``` fields to reflect the changes in [TEP-0110: Add git revision resolution suppot in Git Resolver](tektoncd/resolution#75) and [Add core Reconciler testing and fake resolver framework functions](tektoncd/resolution#51)
QuanZhang-William added a commit to QuanZhang-William/pipeline that referenced this pull request Jul 29, 2022
Part of TEP-0115

Update Git Resolver example to use ```revision``` and ```pathInRepo``` fields to reflect the changes in [TEP-0115: Add git revision resolution suppot in Git Resolver](tektoncd/resolution#75) and [Add core Reconciler testing and fake resolver framework functions](tektoncd/resolution#51)
QuanZhang-William added a commit to QuanZhang-William/pipeline that referenced this pull request Aug 8, 2022
Part of TEP-0115

Update Git Resolver example to use ```revision``` and ```pathInRepo``` fields to reflect the changes in [TEP-0115: Add git revision resolution suppot in Git Resolver](tektoncd/resolution#75) and [Add core Reconciler testing and fake resolver framework functions](tektoncd/resolution#51)
QuanZhang-William added a commit to QuanZhang-William/resolution that referenced this pull request Aug 8, 2022
Part of TEP-0115
Update Git Resolver documentation to use "revision" and "pathInRepo" fields to reflect the changes in [TEP-0115: Add git revision resolution support in Git Resolver](tektoncd#75) and [Add core Reconciler testing and fake resolver framework functions](tektoncd#51)
QuanZhang-William added a commit to QuanZhang-William/resolution that referenced this pull request Aug 8, 2022
Part of TEP-0115
Update Git Resolver documentation to use "revision" and "pathInRepo" fields to reflect the changes in [TEP-0115: Add git revision resolution support in Git Resolver](tektoncd#75) and [Add core Reconciler testing and fake resolver framework functions](tektoncd#51)
QuanZhang-William added a commit to QuanZhang-William/resolution that referenced this pull request Aug 8, 2022
Part of TEP-0115
Update Git Resolver documentation to use "revision" and "pathInRepo" fields to reflect the changes in [TEP-0115: Add git revision resolution support in Git Resolver](tektoncd#75) and [Add core Reconciler testing and fake resolver framework functions](tektoncd#51)
QuanZhang-William added a commit to QuanZhang-William/pipeline that referenced this pull request Aug 8, 2022
Part of TEP-0115

Update git resolver example to use "revision" and "pathInRepo" fields to reflect the changes in [TEP-0115: Add git revision resolution suppot in Git Resolver](tektoncd/resolution#75) and [Add core Reconciler testing and fake resolver framework functions](tektoncd/resolution#51)
tekton-robot pushed a commit that referenced this pull request Aug 8, 2022
Part of TEP-0115
Update Git Resolver documentation to use "revision" and "pathInRepo" fields to reflect the changes in [TEP-0115: Add git revision resolution support in Git Resolver](#75) and [Add core Reconciler testing and fake resolver framework functions](#51)
tekton-robot pushed a commit to tektoncd/pipeline that referenced this pull request Aug 9, 2022
Part of TEP-0115

Update git resolver example to use "revision" and "pathInRepo" fields to reflect the changes in [TEP-0115: Add git revision resolution suppot in Git Resolver](tektoncd/resolution#75) and [Add core Reconciler testing and fake resolver framework functions](tektoncd/resolution#51)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Core Reconciler tests and easy-to-reuse Resolver test harnesses
4 participants