Skip to content

Commit

Permalink
some renames; better formatting in spec models
Browse files Browse the repository at this point in the history
Signed-off-by: mimir-d <[email protected]>
  • Loading branch information
mimir-d committed Oct 8, 2024
1 parent 9a2cc6f commit 4959484
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 102 deletions.
18 changes: 9 additions & 9 deletions src/output/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use std::path::Path;
use std::sync::Arc;
use tokio::sync::Mutex;

use crate::output::emitters;
use crate::output::emitter;

/// The configuration repository for the TestRun.
pub struct Config {
pub(crate) timezone: chrono_tz::Tz,
pub(crate) writer: emitters::WriterType,
pub(crate) writer: emitter::WriterType,
}

impl Config {
Expand All @@ -33,14 +33,14 @@ impl Config {
/// The builder for the [`Config`] object.
pub struct ConfigBuilder {
timezone: Option<chrono_tz::Tz>,
writer: Option<emitters::WriterType>,
writer: Option<emitter::WriterType>,
}

impl ConfigBuilder {
fn new() -> Self {
Self {
timezone: None,
writer: Some(emitters::WriterType::Stdout(emitters::StdoutWriter::new())),
writer: Some(emitter::WriterType::Stdout(emitter::StdoutWriter::new())),
}
}

Expand All @@ -50,7 +50,7 @@ impl ConfigBuilder {
}

pub fn with_buffer_output(mut self, buffer: Arc<Mutex<Vec<String>>>) -> Self {
self.writer = Some(emitters::WriterType::Buffer(emitters::BufferWriter::new(
self.writer = Some(emitter::WriterType::Buffer(emitter::BufferWriter::new(
buffer,
)));
self
Expand All @@ -59,9 +59,9 @@ impl ConfigBuilder {
pub async fn with_file_output<P: AsRef<Path>>(
mut self,
path: P,
) -> Result<Self, emitters::WriterError> {
self.writer = Some(emitters::WriterType::File(
emitters::FileWriter::new(path).await?,
) -> Result<Self, emitter::WriterError> {
self.writer = Some(emitter::WriterType::File(
emitter::FileWriter::new(path).await?,
));
Ok(self)
}
Expand All @@ -71,7 +71,7 @@ impl ConfigBuilder {
timezone: self.timezone.unwrap_or(chrono_tz::UTC),
writer: self
.writer
.unwrap_or(emitters::WriterType::Stdout(emitters::StdoutWriter::new())),
.unwrap_or(emitter::WriterType::Stdout(emitter::StdoutWriter::new())),
}
}
}
12 changes: 6 additions & 6 deletions src/output/emitters.rs → src/output/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ impl JsonEmitter {
}
}

fn serialize_artifact(&self, object: &models::OutputArtifactDescendant) -> serde_json::Value {
fn serialize_artifact(&self, object: &models::RootArtifactSpec) -> serde_json::Value {
let now = chrono::Local::now();
let now_tz = now.with_timezone(&self.timezone);
let out_artifact = models::OutputArtifactSpec {
descendant: object.clone(),
now: now_tz,
sequence_number: self.next_sequence_no(),
let out_artifact = models::RootSpec {
artifact: object.clone(),
timestamp: now_tz,
seqno: self.next_sequence_no(),
};
serde_json::json!(out_artifact)
}
Expand All @@ -114,7 +114,7 @@ impl JsonEmitter {
self.sequence_no.load(atomic::Ordering::SeqCst)
}

pub async fn emit(&self, object: &models::OutputArtifactDescendant) -> Result<(), WriterError> {
pub async fn emit(&self, object: &models::RootArtifactSpec) -> Result<(), WriterError> {
let serialized = self.serialize_artifact(object);
match self.writer {
WriterType::File(ref file) => file.write(&serialized.to_string()).await?,
Expand Down
40 changes: 20 additions & 20 deletions src/output/measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde_json::Value;
use tokio::sync::Mutex;

use crate::output as tv;
use tv::{dut, emitters, models, state};
use tv::{dut, emitter, models, state};

/// The measurement series.
/// A Measurement Series is a time-series list of measurements.
Expand Down Expand Up @@ -76,7 +76,7 @@ impl MeasurementSeries {
/// # Ok::<(), WriterError>(())
/// # });
/// ```
pub async fn start(&self) -> Result<(), emitters::WriterError> {
pub async fn start(&self) -> Result<(), emitter::WriterError> {
self.state
.lock()
.await
Expand Down Expand Up @@ -106,7 +106,7 @@ impl MeasurementSeries {
/// # Ok::<(), WriterError>(())
/// # });
/// ```
pub async fn end(&self) -> Result<(), emitters::WriterError> {
pub async fn end(&self) -> Result<(), emitter::WriterError> {
let end =
MeasurementSeriesEnd::new(self.start.get_series_id(), self.current_sequence_no().await);
self.state
Expand Down Expand Up @@ -138,7 +138,7 @@ impl MeasurementSeries {
/// # Ok::<(), WriterError>(())
/// # });
/// ```
pub async fn add_measurement(&self, value: Value) -> Result<(), emitters::WriterError> {
pub async fn add_measurement(&self, value: Value) -> Result<(), emitter::WriterError> {
let element = MeasurementSeriesElement::new(
self.current_sequence_no().await,
value,
Expand Down Expand Up @@ -180,7 +180,7 @@ impl MeasurementSeries {
&self,
value: Value,
metadata: Vec<(&str, Value)>,
) -> Result<(), emitters::WriterError> {
) -> Result<(), emitter::WriterError> {
let element = MeasurementSeriesElement::new(
self.current_sequence_no().await,
value,
Expand Down Expand Up @@ -227,9 +227,9 @@ impl MeasurementSeries {
/// # Ok::<(), WriterError>(())
/// # });
/// ```
pub async fn scope<'a, F, R>(&'a self, func: F) -> Result<(), emitters::WriterError>
pub async fn scope<'a, F, R>(&'a self, func: F) -> Result<(), emitter::WriterError>
where
R: Future<Output = Result<(), emitters::WriterError>>,
R: Future<Output = Result<(), emitter::WriterError>>,
F: std::ops::FnOnce(&'a MeasurementSeries) -> R,
{
self.start().await?;
Expand Down Expand Up @@ -405,8 +405,8 @@ impl Measurement {
/// let measurement = Measurement::new("name", 50.into());
/// let _ = measurement.to_artifact();
/// ```
pub fn to_artifact(&self) -> models::OutputArtifactDescendant {
models::OutputArtifactDescendant::TestStepArtifact(models::TestStepArtifactSpec {
pub fn to_artifact(&self) -> models::RootArtifactSpec {
models::RootArtifactSpec::TestStepArtifact(models::TestStepArtifactSpec {
descendant: models::TestStepArtifactDescendant::Measurement(models::MeasurementSpec {
name: self.name.clone(),
unit: self.unit.clone(),
Expand Down Expand Up @@ -633,8 +633,8 @@ impl MeasurementSeriesStart {
MeasurementSeriesStartBuilder::new(name, series_id)
}

pub fn to_artifact(&self) -> models::OutputArtifactDescendant {
models::OutputArtifactDescendant::TestStepArtifact(models::TestStepArtifactSpec {
pub fn to_artifact(&self) -> models::RootArtifactSpec {
models::RootArtifactSpec::TestStepArtifact(models::TestStepArtifactSpec {
descendant: models::TestStepArtifactDescendant::MeasurementSeriesStart(
models::MeasurementSeriesStartSpec {
name: self.name.clone(),
Expand Down Expand Up @@ -758,8 +758,8 @@ impl MeasurementSeriesEnd {
}
}

pub fn to_artifact(&self) -> models::OutputArtifactDescendant {
models::OutputArtifactDescendant::TestStepArtifact(models::TestStepArtifactSpec {
pub fn to_artifact(&self) -> models::RootArtifactSpec {
models::RootArtifactSpec::TestStepArtifact(models::TestStepArtifactSpec {
descendant: models::TestStepArtifactDescendant::MeasurementSeriesEnd(
models::MeasurementSeriesEndSpec {
series_id: self.series_id.clone(),
Expand Down Expand Up @@ -794,8 +794,8 @@ impl MeasurementSeriesElement {
}
}

pub fn to_artifact(&self) -> models::OutputArtifactDescendant {
models::OutputArtifactDescendant::TestStepArtifact(models::TestStepArtifactSpec {
pub fn to_artifact(&self) -> models::RootArtifactSpec {
models::RootArtifactSpec::TestStepArtifact(models::TestStepArtifactSpec {
descendant: models::TestStepArtifactDescendant::MeasurementSeriesElement(
models::MeasurementSeriesElementSpec {
index: self.index,
Expand Down Expand Up @@ -827,7 +827,7 @@ mod tests {
let artifact = measurement.to_artifact();
assert_eq!(
artifact,
models::OutputArtifactDescendant::TestStepArtifact(models::TestStepArtifactSpec {
models::RootArtifactSpec::TestStepArtifact(models::TestStepArtifactSpec {
descendant: models::TestStepArtifactDescendant::Measurement(
models::MeasurementSpec {
name: name.to_string(),
Expand Down Expand Up @@ -874,7 +874,7 @@ mod tests {
let artifact = measurement.to_artifact();
assert_eq!(
artifact,
models::OutputArtifactDescendant::TestStepArtifact(models::TestStepArtifactSpec {
models::RootArtifactSpec::TestStepArtifact(models::TestStepArtifactSpec {
descendant: models::TestStepArtifactDescendant::Measurement(
models::MeasurementSpec {
name,
Expand All @@ -901,7 +901,7 @@ mod tests {
let artifact = series.to_artifact();
assert_eq!(
artifact,
models::OutputArtifactDescendant::TestStepArtifact(models::TestStepArtifactSpec {
models::RootArtifactSpec::TestStepArtifact(models::TestStepArtifactSpec {
descendant: models::TestStepArtifactDescendant::MeasurementSeriesStart(
models::MeasurementSeriesStartSpec {
name: name.to_string(),
Expand Down Expand Up @@ -940,7 +940,7 @@ mod tests {
let artifact = series.to_artifact();
assert_eq!(
artifact,
models::OutputArtifactDescendant::TestStepArtifact(models::TestStepArtifactSpec {
models::RootArtifactSpec::TestStepArtifact(models::TestStepArtifactSpec {
descendant: models::TestStepArtifactDescendant::MeasurementSeriesStart(
models::MeasurementSeriesStartSpec {
name,
Expand Down Expand Up @@ -969,7 +969,7 @@ mod tests {
let artifact = series.to_artifact();
assert_eq!(
artifact,
models::OutputArtifactDescendant::TestStepArtifact(models::TestStepArtifactSpec {
models::RootArtifactSpec::TestStepArtifact(models::TestStepArtifactSpec {
descendant: models::TestStepArtifactDescendant::MeasurementSeriesEnd(
models::MeasurementSeriesEndSpec {
series_id: series_id.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mod config;
mod dut;
mod emitters;
mod emitter;
mod error;
mod log;
mod macros;
Expand All @@ -18,7 +18,7 @@ mod step;

pub use config::*;
pub use dut::*;
pub use emitters::*;
pub use emitter::*;
pub use error::*;
pub use log::*;
pub use measurement::*;
Expand Down
Loading

0 comments on commit 4959484

Please sign in to comment.