Skip to content

Commit

Permalink
fix: more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Dec 17, 2024
1 parent f7296e0 commit 40b4456
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
32 changes: 32 additions & 0 deletions operator/src/network/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,39 +61,70 @@ type PodMonitorStub = (
#[derive(Debug)]
pub struct Stub {
network: Network,
/// Expected delete requests
pub delete: Option<ExpectPatch<ExpectFile>>,
/// Expected namespace
pub namespace: ExpectPatch<ExpectFile>,
/// Expected network status
pub status: ExpectPatch<ExpectFile>,
/// Expected monitoring requests
pub monitoring: Vec<ExpectFile>,
/// Expected pod monitor
pub pod_monitor: Vec<PodMonitorStub>,
/// Expected cas_postgres_auth_secret
pub cas_postgres_auth_secret: (ExpectPatch<ExpectFile>, Secret, bool),
/// Expected ceramic_postgres_auth_secret
pub ceramic_postgres_auth_secret: (ExpectPatch<ExpectFile>, Secret),
/// Expected ceramic_admin_secret_missing
pub ceramic_admin_secret_missing: (ExpectPatch<ExpectFile>, Option<Secret>),
/// Expected ceramic_admin_secret_source
pub ceramic_admin_secret_source: Option<(ExpectPatch<ExpectFile>, Option<Secret>, bool)>,
/// Expected ceramic_admin_secret
pub ceramic_admin_secret: Option<(ExpectPatch<ExpectFile>, Option<Secret>)>,
/// Expected ceramic_list_stateful_sets
pub ceramic_list_stateful_sets: (ExpectPatch<ExpectFile>, Option<ObjectList<StatefulSet>>),
/// Expected ceramic_list_services
pub ceramic_list_services: (ExpectPatch<ExpectFile>, Option<ObjectList<Service>>),
/// Expected ceramic_deletes
pub ceramic_deletes: Vec<ExpectPatch<ExpectFile>>,
/// Expected ceramic_pod_status
pub ceramic_pod_status: Vec<(ExpectPatch<ExpectFile>, Option<Pod>)>,
/// Expected keramik_peers_configmap
pub keramik_peers_configmap: ExpectPatch<ExpectFile>,
/// Expected ceramics
pub ceramics: Vec<CeramicStub>,
/// Expected cas_service
pub cas_service: ExpectPatch<ExpectFile>,
/// Expected cas_ipfs_service
pub cas_ipfs_service: ExpectPatch<ExpectFile>,
/// Expected ganache_service
pub ganache_service: ExpectPatch<ExpectFile>,
/// Expected cas_postgres_service
pub cas_postgres_service: ExpectPatch<ExpectFile>,
/// Expected localstack_service
pub localstack_service: ExpectPatch<ExpectFile>,
/// Expected cas_stateful_set
pub cas_stateful_set: ExpectPatch<ExpectFile>,
/// Expected cas_ipfs_stateful_set
pub cas_ipfs_stateful_set: ExpectPatch<ExpectFile>,
/// Expected ganache_stateful_set
pub ganache_stateful_set: ExpectPatch<ExpectFile>,
/// Expected cas_postgres_stateful_set
pub cas_postgres_stateful_set: ExpectPatch<ExpectFile>,
/// Expected localstack_stateful_set
pub localstack_stateful_set: ExpectPatch<ExpectFile>,
/// Expected bootstrap_job
pub bootstrap_job: Vec<(ExpectFile, Option<Job>)>,
}

/// Stub for the Ceramic related requests
#[derive(Debug)]
pub struct CeramicStub {
/// Expected config maps
pub configmaps: Vec<ExpectPatch<ExpectFile>>,
/// Expected stateful set
pub stateful_set: ExpectPatch<ExpectFile>,
/// Expected service
pub service: ExpectPatch<ExpectFile>,
}

Expand Down Expand Up @@ -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 }
}
Expand Down
13 changes: 13 additions & 0 deletions operator/src/simulation/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,35 @@ impl WithStatus for Simulation {
#[derive(Debug)]
pub struct Stub {
simulation: Simulation,
/// Expected peers config map
pub peers_config_map: (ExpectPatch<ExpectFile>, ConfigMap),

/// Expected jaeger status
pub jaeger_status: (ExpectPatch<ExpectFile>, StatefulSet),
/// Expected prometheus status
pub prom_status: (ExpectPatch<ExpectFile>, StatefulSet),
/// Expected open telemetry status
pub otel_status: (ExpectPatch<ExpectFile>, StatefulSet),

/// Expected redis service
pub redis_service: ExpectPatch<ExpectFile>,
/// Expected redis stateful set
pub redis_stateful_set: ExpectPatch<ExpectFile>,
/// Expected redis status
pub redis_status: (ExpectPatch<ExpectFile>, StatefulSet),

/// Expected goose service
pub goose_service: ExpectPatch<ExpectFile>,
/// Expected manager job
pub manager_job: ExpectPatch<ExpectFile>,

/// Expected manager status
pub manager_status: (ExpectPatch<ExpectFile>, Job),

/// Expected worker jobs
pub worker_jobs: Vec<ExpectPatch<ExpectFile>>,

/// Expected simulation status
pub status: ExpectPatch<ExpectFile>,
}

Expand Down Expand Up @@ -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 }
}
Expand Down
22 changes: 17 additions & 5 deletions operator/src/utils/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ use crate::{
utils::{Clock, Context, UtcClock},
};

/// Type for a test handle to the k8s API server
pub type ApiServerHandle = tower_test::mock::Handle<http::Request<Body>, http::Response<Body>>;

// Add test specific implementation to the Context
impl<R> Context<R, StepRng, UtcClock>
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<Self>, ApiServerHandle) {
Self::test_with_clock(mock_rpc_client, UtcClock)
}
Expand All @@ -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<Self>, ApiServerHandle) {
let (mock_service, handle) =
tower_test::mock::pair::<http::Request<Body>, http::Response<Body>>();
Expand All @@ -48,6 +49,7 @@ where
}
}

/// Utility to timeout a task after one second.
pub async fn timeout_after_1s<T>(handle: tokio::task::JoinHandle<T>) -> T {
tokio::time::timeout(std::time::Duration::from_secs(1), handle)
.await
Expand All @@ -58,8 +60,11 @@ pub async fn timeout_after_1s<T>(handle: tokio::task::JoinHandle<T>) -> 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;
}

Expand All @@ -69,6 +74,7 @@ impl ApiServerVerifier {
Self(handle)
}

/// Make a patch request and verify the expected result.
pub async fn handle_patch_status<R>(
&mut self,
expected_request: impl Expectation,
Expand Down Expand Up @@ -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?;
Expand All @@ -111,6 +117,7 @@ impl ApiServerVerifier {
);
Ok(())
}
/// Make a request and verify the expected response.
pub async fn handle_request_response<T>(
&mut self,
expected_request: impl Expectation,
Expand Down Expand Up @@ -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,
}

Expand All @@ -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<Body>) -> Result<Self> {
let method = request.method().to_string();
let uri = request.uri().to_string();
Expand All @@ -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 {
Expand Down

0 comments on commit 40b4456

Please sign in to comment.