diff --git a/Makefile b/Makefile index 4eaee04..67282f2 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,12 @@ qa: analyze test analyze: @cargo clippy + @cargo fmt --check test: @cargo test -.PHONY: analyze qa test +format: + @cargo fmt + +.PHONY: analyze format qa test diff --git a/src/container.rs b/src/container.rs index b5833ea..d0af12a 100644 --- a/src/container.rs +++ b/src/container.rs @@ -137,10 +137,10 @@ impl ContainerBuilder { } /// A running test container for the [EventSourcingDB](https://www.eventsourcingdb.io/). -/// +/// /// Aside from managing the container, this struct also provides methods to get the data needed to connect to /// the database or even a fully configured client. -/// +/// /// You'll most likely want to use the [`Container::start_default`] method to create a new container instance for your tests. /// For more details, see the [`crate::container`] module documentation. /// ``` @@ -167,7 +167,7 @@ impl Container { } /// Shortcut method to start the container with default settings. - /// + /// /// This is the same as calling [`Container::builder`] and then [`ContainerBuilder::start`]. /// In most cases this will create a contaienr with the latest image tag and a working configuration. /// @@ -178,7 +178,7 @@ impl Container { } /// Get the host of the container. - /// + /// /// This is the host that you can use to connect to the database. In most cases this will be `localhost`. /// /// # Errors @@ -188,7 +188,7 @@ impl Container { } /// Get the mapped port for the database. - /// + /// /// This is the port that you can use to connect to the database. This will be a random port that is mapped to the internal port configured via [`ContainerBuilder::with_port`]. /// /// # Errors diff --git a/src/event.rs b/src/event.rs index f927015..be7fe0f 100644 --- a/src/event.rs +++ b/src/event.rs @@ -10,5 +10,5 @@ pub use event_types::event_candidate::EventCandidate; pub use event_types::management_event::ManagementEvent; pub use trace_info::TraceInfo; -#[cfg(feature="cloudevents")] +#[cfg(feature = "cloudevents")] use crate::error::EventError; diff --git a/src/event/event_types/event.rs b/src/event/event_types/event.rs index 1c730ce..93ed39d 100644 --- a/src/event/event_types/event.rs +++ b/src/event/event_types/event.rs @@ -2,8 +2,7 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use crate::event::{trace_info::TraceInfo, EventCandidate}; - +use crate::event::{EventCandidate, trace_info::TraceInfo}; /// Represents an event that has been received from the DB. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/src/event/event_types/event_candidate.rs b/src/event/event_types/event_candidate.rs index 9d5947d..fd21a0c 100644 --- a/src/event/event_types/event_candidate.rs +++ b/src/event/event_types/event_candidate.rs @@ -1,7 +1,7 @@ +use crate::event::trace_info::TraceInfo; use serde::{Deserialize, Serialize}; use serde_json::Value; use typed_builder::TypedBuilder; -use crate::event::trace_info::TraceInfo; #[cfg(feature = "cloudevents")] use crate::error::EventError; diff --git a/src/event/event_types/management_event.rs b/src/event/event_types/management_event.rs index f47893c..56c34dd 100644 --- a/src/event/event_types/management_event.rs +++ b/src/event/event_types/management_event.rs @@ -1,11 +1,11 @@ +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use chrono::{DateTime, Utc}; /// Represents a management event that has been received from the DB. -/// +/// /// For management requests like [`crate::client::Client::ping`] and [`crate::client::Client::verify_api_token`] the DB will send a management event. -/// +/// /// Compared to a normal Event, this does not contain the following fields: /// - hash /// - predecessorhash @@ -18,7 +18,7 @@ pub struct ManagementEvent { source: String, specversion: String, subject: String, - time: DateTime, + time: DateTime, r#type: String, } @@ -61,7 +61,7 @@ impl ManagementEvent { &self.time } /// Get the type of an event. - /// + /// /// This method is called `ty` to avoid conflicts with the `type` keyword in Rust. #[must_use] pub fn ty(&self) -> &str { diff --git a/src/event/trace_info.rs b/src/event/trace_info.rs index 7647423..598a415 100644 --- a/src/event/trace_info.rs +++ b/src/event/trace_info.rs @@ -10,7 +10,6 @@ use serde::{Deserialize, Serialize}; pub enum TraceInfo { // LEAVE ORDER AS IS // This is important for deserialization as the traceparent is always present - /// The traceparent and tracestate of the event. /// This is used for distributed tracing. WithState { @@ -52,7 +51,7 @@ impl TraceInfo { /// /// # Errors /// If the cloudevent contains a tracestate but no traceparent, an error will be returned. - #[cfg(feature="cloudevents")] + #[cfg(feature = "cloudevents")] pub fn from_cloudevent(event: &cloudevents::Event) -> Result, EventError> { let traceparent = event.extension("traceparent").map(ToString::to_string); let tracestate = event.extension("tracestate").map(ToString::to_string); diff --git a/tests/essentials.rs b/tests/essentials.rs index 49b2615..f4a835d 100644 --- a/tests/essentials.rs +++ b/tests/essentials.rs @@ -18,7 +18,10 @@ async fn ping_unavailable_server_errors() { async fn verify_api_token() { let container = Container::start_default().await.unwrap(); let client = container.get_client().await.unwrap(); - client.verify_api_token().await.expect("Failed to verify API token"); + client + .verify_api_token() + .await + .expect("Failed to verify API token"); } #[tokio::test] diff --git a/tests/write_events.rs b/tests/write_events.rs index 4883614..ff38cf4 100644 --- a/tests/write_events.rs +++ b/tests/write_events.rs @@ -1,7 +1,9 @@ mod utils; use eventsourcingdb_client_rust::{ - client::Precondition, container::Container, event::{EventCandidate, TraceInfo} + client::Precondition, + container::Container, + event::{EventCandidate, TraceInfo}, }; use serde_json::json; use utils::{ @@ -46,11 +48,9 @@ async fn write_event_with_is_pristine_condition_on_empty_subject() { let result = client .write_events( vec![event_candidate.clone()], - vec![ - Precondition::IsSubjectPristine { - subject: event_candidate.subject.clone(), - }, - ], + vec![Precondition::IsSubjectPristine { + subject: event_candidate.subject.clone(), + }], ) .await; assert!(result.is_ok(), "Failed to write events: {:?}", result); @@ -74,11 +74,9 @@ async fn write_event_with_is_pristine_condition_on_non_empty_subject() { let result = client .write_events( vec![event_candidate.clone()], - vec![ - Precondition::IsSubjectPristine { - subject: event_candidate.subject.clone(), - }, - ], + vec![Precondition::IsSubjectPristine { + subject: event_candidate.subject.clone(), + }], ) .await; assert!(result.is_err(), "Expected an error, but got: {:?}", result); @@ -96,11 +94,9 @@ async fn write_events_with_is_pristine_condition_on_empty_subject() { let result = client .write_events( event_candidates.clone(), - vec![ - Precondition::IsSubjectPristine { - subject: event_candidates[1].subject.clone(), - }, - ], + vec![Precondition::IsSubjectPristine { + subject: event_candidates[1].subject.clone(), + }], ) .await; assert!(result.is_ok(), "Failed to write events: {:?}", result); @@ -125,11 +121,9 @@ async fn write_events_with_is_pristine_condition_on_non_empty_subject() { let result = client .write_events( event_candidates, - vec![ - Precondition::IsSubjectPristine { - subject: fill_event_candidate.subject.clone(), - }, - ], + vec![Precondition::IsSubjectPristine { + subject: fill_event_candidate.subject.clone(), + }], ) .await; assert!(result.is_err(), "Expected an error, but got: {:?}", result); @@ -144,12 +138,10 @@ async fn write_event_with_is_subject_on_event_id_condition_on_empty_subject() { let result = client .write_events( vec![event_candidate.clone()], - vec![ - Precondition::IsSubjectOnEventId { - subject: event_candidate.subject.clone(), - event_id: "100".to_string(), - }, - ], + vec![Precondition::IsSubjectOnEventId { + subject: event_candidate.subject.clone(), + event_id: "100".to_string(), + }], ) .await; assert!(result.is_err(), "Expected an error, but got: {:?}", result); @@ -170,12 +162,10 @@ async fn write_event_with_is_subject_on_event_id_condition_on_non_empty_subject_ let result = client .write_events( vec![event_candidate.clone()], - vec![ - Precondition::IsSubjectOnEventId { - subject: event_candidate.subject.clone(), - event_id: written.id().to_string(), - }, - ], + vec![Precondition::IsSubjectOnEventId { + subject: event_candidate.subject.clone(), + event_id: written.id().to_string(), + }], ) .await; assert!(result.is_ok(), "Writing the event failed: {:?}", result); @@ -196,12 +186,10 @@ async fn write_event_with_is_subject_on_event_id_condition_on_non_empty_subject_ let result = client .write_events( vec![event_candidate.clone()], - vec![ - Precondition::IsSubjectOnEventId { - subject: event_candidate.subject.clone(), - event_id: 100.to_string(), - }, - ], + vec![Precondition::IsSubjectOnEventId { + subject: event_candidate.subject.clone(), + event_id: 100.to_string(), + }], ) .await; assert!(result.is_err(), "Expected an error, but got: {:?}", result); @@ -219,12 +207,10 @@ async fn write_events_with_is_subject_on_event_id_condition_on_empty_subject() { let result = client .write_events( event_candidates.clone(), - vec![ - Precondition::IsSubjectOnEventId { - subject: event_candidates[1].subject.clone(), - event_id: "100".to_string(), - }, - ], + vec![Precondition::IsSubjectOnEventId { + subject: event_candidates[1].subject.clone(), + event_id: "100".to_string(), + }], ) .await; assert!(result.is_err(), "Expected an error, but got: {:?}", result); @@ -249,12 +235,10 @@ async fn write_events_with_is_subject_on_event_id_condition_on_non_empty_subject let result = client .write_events( event_candidates, - vec![ - Precondition::IsSubjectOnEventId { - subject: fill_event_candidate.subject.clone(), - event_id: written.id().to_string(), - }, - ], + vec![Precondition::IsSubjectOnEventId { + subject: fill_event_candidate.subject.clone(), + event_id: written.id().to_string(), + }], ) .await; assert!(result.is_ok(), "Writing the events failed: {:?}", result); @@ -279,12 +263,10 @@ async fn write_events_with_is_subject_on_event_id_condition_on_non_empty_subject let result = client .write_events( event_candidates, - vec![ - Precondition::IsSubjectOnEventId { - subject: fill_event_candidate.subject.clone(), - event_id: 100.to_string(), - }, - ], + vec![Precondition::IsSubjectOnEventId { + subject: fill_event_candidate.subject.clone(), + event_id: 100.to_string(), + }], ) .await; assert!(result.is_err(), "Expected an error, but got: {:?}", result);