Skip to content

Commit 73145c2

Browse files
authored
add tests to ensure padding is respected, fix KnownArtifactKind (#24)
Looks like parse-display doesn't do the right thing here, but strum does. Switch to strum.
1 parent 5dac8d1 commit 73145c2

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

Cargo.lock

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ hubtools = { git = "https://github.com/oxidecomputer/hubtools.git", branch = "ma
3939
humantime = "2.1.0"
4040
indent_write = "2.2.0"
4141
itertools = "0.13.0"
42-
parse-display = "0.10.0"
4342
parse-size = "1.1.0"
4443
predicates = "3.1.3"
4544
proptest = "1.5.0"

artifact/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ schemars = ["dep:schemars"]
1212
[dependencies]
1313
daft.workspace = true
1414
hex.workspace = true
15-
parse-display.workspace = true
1615
proptest = { workspace = true, optional = true }
1716
schemars = { workspace = true, optional = true }
1817
semver.workspace = true

artifact/src/artifact.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,17 @@ fn hex_schema<const N: usize>(
129129
schema.format = Some(format!("hex string ({N} bytes)"));
130130
schema.into()
131131
}
132+
133+
#[cfg(test)]
134+
mod tests {
135+
use super::*;
136+
137+
#[test]
138+
fn display_respects_padding() {
139+
let h = ArtifactHash([0; 32]);
140+
assert_eq!(
141+
format!("{h:x>100}"),
142+
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000000000000000000000000000000000000000000000000000000000000"
143+
);
144+
}
145+
}

artifact/src/kind.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
use std::{borrow::Cow, convert::Infallible, fmt, str::FromStr};
66

77
use daft::Diffable;
8-
use parse_display::{Display, FromStr};
98
use serde::{Deserialize, Serialize};
10-
use strum::{EnumIter, IntoEnumIterator};
9+
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
1110
use thiserror::Error;
1211

1312
/// The kind of artifact we are dealing with.
@@ -168,13 +167,13 @@ impl FromStr for ArtifactKind {
168167
Ord,
169168
PartialOrd,
170169
Display,
171-
FromStr,
170+
EnumString,
172171
Deserialize,
173172
Serialize,
174173
EnumIter,
175174
)]
176175
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
177-
#[display(style = "snake_case")]
176+
#[strum(serialize_all = "snake_case")]
178177
#[serde(rename_all = "snake_case")]
179178
pub enum KnownArtifactKind {
180179
// Sled Artifacts
@@ -289,4 +288,13 @@ mod tests {
289288
assert_eq!(kind, kind2);
290289
}
291290
}
291+
292+
#[test]
293+
fn display_respects_padding() {
294+
let kind = ArtifactKind::from_static("foo");
295+
assert_eq!(format!("{kind:x>10}"), "xxxxxxxfoo");
296+
297+
let kind = KnownArtifactKind::Host;
298+
assert_eq!(format!("{kind:x>10}"), "xxxxxxhost");
299+
}
292300
}

artifact/src/version.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ mod tests {
216216
);
217217
}
218218

219+
#[test]
220+
fn display_respects_padding() {
221+
let v = ArtifactVersion::new_const("5.4.3");
222+
assert_eq!(format!("{v:x>10}"), "xxxxx5.4.3");
223+
}
224+
219225
#[proptest]
220226
fn proptest_valid_version(#[strategy(PROPTEST_REGEX)] version: String) {
221227
validate_version(&version).unwrap();

0 commit comments

Comments
 (0)