Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
qa: analyze test

analyze:
analyze: format-check
@cargo clippy

test:
@cargo test

format:
@cargo fmt

format-check:
@cargo fmt --check

.PHONY: analyze qa test
10 changes: 5 additions & 5 deletions src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// ```
Expand All @@ -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.
///
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 1 addition & 2 deletions src/event/event_types/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/event/event_types/event_candidate.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/event/event_types/management_event.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,7 +18,7 @@ pub struct ManagementEvent {
source: String,
specversion: String,
subject: String,
time: DateTime<Utc>,
time: DateTime<Utc>,
r#type: String,
}

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/event/trace_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Option<Self>, EventError> {
let traceparent = event.extension("traceparent").map(ToString::to_string);
let tracestate = event.extension("tracestate").map(ToString::to_string);
Expand Down
5 changes: 4 additions & 1 deletion tests/essentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
96 changes: 39 additions & 57 deletions tests/write_events.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down