diff --git a/sessionspaces/Cargo.lock b/sessionspaces/Cargo.lock index 53cd86ed..ebb6dfb6 100644 --- a/sessionspaces/Cargo.lock +++ b/sessionspaces/Cargo.lock @@ -323,16 +323,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" -[[package]] -name = "colored" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" -dependencies = [ - "lazy_static", - "windows-sys 0.48.0", -] - [[package]] name = "concurrent-queue" version = "2.5.0" @@ -419,6 +409,24 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +[[package]] +name = "deadpool" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb84100978c1c7b37f09ed3ce3e5f843af02c2a2c431bae5b19230dad2c1b490" +dependencies = [ + "async-trait", + "deadpool-runtime", + "num_cpus", + "tokio", +] + +[[package]] +name = "deadpool-runtime" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" + [[package]] name = "der" version = "0.7.9" @@ -710,9 +718,9 @@ checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "h2" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" dependencies = [ "atomic-waker", "bytes", @@ -1248,30 +1256,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "mockito" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b34bd91b9e5c5b06338d392463e1318d683cf82ec3d3af4014609be6e2108d" -dependencies = [ - "assert-json-diff", - "bytes", - "colored", - "futures-util", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-util", - "log", - "rand", - "regex", - "serde_json", - "serde_urlencoded", - "similar", - "tokio", -] - [[package]] name = "nom" version = "7.1.3" @@ -1355,6 +1339,16 @@ dependencies = [ "libm", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.36.1" @@ -1998,7 +1992,6 @@ dependencies = [ "k8s-openapi", "kube", "ldap3", - "mockito", "serde_json", "sqlx", "strum", @@ -2008,6 +2001,7 @@ dependencies = [ "tracing", "tracing-subscriber", "url", + "wiremock", ] [[package]] @@ -2060,12 +2054,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "similar" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" - [[package]] name = "slab" version = "0.4.9" @@ -2507,7 +2495,6 @@ dependencies = [ "bytes", "libc", "mio", - "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -3049,6 +3036,30 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wiremock" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a59f8ae78a4737fb724f20106fb35ccb7cfe61ff335665d3042b3aa98e34717" +dependencies = [ + "assert-json-diff", + "async-trait", + "base64 0.21.7", + "deadpool", + "futures", + "http", + "http-body-util", + "hyper", + "hyper-util", + "log", + "once_cell", + "regex", + "serde", + "serde_json", + "tokio", + "url", +] + [[package]] name = "x509-parser" version = "0.15.1" diff --git a/sessionspaces/Cargo.toml b/sessionspaces/Cargo.toml index 28880f99..25646fc1 100644 --- a/sessionspaces/Cargo.toml +++ b/sessionspaces/Cargo.toml @@ -16,7 +16,6 @@ kube = { version = "0.93.1" } ldap3 = { version = "0.11.5", default-features = false, features = [ "tls-rustls", ] } -mockito = { version = "1.5.0" } serde_json = { version = "1.0.125" } sqlx = { version = "0.8.0", features = [ "runtime-tokio", @@ -31,3 +30,6 @@ tower = { version = "0.4.13", features = ["limit", "util"] } tracing = { version = "0.1.40" } tracing-subscriber = { version = "0.3.18" } url = { version = "2.5.2" } + +[dev-dependencies] +wiremock = "0.6.1" diff --git a/sessionspaces/src/resources/namespace.rs b/sessionspaces/src/resources/namespace.rs index 92a95786..70492440 100644 --- a/sessionspaces/src/resources/namespace.rs +++ b/sessionspaces/src/resources/namespace.rs @@ -61,36 +61,36 @@ pub async fn create_namespace( #[cfg(test)] mod tests { - use super::*; - use kube::Client; - use kube::Config; - use mockito::Server; + use super::create_namespace; + use k8s_openapi::api::core::v1::Namespace; + use kube::{api::ObjectMeta, Client, Config}; + use wiremock::{ + matchers::{body_partial_json, method, path, query_param}, + Mock, MockServer, ResponseTemplate, + }; #[tokio::test] async fn create_new_namespace() { - let mut server = Server::new_async().await; - let mock_patch_test_namespace = server - .mock( - "PATCH", - "/api/v1/namespaces/test?&fieldManager=sessionspaces", - ) - .with_status(201) - .with_header("content-type", "application/json") - .with_body( - r#"{ - "apiVersion": "v1", - "kind": "Namespace", - "metadata": { - "name": "test" - } - }"#, - ) - .create(); - let config = Config::new(server.url().parse().unwrap()); + let server = MockServer::start().await; + let namespace = Namespace { + metadata: ObjectMeta { + name: Some("cm37235-3".to_string()), + ..Default::default() + }, + ..Default::default() + }; + let _mock = Mock::given(method("PATCH")) + .and(path("/api/v1/namespaces/cm37235-3")) + .and(query_param("fieldManager", "sessionspaces")) + .and(body_partial_json(namespace.clone())) + .respond_with(ResponseTemplate::new(201).set_body_json(namespace)) + .expect(1) + .mount(&server) + .await; + let config = Config::new(server.uri().parse().unwrap()); let k8s_client = Client::try_from(config).unwrap(); - create_namespace("test".to_string(), k8s_client) + create_namespace("cm37235-3".to_string(), k8s_client) .await .unwrap(); - mock_patch_test_namespace.assert(); } }