Skip to content

Commit 63f3dfc

Browse files
authored
[nexus-config] use pretty_assertions in tests (#7798)
Currently, assertion failures from the `nexus-config` tests are pretty hard to interpret. When we assert a parsed config matches the expected config, we use `assert_eq!`, which uses the default `fmt::Debug` formatter. As the config types are quite complex, this spits out a huge amount of text, and it's all on one line. the differences between the actual and expected onfig are pretty hard to find. For example, see [this failure on Buildomat][1]. This commit changes these tests to use the `pretty_assertions` crate's `assert_eq!` macro, which formats the difference between the actual and expected values as a diff, highlighting what didn't match. I also considered using `daft` to diff these values, but `pretty_assertions` is already in our dep tree, and didn't require any additional code outside of the tests (where `daft` would require deriving stuff for the config types). For this use case, the simple textual diff seems sufficient. [1]: https://buildomat.eng.oxide.computer/wg/0/details/01JP8BHQ5Z41DPB6GEK4D2K3N9/PhIpT14ekjFiDaHBPM5hDzWVhYr53VTLUXpaAAs6veI1rUJh/01JP8BJ6EZH8RRE1V27DGK7DDG#S6106
1 parent 288c1a1 commit 63f3dfc

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nexus-config/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ uuid.workspace = true
2424
expectorate.workspace = true
2525
libc.workspace = true
2626
serde_json.workspace = true
27+
pretty_assertions.workspace = true

nexus-config/src/nexus_config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ mod test {
830830
use dropshot::ConfigLogging;
831831
use dropshot::ConfigLoggingIfExists;
832832
use dropshot::ConfigLoggingLevel;
833+
use pretty_assertions::assert_eq;
833834
use std::collections::HashMap;
834835
use std::fs;
835836
use std::net::{Ipv6Addr, SocketAddr, SocketAddrV6};

0 commit comments

Comments
 (0)