Skip to content

Commit cdd5ccb

Browse files
committed
test: let integration tests handle it
1 parent 7b0e993 commit cdd5ccb

File tree

2 files changed

+7
-121
lines changed

2 files changed

+7
-121
lines changed

crates/prek/src/languages/dotnet/dotnet.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::cli::reporter::{HookInstallReporter, HookRunReporter};
1111
use crate::hook::{Hook, InstallInfo, InstalledHook};
1212
use crate::languages::LanguageImpl;
1313
use crate::languages::dotnet::installer::{installer_from_store, query_dotnet_version};
14-
use crate::languages::version::LanguageRequest;
1514
use crate::process::Cmd;
1615
use crate::run::run_by_batch;
1716
use crate::store::Store;

crates/prek/src/languages/dotnet/installer.rs

Lines changed: 7 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -484,123 +484,18 @@ mod tests {
484484
assert!(display_str.contains("8.0.100"));
485485
}
486486

487-
#[tokio::test]
488-
async fn test_dotnet_installer_new() {
489-
let root = std::path::PathBuf::from("/test/root");
490-
let installer = DotnetInstaller::new(root.clone());
491-
assert_eq!(installer.root, root);
492-
}
493-
494-
#[tokio::test]
495-
async fn test_dotnet_installer_system_only_no_download_allowed() -> anyhow::Result<()> {
496-
let temp_dir = tempfile::tempdir()?;
497-
let installer = DotnetInstaller::new(temp_dir.path().join("dotnet"));
498-
499-
// Test system_only: true - this might find system dotnet or not
500-
let request = LanguageRequest::Any { system_only: true };
501-
let result = installer.install(&request, false).await;
502-
503-
// If system dotnet is available, it should succeed
504-
// If not, it should fail with the expected error message
505-
if let Err(err) = result {
506-
assert!(
507-
err.to_string()
508-
.contains("No system dotnet installation found")
509-
);
510-
}
511-
// If it succeeds, that's also fine - system dotnet was found
512-
513-
Ok(())
514-
}
515-
516-
#[tokio::test]
517-
async fn test_dotnet_installer_no_download_allowed() -> anyhow::Result<()> {
518-
let temp_dir = tempfile::tempdir()?;
519-
let installer = DotnetInstaller::new(temp_dir.path().join("dotnet"));
520-
521-
// Test with allows_download = false
522-
let request = LanguageRequest::Dotnet(DotnetRequest::Major(999)); // Non-existent version
523-
let result = installer.install(&request, false).await;
524-
525-
// Should fail because downloads are disabled
526-
assert!(result.is_err());
527-
assert!(
528-
result
529-
.unwrap_err()
530-
.to_string()
531-
.contains("No suitable dotnet version found and downloads are disabled")
532-
);
533-
534-
Ok(())
535-
}
536-
537-
#[tokio::test]
538-
async fn test_dotnet_installer_find_existing() -> anyhow::Result<()> {
539-
let temp_dir = tempfile::tempdir()?;
540-
let installer = DotnetInstaller::new(temp_dir.path().join("dotnet"));
541-
542-
// Create a fake installed dotnet
543-
let version_dir = installer.root.join("8.0.100");
544-
fs_err::tokio::create_dir_all(&version_dir).await?;
545-
546-
let fake_dotnet = dotnet_executable(&version_dir);
547-
fs_err::tokio::write(&fake_dotnet, "#!/bin/sh\necho '8.0.100'\n").await?;
548-
549-
#[cfg(unix)]
550-
{
551-
use std::os::unix::fs::PermissionsExt;
552-
let perms = std::fs::Permissions::from_mode(0o755);
553-
std::fs::set_permissions(&fake_dotnet, perms)?;
554-
}
555-
556-
// Mock the query to return our fake version
557-
// Since we can't easily mock the actual query_dotnet_version function,
558-
// we'll test the find_installed method indirectly by testing scenarios
559-
// where it would be called
560-
561-
Ok(())
562-
}
563-
564-
#[tokio::test]
565-
async fn test_dotnet_installer_remove_existing_dir() -> anyhow::Result<()> {
566-
let temp_dir = tempfile::tempdir()?;
567-
let installer = DotnetInstaller::new(temp_dir.path().join("dotnet"));
568-
569-
// Create the installer root
570-
fs_err::tokio::create_dir_all(&installer.root).await?;
571-
572-
// Create a directory that would be the target install dir
573-
let install_dir = installer.root.join("8.0");
574-
fs_err::tokio::create_dir_all(&install_dir).await?;
575-
fs_err::tokio::write(install_dir.join("dummy.txt"), "test").await?;
576-
577-
// Verify the directory exists
578-
assert!(install_dir.exists());
579-
580-
// The installer should clean up existing partial installations
581-
// We can't easily test the full download scenario, but we can verify
582-
// the cleanup logic works by checking that our test directory structure
583-
// is properly set up for testing
584-
585-
Ok(())
586-
}
587-
588487
#[test]
589488
fn test_display_format_error() {
590489
let path = std::path::PathBuf::from("/usr/bin/dotnet");
591490
let version = Version::new(8, 0, 100);
592491
let result = DotnetResult::new(path, version);
593492

594-
// Test the Display implementation more thoroughly
493+
// Test the Display implementation
595494
let display_str = format!("{result}");
596495
assert!(display_str.contains("/usr/bin/dotnet@8.0.100"));
597496

598-
// Test that the write! operation in fmt could potentially fail
599-
// by using a custom formatter that simulates failure
600497
use std::fmt::{self, Write};
601-
602498
struct FailingFormatter;
603-
604499
impl Write for FailingFormatter {
605500
fn write_str(&mut self, _s: &str) -> fmt::Result {
606501
Err(fmt::Error)
@@ -616,39 +511,31 @@ mod tests {
616511
#[test]
617512
fn test_add_channel_args_unix_coverage() {
618513
let mut cmd = Cmd::new("test", "test");
619-
620-
// Test with full version
621514
add_channel_args_unix(&mut cmd, Some("8.0.100"));
622-
// This would add --version 8.0.100
515+
assert!(format!("{cmd}").contains("--version 8.0.100"));
623516

624517
let mut cmd = Cmd::new("test", "test");
625-
// Test with channel
626518
add_channel_args_unix(&mut cmd, Some("8.0"));
627-
// This would add --channel 8.0
519+
assert!(format!("{cmd}").contains("--channel 8.0"));
628520

629521
let mut cmd = Cmd::new("test", "test");
630-
// Test with None
631522
add_channel_args_unix(&mut cmd, None);
632-
// This would add --channel LTS
523+
assert!(format!("{cmd}").contains("--channel LTS"));
633524
}
634525

635526
#[cfg(windows)]
636527
#[test]
637528
fn test_add_channel_args_windows_coverage() {
638529
let mut cmd = Cmd::new("test", "test");
639-
640-
// Test with full version
641530
add_channel_args_windows(&mut cmd, Some("8.0.100"));
642-
// This would add -Version 8.0.100
531+
assert!(format!("{cmd}").contains("-Version 8.0.100"));
643532

644533
let mut cmd = Cmd::new("test", "test");
645-
// Test with channel
646534
add_channel_args_windows(&mut cmd, Some("8.0"));
647-
// This would add -Channel 8.0
535+
assert!(format!("{cmd}").contains("-Channel 8.0"));
648536

649537
let mut cmd = Cmd::new("test", "test");
650-
// Test with None
651538
add_channel_args_windows(&mut cmd, None);
652-
// This would add -Channel LTS
539+
assert!(format!("{cmd}").contains("-Channel LTS"));
653540
}
654541
}

0 commit comments

Comments
 (0)