Added documentation for unit tests with the envtest crate#92
Open
emilianomaccaferri wants to merge 1 commit into
Open
Added documentation for unit tests with the envtest crate#92emilianomaccaferri wants to merge 1 commit into
envtest crate#92emilianomaccaferri wants to merge 1 commit into
Conversation
Signed-off-by: Emiliano Maccaferri <inbox@emilianomaccaferri.com>
envtest crateenvtest crate
| async fn test_namespace_creation() { | ||
| initialize_ring(); | ||
| // this assumes you have a `crd.yaml` in your `src` folder | ||
| let env = envtest_with_crds(vec![current_dir().unwrap().join("src/crd.yaml")]); |
Member
There was a problem hiding this comment.
Suggested change
| let env = envtest_with_crds(vec![current_dir().unwrap().join("src/crd.yaml")]); | |
| let env = Environment::default().with_crds(Test::crd()); |
Should work as well, which can remove envtest_with_crds
Here is an example - https://github.com/kube-rs/controller-rs/blob/main/src/controller.rs#L309, though passing vec! is not necessary.
| // this assumes you have a `crd.yaml` in your `src` folder | ||
| let env = envtest_with_crds(vec![current_dir().unwrap().join("src/crd.yaml")]); | ||
| let apiserver = env.create().unwrap(); // this starts the api server! | ||
| let (client, ctx) = client_and_ctx(apiserver.kubeconfig().unwrap()).await; |
Member
There was a problem hiding this comment.
Suggested change
| let (client, ctx) = client_and_ctx(apiserver.kubeconfig().unwrap()).await; | |
| let client = apiserver.client(); | |
| let ctx = KubeContext{client: client.clone()}; |
Should do it, assuming you have enabled kube feature https://docs.rs/crate/envtest/0.1.2/features#kube. It should be enabled by default.
Contributor
Author
There was a problem hiding this comment.
nice! i'll check these tomorrow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I added a few lines that document how to test a simple reconciler using this crate.
Keep up the great work you're doing with the
kube-rsecosystem!Edit: lol I didn't notice that @Danil-Grigorev was a kube-rs maintainer