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

[COR-37] Integration / functional tests #23

Merged
merged 18 commits into from
Dec 21, 2022
Merged

[COR-37] Integration / functional tests #23

merged 18 commits into from
Dec 21, 2022

Conversation

sjmiller609
Copy link
Contributor

@sjmiller609 sjmiller609 commented Dec 20, 2022

  • add integration testing setup
    • starts Kind cluster(s)
    • installs CRD
    • starts operator
    • runs integration tests
  • integration tests:
    • apply a configuration of coreDB
    • check pod becomes running


#[tokio::test]
#[ignore]
async fn functional_test_basic_create() {
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 test deploys a CoreDB into the cluster we are connected to, then checks that a pod starts

@sjmiller609 sjmiller609 marked this pull request as ready for review December 21, 2022 20:13
Comment on lines +68 to +69
- 'kindest/node:v1.25.3'
- 'kindest/node:v1.22.15'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can test against multiple k8s versions

Comment on lines +67 to +77
if let Err(_) = tokio::time::timeout(
std::time::Duration::from_secs(timeout_seconds),
await_condition(pods, &pod_name, conditions::is_pod_running()),
)
.await
{
panic!(
"\n\nERROR: Did not find the pod {} to be running after waiting for {} seconds\n\n",
pod_name, timeout_seconds
)
}
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 found this pattern to wait on something to be useful

Copy link

Choose a reason for hiding this comment

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

if you are just panic'ing you could do tokio::timeout(...).await.expect("CRD was not installed in time") for a "one-liner" - also passes error info into the panic

Comment on lines +107 to +115
let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
if let Err(_) = tokio::time::timeout(
std::time::Duration::from_secs(2),
await_condition(crds, "coredbs.kube.rs", conditions::is_crd_established()),
)
.await
{
panic!("\n\nERROR: Did not find the CRD to be installed.\n\n")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example same pattern here to wait on CRD. kube-rs also offers custom conditions, so can write a function and wait until that is satisfied.

https://docs.rs/kube/latest/kube/runtime/wait/trait.Condition.html

@sjmiller609 sjmiller609 merged commit c670349 into main Dec 21, 2022
@sjmiller609 sjmiller609 deleted the COR-37 branch December 21, 2022 20:26
Comment on lines +82 to +88
let client_future = Client::try_default();
let client = match client_future.await {
Ok(wrapped_client) => wrapped_client,
Err(_error) => panic!("Please configure your Kubernetes Context"),
};
// Get the name of the currently selected namespace
let selected_namespace = Config::infer().await.unwrap().default_namespace;
Copy link

Choose a reason for hiding this comment

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

NB: you are technically doing Config::infer twice in this block. you could use the result of the config inference to create a Client

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 will check on this. Thank you!

ianstanton added a commit to ianstanton/coredb that referenced this pull request Mar 23, 2023
sjmiller609 pushed a commit that referenced this pull request Dec 5, 2023
hard code image in all containers
sjmiller609 pushed a commit that referenced this pull request Dec 5, 2023
* Updates test so it cleans up after itself and doesn't leave things in the config file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants