-
Notifications
You must be signed in to change notification settings - Fork 155
cli: add install print-configuration --all
#1820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| use indoc::indoc; | ||
| use scopeguard::defer; | ||
| use serde::Deserialize; | ||
| use std::fs; | ||
| use std::process::Command; | ||
|
|
||
| use anyhow::{Context, Result}; | ||
|
|
@@ -36,8 +40,34 @@ pub(crate) fn test_bootc_install_config() -> Result<()> { | |
| let config = cmd!(sh, "bootc install print-configuration").read()?; | ||
| let config: serde_json::Value = | ||
| serde_json::from_str(&config).context("Parsing install config")?; | ||
| // Just verify we parsed the config, if any | ||
| drop(config); | ||
| // check that it parses okay, but also ensure kargs is not available here (only via --all) | ||
| assert!(config.get("kargs").is_none()); | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub(crate) fn test_bootc_install_config_all() -> Result<()> { | ||
| #[derive(Deserialize)] | ||
| struct TestInstallConfig { | ||
| kargs: Vec<String>, | ||
| } | ||
|
|
||
| let config_d = std::path::Path::new("/run/bootc/install/"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, though I guess probably what we really need here is a workflow that combines container build + test.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, it would be nice to have a combined build+test here. I can remove this part of the code again, its a bit unnecessary because the default container already has some kargs I can test for. I wanted to make this is a test-as-example thing so wanted to include the code that writes the toml but maybe I was overthinking it :) Either way is fine with me! |
||
| let test_toml_path = config_d.join("10-test.toml"); | ||
| std::fs::create_dir_all(&config_d)?; | ||
| let content = indoc! {r#" | ||
| [install] | ||
| kargs = ["karg1=1", "karg2=2"] | ||
| "#}; | ||
| std::fs::write(&test_toml_path, content)?; | ||
| defer! { | ||
| fs::remove_file(test_toml_path).expect("cannot remove tempfile"); | ||
| } | ||
|
|
||
| let sh = &xshell::Shell::new()?; | ||
| let config = cmd!(sh, "bootc install print-configuration --all").read()?; | ||
| let config: TestInstallConfig = | ||
| serde_json::from_str(&config).context("Parsing install config")?; | ||
| assert_eq! {config.kargs, vec!["karg1=1".to_string(), "karg2=2".to_string(), "localtestkarg=somevalue".to_string(), "otherlocalkarg=42".to_string()]}; | ||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -88,6 +118,7 @@ pub(crate) fn run(testargs: libtest_mimic::Arguments) -> Result<()> { | |
| new_test("variant-base-crosscheck", test_variant_base_crosscheck), | ||
| new_test("bootc upgrade", test_bootc_upgrade), | ||
| new_test("install config", test_bootc_install_config), | ||
| new_test("printconfig --all", test_bootc_install_config_all), | ||
| new_test("status", test_bootc_status), | ||
| new_test("system-reinstall --help", test_system_reinstall_help), | ||
| ]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the change itself is correct, it would be beneficial to add a unit test to verify the parsing of the new
--allflag for theinstall print-configurationsubcommand. This ensures future changes don't accidentally break this functionality.You could add a new test function in the
testsmodule of this file, similar totest_parse_install_args. For example:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are good, but we can't really do this in unit tests because it operates on ambient data.
We can do it in
tests-integration/src/container.rsthough I think.