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

fix: fix new clippy warning #207

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +20,7 @@ check-fmt:
update:
${CARGO} update

.PHONY: check-clippy
.PHONY: check-clippy
check-clippy:
# Check with default features
${CARGO} clippy --workspace
Expand Down
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
2 changes: 1 addition & 1 deletion runner/src/scenario/ceramic/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})?;
Expand Down
Loading