Skip to content
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 tests for main Perses controller #5

Merged
merged 1 commit into from
Jan 15, 2024
Merged

Conversation

jgbernalp
Copy link
Contributor

This PR adds testing for the main Perses controller. Asserting that the service, configMap, deployment are reconciled based on Perses CR

@jgbernalp jgbernalp force-pushed the add-tests branch 2 times, most recently from ef2c318 to e956072 Compare November 15, 2023 08:48
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

var _ = Describe("Perses controller", func() {

Choose a reason for hiding this comment

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

I'm a bit torn about this approach.
Thinking if don't make a bit harder for other go developers get starting with tests.
wdyt @Nexucis ?

Copy link
Member

Choose a reason for hiding this comment

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

ah I forgot to comment about this. I'm thinking the same, it's more a php/javascript approach I believe.

The "Golang way" is more about creating a list of cases and then looping other it to run the tested function.
Like that for example: https://github.com/perses/perses/blob/main/pkg/model/api/v1/metadata_test.go#L24-L47

Or for more complicated use case that requires more struct, then you could have something like that:
https://github.com/perses/perses/blob/main/internal/cli/test/test.go

Which is used like that: https://github.com/perses/perses/blob/main/internal/cli/cmd/apply/apply_test.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thnx for your feedback, I followed the docs on testing operators. In which test are run using envtest controller runtime so the eventual state of the operator can be asserted, I believe the goal here is not to test expected outputs of a function as the reconcilers creates resources in a cluster as a side effect. Are there other approaches or suggestions @simonpasquier?

Choose a reason for hiding this comment

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

I have no strong opinion on the topic. In fact all the operators I've been working on have developed their own home-made framework (based on the Go testing library) to run end-to-end tests. In my current experiences, the end-to-end tests require a running Kube cluster (typically Kind), they setup all required resources (e.g. CRDs, service accounts, roles, bindings, ...) then they run the operator binary and exercise various scenarios.

So I've got no direct experience with the envtest framework and I understand that it can feel a bit daunting at first but at the same time, it may simplify the setup and teardown of the test environment.

@jgbernalp
Copy link
Contributor Author

@nicolastakashi @Nexucis would you be ok to proceed with this approach for e2e tests?

@Nexucis
Copy link
Member

Nexucis commented Jan 5, 2024

ah yeah sorry I forgot to reply here.

So yeah on my side I'm ok to move forward on this PR if like Simon said, using this framework is simplifying the setup I'm good with that

@jgbernalp jgbernalp merged commit 655b841 into perses:main Jan 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants