Skip to content

Commit 8d7939d

Browse files
authored
test: collapse per-variant test clusters in ib-fabric, admin-cli, and libmlx (#2710)
1 parent cb07b44 commit 8d7939d

13 files changed

Lines changed: 554 additions & 855 deletions

File tree

crates/admin-cli/src/boot_override/tests.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,48 +46,35 @@ fn verify_cmd_structure() {
4646
// including testing required arguments, as well as optional
4747
// flag-specific checking.
4848

49-
// parse_get ensures the get subcommand routes to the Get variant and
50-
// parses its interface_id.
49+
// The get and clear subcommands each route to their own variant and parse the
50+
// shared interface_id. The closure yields the routed variant name paired with the
51+
// parsed interface_id, so one table covers both.
5152
#[test]
52-
fn parse_get() {
53+
fn parse_get_and_clear() {
5354
scenarios!(
5455
run = |argv| {
5556
Cmd::try_parse_from(argv.iter().copied())
5657
.map(|cmd| match cmd {
57-
Cmd::Get(args) => args.inner.interface_id.to_string(),
58-
_ => panic!("expected Get variant"),
58+
Cmd::Get(args) => ("get", args.inner.interface_id.to_string()),
59+
Cmd::Clear(args) => ("clear", args.inner.interface_id.to_string()),
60+
_ => panic!("expected Get or Clear variant"),
5961
})
6062
.map_err(drop)
6163
};
62-
"get parses interface_id" {
64+
"get routes to Get and parses interface_id" {
6365
&[
6466
"boot-override",
6567
"get",
6668
"550e8400-e29b-41d4-a716-446655440000",
67-
][..] => Yields("550e8400-e29b-41d4-a716-446655440000".to_string()),
69+
][..] => Yields(("get", "550e8400-e29b-41d4-a716-446655440000".to_string())),
6870
}
69-
);
70-
}
7171

72-
// parse_clear ensures the clear subcommand routes to the Clear variant and
73-
// parses its interface_id.
74-
#[test]
75-
fn parse_clear() {
76-
scenarios!(
77-
run = |argv| {
78-
Cmd::try_parse_from(argv.iter().copied())
79-
.map(|cmd| match cmd {
80-
Cmd::Clear(args) => args.inner.interface_id.to_string(),
81-
_ => panic!("expected Clear variant"),
82-
})
83-
.map_err(drop)
84-
};
85-
"clear parses interface_id" {
72+
"clear routes to Clear and parses interface_id" {
8673
&[
8774
"boot-override",
8875
"clear",
8976
"550e8400-e29b-41d4-a716-446655440000",
90-
][..] => Yields("550e8400-e29b-41d4-a716-446655440000".to_string()),
77+
][..] => Yields(("clear", "550e8400-e29b-41d4-a716-446655440000".to_string())),
9178
}
9279
);
9380
}

crates/admin-cli/src/cfg/dispatch.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ mod tests {
5959
}
6060
}
6161

62-
// Verify the derive generates a valid Dispatch impl when
63-
// all variants are "leaf" commands (i.e. the Run trait).
62+
// Deriving `Dispatch` on these enums is itself the test: the derive only
63+
// compiles if it generates a valid `Dispatch` impl. `AllRunCmd` covers the
64+
// all-leaf case (every variant is a `Run` command); `MixedCmd` covers mixing
65+
// a leaf command with a nested `#[dispatch]` group. If either impl failed to
66+
// generate, this module would not compile.
6467
#[derive(Dispatch)]
6568
#[allow(dead_code)]
6669
enum AllRunCmd {
@@ -69,26 +72,11 @@ mod tests {
6972
CmdC(StubRunArgs),
7073
}
7174

72-
// Verify the derive generates a valid Dispatch impl when
73-
// mixing "leaf" commands (the `Run` trait) with nested command
74-
// groups (which we annotate inline with `#[dispatch]`).
7575
#[derive(Dispatch)]
7676
#[allow(dead_code)]
7777
enum MixedCmd {
7878
SimpleRunCommand(StubRunArgs),
7979
#[dispatch]
8080
NestedCommandGroup(StubNestedCmd),
8181
}
82-
83-
fn assert_dispatch<T: Dispatch>() {}
84-
85-
#[test]
86-
fn all_run_variants_derive_dispatch() {
87-
assert_dispatch::<AllRunCmd>();
88-
}
89-
90-
#[test]
91-
fn mixed_run_and_dispatch_variants_derive_dispatch() {
92-
assert_dispatch::<MixedCmd>();
93-
}
9482
}

crates/admin-cli/src/dpu/tests.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ fn verify_cmd_structure() {
5050
// including testing required arguments, as well as optional
5151
// flag-specific checking.
5252

53-
// parse_status ensures status routes to the Status variant
54-
// with no arguments.
55-
#[test]
56-
fn parse_status() {
57-
let cmd = Cmd::try_parse_from(["dpu", "status"]).expect("should parse status");
58-
assert!(matches!(cmd, Cmd::Status(_)));
59-
}
60-
6153
// versions parses with and without --updates-only; the parsed flag mirrors
6254
// whether the switch was supplied.
6355
#[test]

crates/admin-cli/src/expected_machines/tests.rs

Lines changed: 91 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -499,87 +499,106 @@ fn parse_add_without_dpu_mode() {
499499
}
500500
}
501501

502-
// parse_add_with_dpu_mode_nic ensures `--dpu-mode nic-mode`
503-
// parses to the NicMode variant.
502+
// `--dpu-mode <value>` parses to the matching DpuMode variant on both `add`
503+
// (alongside the required credential/chassis args) and `patch` (where flipping
504+
// dpu_mode on a single host is the whole point). The closure pulls dpu_mode off
505+
// whichever variant parsed; each row pins the parsed `Some(variant)`.
504506
#[test]
505-
fn parse_add_with_dpu_mode_nic() {
506-
let cmd = Cmd::try_parse_from([
507-
"expected-machine",
508-
"add",
509-
"--bmc-mac-address",
510-
"1a:2b:3c:4d:5e:6f",
511-
"--bmc-username",
512-
"admin",
513-
"--bmc-password",
514-
"secret",
515-
"--chassis-serial-number",
516-
"SN12345",
517-
"--dpu-mode",
518-
"nic-mode",
519-
])
520-
.expect("should parse nic-mode");
507+
fn parse_dpu_mode_to_its_variant() {
508+
scenarios!(
509+
run = |argv| {
510+
Cmd::try_parse_from(argv.iter().copied())
511+
.map(|cmd| match cmd {
512+
Cmd::Add(args) => args.dpu_mode,
513+
Cmd::Patch(args) => args.dpu_mode,
514+
_ => panic!("expected Add or Patch variant"),
515+
})
516+
.map_err(drop)
517+
};
518+
"add --dpu-mode nic-mode" {
519+
&[
520+
"expected-machine",
521+
"add",
522+
"--bmc-mac-address",
523+
"1a:2b:3c:4d:5e:6f",
524+
"--bmc-username",
525+
"admin",
526+
"--bmc-password",
527+
"secret",
528+
"--chassis-serial-number",
529+
"SN12345",
530+
"--dpu-mode",
531+
"nic-mode",
532+
][..] => Yields(Some(rpc::forge::DpuMode::NicMode)),
533+
}
521534

522-
match cmd {
523-
Cmd::Add(args) => {
524-
assert!(matches!(args.dpu_mode, Some(rpc::forge::DpuMode::NicMode)));
535+
"add --dpu-mode no-dpu" {
536+
&[
537+
"expected-machine",
538+
"add",
539+
"--bmc-mac-address",
540+
"1a:2b:3c:4d:5e:6f",
541+
"--bmc-username",
542+
"admin",
543+
"--bmc-password",
544+
"secret",
545+
"--chassis-serial-number",
546+
"SN12345",
547+
"--dpu-mode",
548+
"no-dpu",
549+
][..] => Yields(Some(rpc::forge::DpuMode::NoDpu)),
525550
}
526-
_ => panic!("expected Add variant"),
527-
}
528-
}
529551

530-
// parse_add_with_dpu_mode_no_dpu ensures `--dpu-mode no-dpu` parses
531-
// correctly (host with zero DPU hardware at all).
532-
#[test]
533-
fn parse_add_with_dpu_mode_no_dpu() {
534-
let cmd = Cmd::try_parse_from([
535-
"expected-machine",
536-
"add",
537-
"--bmc-mac-address",
538-
"1a:2b:3c:4d:5e:6f",
539-
"--bmc-username",
540-
"admin",
541-
"--bmc-password",
542-
"secret",
543-
"--chassis-serial-number",
544-
"SN12345",
545-
"--dpu-mode",
546-
"no-dpu",
547-
])
548-
.expect("should parse no-dpu");
552+
"add --dpu-mode dpu-mode" {
553+
&[
554+
"expected-machine",
555+
"add",
556+
"--bmc-mac-address",
557+
"1a:2b:3c:4d:5e:6f",
558+
"--bmc-username",
559+
"admin",
560+
"--bmc-password",
561+
"secret",
562+
"--chassis-serial-number",
563+
"SN12345",
564+
"--dpu-mode",
565+
"dpu-mode",
566+
][..] => Yields(Some(rpc::forge::DpuMode::DpuMode)),
567+
}
549568

550-
match cmd {
551-
Cmd::Add(args) => {
552-
assert!(matches!(args.dpu_mode, Some(rpc::forge::DpuMode::NoDpu)));
569+
"patch --dpu-mode nic-mode" {
570+
&[
571+
"expected-machine",
572+
"patch",
573+
"--bmc-mac-address",
574+
"1a:2b:3c:4d:5e:6f",
575+
"--dpu-mode",
576+
"nic-mode",
577+
][..] => Yields(Some(rpc::forge::DpuMode::NicMode)),
553578
}
554-
_ => panic!("expected Add variant"),
555-
}
556-
}
557579

558-
// parse_add_with_dpu_mode_dpu ensures `--dpu-mode dpu-mode` parses.
559-
#[test]
560-
fn parse_add_with_dpu_mode_dpu() {
561-
let cmd = Cmd::try_parse_from([
562-
"expected-machine",
563-
"add",
564-
"--bmc-mac-address",
565-
"1a:2b:3c:4d:5e:6f",
566-
"--bmc-username",
567-
"admin",
568-
"--bmc-password",
569-
"secret",
570-
"--chassis-serial-number",
571-
"SN12345",
572-
"--dpu-mode",
573-
"dpu-mode",
574-
])
575-
.expect("should parse dpu-mode");
580+
"patch --dpu-mode no-dpu" {
581+
&[
582+
"expected-machine",
583+
"patch",
584+
"--bmc-mac-address",
585+
"1a:2b:3c:4d:5e:6f",
586+
"--dpu-mode",
587+
"no-dpu",
588+
][..] => Yields(Some(rpc::forge::DpuMode::NoDpu)),
589+
}
576590

577-
match cmd {
578-
Cmd::Add(args) => {
579-
assert!(matches!(args.dpu_mode, Some(rpc::forge::DpuMode::DpuMode)));
591+
"patch --dpu-mode dpu-mode" {
592+
&[
593+
"expected-machine",
594+
"patch",
595+
"--bmc-mac-address",
596+
"1a:2b:3c:4d:5e:6f",
597+
"--dpu-mode",
598+
"dpu-mode",
599+
][..] => Yields(Some(rpc::forge::DpuMode::DpuMode)),
580600
}
581-
_ => panic!("expected Add variant"),
582-
}
601+
);
583602
}
584603

585604
// parse_add_rejects_invalid_dpu_mode ensures clap rejects values that
@@ -606,74 +625,6 @@ fn parse_add_rejects_invalid_dpu_mode() {
606625
);
607626
}
608627

609-
// parse_patch_with_dpu_mode_nic ensures `patch ... --dpu-mode nic-mode`
610-
// parses to NicMode. Patch users flip dpu_mode on a single host without
611-
// rewriting the entire ExpectedMachine.
612-
#[test]
613-
fn parse_patch_with_dpu_mode_nic() {
614-
let cmd = Cmd::try_parse_from([
615-
"expected-machine",
616-
"patch",
617-
"--bmc-mac-address",
618-
"1a:2b:3c:4d:5e:6f",
619-
"--dpu-mode",
620-
"nic-mode",
621-
])
622-
.expect("should parse patch --dpu-mode nic-mode");
623-
624-
match cmd {
625-
Cmd::Patch(args) => {
626-
assert!(matches!(args.dpu_mode, Some(rpc::forge::DpuMode::NicMode)));
627-
}
628-
_ => panic!("expected Patch variant"),
629-
}
630-
}
631-
632-
// parse_patch_with_dpu_mode_no_dpu ensures `patch ... --dpu-mode no-dpu`
633-
// parses (host with no DPU hardware at all).
634-
#[test]
635-
fn parse_patch_with_dpu_mode_no_dpu() {
636-
let cmd = Cmd::try_parse_from([
637-
"expected-machine",
638-
"patch",
639-
"--bmc-mac-address",
640-
"1a:2b:3c:4d:5e:6f",
641-
"--dpu-mode",
642-
"no-dpu",
643-
])
644-
.expect("should parse patch --dpu-mode no-dpu");
645-
646-
match cmd {
647-
Cmd::Patch(args) => {
648-
assert!(matches!(args.dpu_mode, Some(rpc::forge::DpuMode::NoDpu)));
649-
}
650-
_ => panic!("expected Patch variant"),
651-
}
652-
}
653-
654-
// parse_patch_with_dpu_mode_dpu ensures `patch ... --dpu-mode dpu-mode`
655-
// parses; this is how operators revert a host back to the default after
656-
// previously setting NicMode/NoDpu.
657-
#[test]
658-
fn parse_patch_with_dpu_mode_dpu() {
659-
let cmd = Cmd::try_parse_from([
660-
"expected-machine",
661-
"patch",
662-
"--bmc-mac-address",
663-
"1a:2b:3c:4d:5e:6f",
664-
"--dpu-mode",
665-
"dpu-mode",
666-
])
667-
.expect("should parse patch --dpu-mode dpu-mode");
668-
669-
match cmd {
670-
Cmd::Patch(args) => {
671-
assert!(matches!(args.dpu_mode, Some(rpc::forge::DpuMode::DpuMode)));
672-
}
673-
_ => panic!("expected Patch variant"),
674-
}
675-
}
676-
677628
// validate_patch_with_dpu_mode_only ensures `patch --dpu-mode nic-mode`
678629
// alone (no other patchable fields) satisfies clap's ArgGroup and the
679630
// `Args::validate()` "at least one field" check. The whole point of this

crates/admin-cli/src/firmware/tests.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// Command Structure - Baseline debug_assert() of the entire command.
2424
// Argument Parsing - Ensure required/optional arg combinations parse correctly.
2525

26-
use clap::{CommandFactory, Parser};
26+
use clap::CommandFactory;
2727

2828
use super::*;
2929

@@ -36,18 +36,3 @@ use super::*;
3636
fn verify_cmd_structure() {
3737
Cmd::command().debug_assert();
3838
}
39-
40-
/////////////////////////////////////////////////////////////////////////////
41-
// Argument Parsing
42-
//
43-
// This section contains tests specific to argument parsing,
44-
// including testing required arguments, as well as optional
45-
// flag-specific checking.
46-
47-
// parse_show ensures show parses with no arguments.
48-
#[test]
49-
fn parse_show() {
50-
let cmd = Cmd::try_parse_from(["firmware", "show"]).expect("should parse show");
51-
52-
assert!(matches!(cmd, Cmd::Show(_)));
53-
}

0 commit comments

Comments
 (0)