-
Notifications
You must be signed in to change notification settings - Fork 17
Add core Reconciler testing and fake resolver framework functions #51
Conversation
limitations under the License. | ||
*/ | ||
|
||
package framework |
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 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.
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.
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 { |
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.
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) { |
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.
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) |
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.
What can I say, I like consistent Makefile
s 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.
cc @chitrangpatel, @dibyom, @vdemeester, @lbernick I've got more I'm going to add to this - an "acceptance test" for Oh, and my apologies for the size of the PR - that's basically all |
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.
/retest
@@ -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) |
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 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.go
s.
653919d
to
666b136
Compare
_ "knative.dev/pkg/system/testing" // Setup system.Namespace() | ||
) | ||
|
||
func TestReconcile(t *testing.T) { |
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.
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.go
s 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. =)
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.
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...
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.
Well, it did break something in the integration tests... =)
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.
Ok, I gave up, at least for now, and copy-pasted the testing framework code around. Ah well.
/retest |
nice to see all the tests pass 😄 . Is this still a WIP @abayer ? I wanted to write some tests for |
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>
Ok, took this out of WIP. @vdemeester, @jerop, @dibyom, @chitrangpatel - I'd really appreciate reviews. =) |
/approved |
limitations under the License. | ||
*/ | ||
|
||
package names |
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.
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 ?
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.
Exactly!
[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 |
@jerop @chitrangpatel - I could use an |
/lgtm |
@chitrangpatel: changing LGTM is restricted to collaborators In response to this:
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. |
I'm unable to give it. I get the message: |
Hum, something might have failed with the org sync.. Let's me check… In the meantime… |
/lgtm |
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)
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)
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)
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)
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)
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)
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)
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)
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)
Add core Reconciler testing and fake resolver framework functions
Fixes #39
Tests are added for
pkg/resolver/framework/reconciler.go
andpkg/reconciler/resolutionrequest/resolution.request.go
, as well as the new framework for testingResolver
s inpkg/resolver/framework/testing
, with tests using that ingitresolver/pkg/git/resolver_test.go
anddocs/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.