Skip to content

Commit

Permalink
Add #[derive(PartialEq, Eq)) for cli bits
Browse files Browse the repository at this point in the history
So we can unit test with `assert_eq!()`.

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed Mar 22, 2024
1 parent 532815a commit 231aad9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
27 changes: 19 additions & 8 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::spec::ImageReference;
use crate::utils::sigpolicy_from_opts;

/// Perform an upgrade operation
#[derive(Debug, Parser)]
#[derive(Debug, Parser, PartialEq, Eq)]
pub(crate) struct UpgradeOpts {
/// Don't display progress
#[clap(long)]
Expand All @@ -46,7 +46,7 @@ pub(crate) struct UpgradeOpts {
}

/// Perform an switch operation
#[derive(Debug, Parser)]
#[derive(Debug, Parser, PartialEq, Eq)]
pub(crate) struct SwitchOpts {
/// Don't display progress
#[clap(long)]
Expand Down Expand Up @@ -87,7 +87,7 @@ pub(crate) struct SwitchOpts {
}

/// Perform an edit operation
#[derive(Debug, Parser)]
#[derive(Debug, Parser, PartialEq, Eq)]
pub(crate) struct EditOpts {
/// Use filename to edit system specification
#[clap(long, short = 'f')]
Expand All @@ -99,7 +99,7 @@ pub(crate) struct EditOpts {
}

/// Perform an status operation
#[derive(Debug, Parser)]
#[derive(Debug, Parser, PartialEq, Eq)]
pub(crate) struct StatusOpts {
/// Output in JSON format.
#[clap(long)]
Expand All @@ -112,7 +112,7 @@ pub(crate) struct StatusOpts {

/// Options for internal testing
#[cfg(feature = "install")]
#[derive(Debug, clap::Subcommand)]
#[derive(Debug, clap::Subcommand, PartialEq, Eq)]
pub(crate) enum InstallOpts {
/// Install to the target block device
ToDisk(crate::install::InstallToDiskOpts),
Expand All @@ -129,15 +129,15 @@ pub(crate) enum InstallOpts {
}

/// Options for man page generation
#[derive(Debug, Parser)]
#[derive(Debug, Parser, PartialEq, Eq)]
pub(crate) struct ManOpts {
#[clap(long)]
/// Output to this directory
pub(crate) directory: Utf8PathBuf,
}

/// Options for internal testing
#[derive(Debug, clap::Subcommand)]
#[derive(Debug, clap::Subcommand, PartialEq, Eq)]
pub(crate) enum TestingOpts {
/// Execute integration tests that require a privileged container
RunPrivilegedIntegration {},
Expand Down Expand Up @@ -168,7 +168,7 @@ pub(crate) enum TestingOpts {
///
/// Changes in `/etc` and `/var` persist.
///
#[derive(Debug, Parser)]
#[derive(Debug, Parser, PartialEq, Eq)]
#[clap(name = "bootc")]
#[clap(rename_all = "kebab-case")]
#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -576,3 +576,14 @@ fn test_parse_install_args() {
assert!(o.target_opts.target_no_signature_verification);
assert_eq!(o.filesystem_opts.root_path.as_str(), "/target");
}

#[test]
fn test_parse_opts() {
assert!(matches!(
Opt::parse_from(["bootc", "status"]),
Opt::Status(StatusOpts {
json: false,
booted: false
})
));
}
14 changes: 7 additions & 7 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub(crate) const ARCH_USES_EFI: bool = cfg!(any(target_arch = "x86_64", target_a
/// Kernel argument used to specify we want the rootfs mounted read-write by default
const RW_KARG: &str = "rw";

#[derive(clap::Args, Debug, Clone, Serialize, Deserialize)]
#[derive(clap::Args, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct InstallTargetOpts {
// TODO: A size specifier which allocates free space for the root in *addition* to the base container image size
// pub(crate) root_additional_size: Option<String>
Expand Down Expand Up @@ -110,7 +110,7 @@ pub(crate) struct InstallTargetOpts {
pub(crate) skip_fetch_check: bool,
}

#[derive(clap::Args, Debug, Clone, Serialize, Deserialize)]
#[derive(clap::Args, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct InstallSourceOpts {
/// Install the system from an explicitly given source.
///
Expand All @@ -122,7 +122,7 @@ pub(crate) struct InstallSourceOpts {
pub(crate) source_imgref: Option<String>,
}

#[derive(clap::Args, Debug, Clone, Serialize, Deserialize)]
#[derive(clap::Args, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct InstallConfigOpts {
/// Disable SELinux in the target (installed) system.
///
Expand Down Expand Up @@ -159,7 +159,7 @@ pub(crate) struct InstallConfigOpts {
}

/// Perform an installation to a block device.
#[derive(Debug, Clone, clap::Parser, Serialize, Deserialize)]
#[derive(Debug, Clone, clap::Parser, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct InstallToDiskOpts {
#[clap(flatten)]
#[serde(flatten)]
Expand Down Expand Up @@ -206,7 +206,7 @@ impl std::fmt::Display for ReplaceMode {
}

/// Options for installing to a filesystem
#[derive(Debug, Clone, clap::Args)]
#[derive(Debug, Clone, clap::Args, PartialEq, Eq)]
pub(crate) struct InstallTargetFilesystemOpts {
/// Path to the mounted root filesystem.
///
Expand All @@ -232,7 +232,7 @@ pub(crate) struct InstallTargetFilesystemOpts {
}

/// Perform an installation to a mounted filesystem.
#[derive(Debug, Clone, clap::Parser)]
#[derive(Debug, Clone, clap::Parser, PartialEq, Eq)]
pub(crate) struct InstallToFilesystemOpts {
#[clap(flatten)]
pub(crate) filesystem_opts: InstallTargetFilesystemOpts,
Expand All @@ -248,7 +248,7 @@ pub(crate) struct InstallToFilesystemOpts {
}

/// Perform an installation to the host root filesystem.
#[derive(Debug, Clone, clap::Parser)]
#[derive(Debug, Clone, clap::Parser, PartialEq, Eq)]
pub(crate) struct InstallToExistingRootOpts {
/// Configure how existing data is treated.
#[clap(long, default_value = "alongside")]
Expand Down
2 changes: 1 addition & 1 deletion lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Default for BlockSetup {
}

/// Options for installing to a block device
#[derive(Debug, Clone, clap::Args, Serialize, Deserialize)]
#[derive(Debug, Clone, clap::Args, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub(crate) struct InstallBlockDeviceOpts {
/// Target block device for installation. The entire device will be wiped.
Expand Down

0 comments on commit 231aad9

Please sign in to comment.