diff --git a/Makefile b/Makefile index 8625195..87faf74 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CARGO = CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse RUSTFLAGS="--cfg tokio_unstab all: build check-fmt check-clippy test .PHONY: test -test: update +test: # Test with default features ${CARGO} test --locked # Test with all features @@ -20,7 +20,7 @@ check-fmt: update: ${CARGO} update -.PHONY: check-clippy +.PHONY: check-clippy check-clippy: # Check with default features ${CARGO} clippy --workspace diff --git a/operator/src/network/stub.rs b/operator/src/network/stub.rs index 9dd2a1b..01cface 100644 --- a/operator/src/network/stub.rs +++ b/operator/src/network/stub.rs @@ -61,39 +61,70 @@ type PodMonitorStub = ( #[derive(Debug)] pub struct Stub { network: Network, + /// Expected delete requests pub delete: Option>, + /// Expected namespace pub namespace: ExpectPatch, + /// Expected network status pub status: ExpectPatch, + /// Expected monitoring requests pub monitoring: Vec, + /// Expected pod monitor pub pod_monitor: Vec, + /// Expected cas_postgres_auth_secret pub cas_postgres_auth_secret: (ExpectPatch, Secret, bool), + /// Expected ceramic_postgres_auth_secret pub ceramic_postgres_auth_secret: (ExpectPatch, Secret), + /// Expected ceramic_admin_secret_missing pub ceramic_admin_secret_missing: (ExpectPatch, Option), + /// Expected ceramic_admin_secret_source pub ceramic_admin_secret_source: Option<(ExpectPatch, Option, bool)>, + /// Expected ceramic_admin_secret pub ceramic_admin_secret: Option<(ExpectPatch, Option)>, + /// Expected ceramic_list_stateful_sets pub ceramic_list_stateful_sets: (ExpectPatch, Option>), + /// Expected ceramic_list_services pub ceramic_list_services: (ExpectPatch, Option>), + /// Expected ceramic_deletes pub ceramic_deletes: Vec>, + /// Expected ceramic_pod_status pub ceramic_pod_status: Vec<(ExpectPatch, Option)>, + /// Expected keramik_peers_configmap pub keramik_peers_configmap: ExpectPatch, + /// Expected ceramics pub ceramics: Vec, + /// Expected cas_service pub cas_service: ExpectPatch, + /// Expected cas_ipfs_service pub cas_ipfs_service: ExpectPatch, + /// Expected ganache_service pub ganache_service: ExpectPatch, + /// Expected cas_postgres_service pub cas_postgres_service: ExpectPatch, + /// Expected localstack_service pub localstack_service: ExpectPatch, + /// Expected cas_stateful_set pub cas_stateful_set: ExpectPatch, + /// Expected cas_ipfs_stateful_set pub cas_ipfs_stateful_set: ExpectPatch, + /// Expected ganache_stateful_set pub ganache_stateful_set: ExpectPatch, + /// Expected cas_postgres_stateful_set pub cas_postgres_stateful_set: ExpectPatch, + /// Expected localstack_stateful_set pub localstack_stateful_set: ExpectPatch, + /// Expected bootstrap_job pub bootstrap_job: Vec<(ExpectFile, Option)>, } +/// Stub for the Ceramic related requests #[derive(Debug)] pub struct CeramicStub { + /// Expected config maps pub configmaps: Vec>, + /// Expected stateful set pub stateful_set: ExpectPatch, + /// Expected service pub service: ExpectPatch, } @@ -196,6 +227,7 @@ impl Default for Stub { } impl Stub { + /// Stub with a network pub fn with_network(self, network: Network) -> Self { Self { network, ..self } } diff --git a/operator/src/simulation/stub.rs b/operator/src/simulation/stub.rs index 67e53ec..907f16e 100644 --- a/operator/src/simulation/stub.rs +++ b/operator/src/simulation/stub.rs @@ -60,23 +60,35 @@ impl WithStatus for Simulation { #[derive(Debug)] pub struct Stub { simulation: Simulation, + /// Expected peers config map pub peers_config_map: (ExpectPatch, ConfigMap), + /// Expected jaeger status pub jaeger_status: (ExpectPatch, StatefulSet), + /// Expected prometheus status pub prom_status: (ExpectPatch, StatefulSet), + /// Expected open telemetry status pub otel_status: (ExpectPatch, StatefulSet), + /// Expected redis service pub redis_service: ExpectPatch, + /// Expected redis stateful set pub redis_stateful_set: ExpectPatch, + /// Expected redis status pub redis_status: (ExpectPatch, StatefulSet), + /// Expected goose service pub goose_service: ExpectPatch, + /// Expected manager job pub manager_job: ExpectPatch, + /// Expected manager status pub manager_status: (ExpectPatch, Job), + /// Expected worker jobs pub worker_jobs: Vec>, + /// Expected simulation status pub status: ExpectPatch, } @@ -175,6 +187,7 @@ impl Default for Stub { } impl Stub { + /// Set the simulation on the stub pub fn with_simulation(self, simulation: Simulation) -> Self { Self { simulation, ..self } } diff --git a/operator/src/utils/test.rs b/operator/src/utils/test.rs index 577265c..6618c47 100644 --- a/operator/src/utils/test.rs +++ b/operator/src/utils/test.rs @@ -14,6 +14,7 @@ use crate::{ utils::{Clock, Context, UtcClock}, }; +/// Type for a test handle to the k8s API server pub type ApiServerHandle = tower_test::mock::Handle, http::Response>; // Add test specific implementation to the Context @@ -21,8 +22,8 @@ impl Context where R: IpfsRpcClient, { - // Create a test context with a mocked kube and rpc clients - // Uses real clock + /// Create a test context with a mocked kube and rpc clients + /// Uses real clock pub fn test(mock_rpc_client: R) -> (Arc, ApiServerHandle) { Self::test_with_clock(mock_rpc_client, UtcClock) } @@ -33,7 +34,7 @@ where R: IpfsRpcClient, C: Clock, { - // Create a test context with a mocked kube and rpc clients + /// Create a test context with a mocked kube and rpc clients pub fn test_with_clock(mock_rpc_client: R, clock: C) -> (Arc, ApiServerHandle) { let (mock_service, handle) = tower_test::mock::pair::, http::Response>(); @@ -48,6 +49,7 @@ where } } +/// Utility to timeout a task after one second. pub async fn timeout_after_1s(handle: tokio::task::JoinHandle) -> T { tokio::time::timeout(std::time::Duration::from_secs(1), handle) .await @@ -58,8 +60,11 @@ pub async fn timeout_after_1s(handle: tokio::task::JoinHandle) -> T { /// ApiServerVerifier verifies that the serve is called according to test expectations. pub struct ApiServerVerifier(ApiServerHandle); +/// Builder trait to add a status to a value. pub trait WithStatus { + /// The type of the status itself. type Status; + /// Add the status to self. fn with_status(self, status: Self::Status) -> Self; } @@ -69,6 +74,7 @@ impl ApiServerVerifier { Self(handle) } + /// Make a patch request and verify the expected result. pub async fn handle_patch_status( &mut self, expected_request: impl Expectation, @@ -98,7 +104,7 @@ impl ApiServerVerifier { ); Ok(resource) } - + /// Make an apply request and verify expected result. pub async fn handle_apply(&mut self, expected_request: impl Expectation) -> Result<()> { let (request, send) = self.0.next_request().await.expect("service not called"); let request = Request::from_request(request).await?; @@ -111,6 +117,7 @@ impl ApiServerVerifier { ); Ok(()) } + /// Make a request and verify the expected response. pub async fn handle_request_response( &mut self, expected_request: impl Expectation, @@ -148,9 +155,13 @@ impl ApiServerVerifier { /// The only purpose of this struct is its debug implementation /// to be used in expect![[]] calls. pub struct Request { + /// HTTP method pub method: String, + /// URI pub uri: String, + /// Headers pub headers: HeaderMap, + /// String representation of the body pub body: Raw, } @@ -167,6 +178,7 @@ impl std::fmt::Debug for Request { } impl Request { + /// Construct a Request from an http::Request pub async fn from_request(request: http::Request) -> Result { let method = request.method().to_string(); let uri = request.uri().to_string(); @@ -188,7 +200,7 @@ impl Request { } } -// Raw String the does not escape its value for debugging +/// Raw String the does not escape its value for debugging pub struct Raw(pub String); impl std::fmt::Debug for Raw { diff --git a/runner/src/scenario/ceramic/query.rs b/runner/src/scenario/ceramic/query.rs index 0bea293..8a01a93 100644 --- a/runner/src/scenario/ceramic/query.rs +++ b/runner/src/scenario/ceramic/query.rs @@ -104,7 +104,7 @@ async fn query_large_mid_verify_edges( ) .await?; - if resp.edges.first().is_none() { + if resp.edges.is_empty() { goose_try!(user, "query", &mut metrics, { Err(anyhow::anyhow!("no edges returned")) })?;