Skip to content

Commit

Permalink
still work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmiller609 committed Dec 20, 2022
1 parent 1ee18b1 commit b82ec09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
2 changes: 2 additions & 0 deletions coredb-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ cargo test
kubectl label namespace default safe-to-run-coredb-tests=true
```

- Start or install the controller you want to test (see the following sections)
- Run the integration tests
```
cargo test -- --ignored
```
- The integration tests assume you already have installed or are running the operator connected to the cluster.

### Cluster
As an example; get `k3d` then:
Expand Down
37 changes: 28 additions & 9 deletions coredb-operator/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,41 @@
// To run all tests, use 'cargo test -- --include-ignored'
//
// https://doc.rust-lang.org/book/ch11-02-running-tests.html
//
// These tests assume there is already kubernetes running and you have a context configured.
// It also assumes that the CRD(s) and operator are already installed for this cluster.
// In this way, it can be used as a conformance test on a target, separate from installation.

use kube::Api;
use kube::api::{PatchParams, Patch};
use controller::CoreDB;

#[tokio::test]
#[ignore]
async fn it_is() {
async fn functional_test_creates_running_pod() {
// Initialize the Kubernetes client
let _client = kube_client().await;
assert!(true);
let client = kube_client().await;

let coredbs: Api<CoreDB> = Api::namespaced(client, "default");
let coredb_json = serde_json::json!({
"apiVersion": "kube.rs/v1",
"kind": "CoreDB",
"metadata": {
"name": "sample-coredb"
},
"spec": {
"replicas": 1
}
});
let params = PatchParams::apply("coredb-integration-test");
let patch = Patch::Apply(&coredb_json);
let coredb_resource = coredbs.patch("sample-coredb", &params, &patch).await;
panic!("{:?}", coredb_resource)
}

async fn kube_client() -> kube::Client {
use k8s_openapi::api::core::v1::Namespace;
use kube::{api::Api, Client, Config};
use kube::{Client, Config};

// Initialize the Kubernetes client
let client_future = Client::try_default();
Expand All @@ -29,10 +52,6 @@ async fn kube_client() -> kube::Client {
// Next, check that the currently selected namespace is labeled
// to allow the running of tests.

// Set the labels you want to filter by
// let mut params = ListParams::default();
// params.labels("safe-to-run-coredb-testing=true");

// List the namespaces with the specified labels
let namespaces: Api<Namespace> = Api::all(client.clone());
let namespace = namespaces.get(&selected_namespace).await.unwrap();
Expand All @@ -45,5 +64,5 @@ async fn kube_client() -> kube::Client {
labels["safe-to-run-coredb-tests"], "true",
"expected to find label 'safe-to-run-core-db-tests' with value 'true'"
);
client
return client
}

0 comments on commit b82ec09

Please sign in to comment.