-
Notifications
You must be signed in to change notification settings - Fork 84
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 side input for golden file tests #203
Add side input for golden file tests #203
Conversation
|
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
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 understand the commands that are listed here. |
Welcome @llamallamaduck! |
Hi @llamallamaduck. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
nonListKind := gvkUnprocessed.Kind | ||
nonListKind = nonListKind[:len(nonListKind)-4] | ||
gvk := schema.GroupVersionKind{gvkUnprocessed.Group, gvkUnprocessed.Version, nonListKind} | ||
gvr, _ := meta.UnsafeGuessKindToResource(gvk) |
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.
Not super happy with the way of figuring out gvk and gvr here - any suggestions on how to make it nicer?
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.
+1 for this, I wonder if folks from api-server will be more aware about this.
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'll take a look but I don't want to hold up this PR (sorry for the delay already!) :-)
5ab7463
to
4d3227e
Compare
|
d702149
to
a553f84
Compare
|
@llamallamaduck As k8s-ci-bot says, could you sign CLA? |
/check-cla |
/ok-to-test |
/test pull-declarative-test |
1 similar comment
/test pull-declarative-test |
7c72cb2
to
ba9744f
Compare
Yeah, I've done everything as stated in instructions and still no luck. I've opened a support ticket to sort it out. |
0009745
to
ed7f42e
Compare
Adds a posibility to provide a *.side_in.yaml file, that contains resources that should exist before the resource defined in `*.in.yaml` is applied. These side input resources are going to be created before running a testcase, and cleaned up at the end of it. The resources will be accessible via Get and List. Note that the existing functionality has not been changed.
ed7f42e
to
c8123e8
Compare
/check-cla |
/cc @kubernetes-sigs/kubernetes-sig-api-machinery-reviewers |
/cc @kubernetes-sigs/kubebuilder-declarative-pattern-admins |
@@ -22,6 +22,11 @@ The bulk of these tests are implemented in `pkg/tests` via the `StandardValidato | |||
The test scans a `tests` directory for `*.in.yaml` files, runs the operator for each | |||
of them, and compares the output to `*.out.yaml` files. | |||
|
|||
It is also possible to provide `*.side_in.yaml` file that contains resources that | |||
should exist before the resource defined in `*.in.yaml` is applied. These resources | |||
are going to be created before running a test, and cleaned up upon finishing. They |
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.
are going to be created before running a test, and cleaned up upon finishing. They | |
are going to be created before running a test, and cleaned up upon finishing. It |
nonListKind := gvkUnprocessed.Kind | ||
nonListKind = nonListKind[:len(nonListKind)-4] | ||
gvk := schema.GroupVersionKind{gvkUnprocessed.Group, gvkUnprocessed.Version, nonListKind} | ||
gvr, _ := meta.UnsafeGuessKindToResource(gvk) |
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.
+1 for this, I wonder if folks from api-server will be more aware about this.
/lgtm |
sideInputPath := strings.Replace(p, ".in.yaml", ".side_in.yaml", -1) | ||
sideInputRead, err := os.ReadFile(sideInputPath) | ||
if err != nil { | ||
t.Logf("Could not read side input file %s: %v, skipping", sideInputPath, err) |
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.
Nit: I like to check that the error is indeed os.IsNotFound(err) (I'm assuming that's what we're expecting), and avoid the log message - and possibly avoid covering up another error (like e.g. a permissions error)
nonListKind := gvkUnprocessed.Kind | ||
nonListKind = nonListKind[:len(nonListKind)-4] | ||
gvk := schema.GroupVersionKind{gvkUnprocessed.Group, gvkUnprocessed.Version, nonListKind} | ||
gvr, _ := meta.UnsafeGuessKindToResource(gvk) |
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'll take a look but I don't want to hold up this PR (sorry for the delay already!) :-)
Thanks @llamallamaduck - this looks good. I'll take a look at the list thing separately - there should be a helper for this, but I don't know of one immediately. /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: justinsb, llamallamaduck 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 |
What this PR does / why we need it:
This PR adds a possibility to provide a
*.side_in.yaml
file that contains resources that should exist before the resource defined in*.in.yaml
is applied, when running golden file tests. These side input resources are going to be created before running a test case, and cleaned up at the end of it. The resources will be accessible via Get and List. Note that the existing functionality has not been changed.Context from which the need for this change came up:
We have 3 CRDs: Event(E), Component(C) and EventComponentDeployment(ECD). When an E is created, for every existing C we create an ECD. Every ECD has a reference to E and C, and upon creation it further creates other resources based on whats inside E and C. To be able to test E controller and ECD controller with golden file tests, we needed a way easily create surrounding resources (Cs for testing E controller, and Es and Cs for testing ECD controller). This change works well for this use case.
Note for reviewers:
The second commit in this PR makes the examples run with local library (to include changes in this PR), which required running
go mod tidy
, which resulted in a lot of changes. If you prefer me to remove this commit, and update the tests in example later/in a separate PR, let me know. The gist of this change is in the first commit.