mirror of
https://github.com/fluencelabs/marine.git
synced 2025-06-24 04:01:37 +00:00
Support build time in module manifests (#71)
This commit is contained in:
@ -47,4 +47,8 @@ pub enum ManifestError {
|
||||
/// Manifest contains some trailing characters.
|
||||
#[error("embedded manifest is corrupted: there are some trailing characters")]
|
||||
ManifestRemainderNotEmpty,
|
||||
|
||||
/// Error occurred while parsing embedded build time.
|
||||
#[error("build time can't be parsed: {0}")]
|
||||
DateTimeParseError(#[from] chrono::ParseError),
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ pub struct ModuleManifest {
|
||||
pub version: semver::Version,
|
||||
pub description: String,
|
||||
pub repository: String,
|
||||
pub build_time: chrono::DateTime<chrono::FixedOffset>,
|
||||
}
|
||||
|
||||
use super::ManifestError;
|
||||
@ -39,16 +40,20 @@ impl TryFrom<&[u8]> for ModuleManifest {
|
||||
let (version, next_offset) = try_extract_field_as_version(value, next_offset, "version")?;
|
||||
let (description, next_offset) = try_extract_field_as_string(value, next_offset, "description")?;
|
||||
let (repository, next_offset) = try_extract_field_as_string(value, next_offset, "repository")?;
|
||||
let (build_time, next_offset) = try_extract_field_as_string(value, next_offset, "build time")?;
|
||||
|
||||
if next_offset != value.len() {
|
||||
return Err(ManifestError::ManifestRemainderNotEmpty)
|
||||
}
|
||||
|
||||
let build_time = chrono::DateTime::parse_from_rfc3339(&build_time)?;
|
||||
|
||||
let manifest = ModuleManifest {
|
||||
authors,
|
||||
version,
|
||||
description,
|
||||
repository,
|
||||
build_time
|
||||
};
|
||||
|
||||
Ok(manifest)
|
||||
@ -140,6 +145,7 @@ impl fmt::Display for ModuleManifest {
|
||||
writeln!(f, "authors: {}", self.authors)?;
|
||||
writeln!(f, "version: {}", self.version)?;
|
||||
writeln!(f, "description: {}", self.description)?;
|
||||
write!(f, "repository: {}", self.repository)
|
||||
writeln!(f, "repository: {}", self.repository)?;
|
||||
write!(f, "build time: {} UTC", self.build_time)
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ fn test_reading_simple_config() {
|
||||
let version = semver::Version::from_str("0.1.0").unwrap();
|
||||
let description = "description".to_string();
|
||||
let repository = "repository".to_string();
|
||||
let build_time = chrono::Utc::now();
|
||||
|
||||
let mut array = ByteEncoder::new();
|
||||
|
||||
@ -78,6 +79,7 @@ fn test_reading_simple_config() {
|
||||
array.add_utf8_field(&version.to_string());
|
||||
array.add_utf8_field(&description);
|
||||
array.add_utf8_field(&repository);
|
||||
array.add_utf8_field(&build_time.to_rfc3339());
|
||||
|
||||
let actual: ModuleManifest = array
|
||||
.as_bytes()
|
||||
@ -89,6 +91,7 @@ fn test_reading_simple_config() {
|
||||
version,
|
||||
description,
|
||||
repository,
|
||||
build_time: build_time.into(),
|
||||
};
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
|
Reference in New Issue
Block a user