Skip to content
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

fix: Prevent nix-health info from printing to stdout; add integration test #81

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 87 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ clap = { version = "4.4", features = ["derive"] }
urlencoding = "2.1.3"
nix_rs = { version = "0.5.0", features = ["clap"] }
# nix_rs = { version = "0.5.0", path = "../nix-rs", features = ["clap"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing = "0.1.37"
nix_health = { version = "0.4.0" }
nix_health = { git = "https://github.com/juspay/nix-health" }

[dev-dependencies]
regex = "1.9"
ctor = "0.2"
assert_cmd = "2.0.14"

[features]
integration_test = []
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub async fn check_nix_version(nixcmd: &NixCmd, flake_url: &FlakeUrl) -> anyhow:
.with_context(|| "Unable to gather nix info")?;
let nix_health = NixHealth::from_flake(flake_url).await?;
let checks = nix_health.nix_version.check(&nix_info, Some(flake_url));
let exit_code = NixHealth::print_report_returning_exit_code(&checks, false);
let exit_code = NixHealth::print_report_returning_exit_code(&checks);

if exit_code != 0 {
std::process::exit(exit_code);
Expand Down
4 changes: 2 additions & 2 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ where

pub fn setup_logging(verbose: bool) {
let env_filter = if verbose {
"nixci=debug,nix_rs=debug"
"nixci=debug,nix_rs=debug,nix_health=info"
} else {
"nixci=info,nix_rs=info"
"nixci=info,nix_rs=info,nix_health=info"
};
let builder = tracing_subscriber::fmt()
.with_writer(io::stderr)
Expand Down
28 changes: 27 additions & 1 deletion tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
//! sandbox), and must be manually enabled using the feature flag.
#[cfg(feature = "integration_test")]
mod integration_test {
use std::path::{Path, PathBuf};
use std::{
path::{Path, PathBuf},
process::Command,
};

use assert_cmd::cargo::CommandCargoExt;
use clap::Parser;
use nixci::{self, cli, nix::nix_store::StorePath};
use regex::Regex;
Expand All @@ -15,6 +19,28 @@ mod integration_test {
nixci::logging::setup_logging(true);
}

#[tokio::test]
/// Run `nixci build` and check if the stdout consists of only /nix/store/* paths
async fn nixci_build_output() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin("nixci")?;
cmd.arg("build")
.arg("github:srid/haskell-multi-nix/c85563721c388629fa9e538a1d97274861bc8321");

let output = cmd.output()?;
let stdout = String::from_utf8_lossy(&output.stdout);
let lines = stdout.lines();

for line in lines {
assert!(
line.starts_with("/nix/store/"),
"Unexpected line in stdout: {}",
line
);
}

Ok(())
}

#[tokio::test]
/// A simple test, without config
async fn test_haskell_multi_nix() -> anyhow::Result<()> {
Expand Down