fn caching_download_fails_if_temp_file_exists() {
        let temp_dir = TempDir::new("example").expect("could not create tempdir");
        let dest_dir = temp_dir.path();

        let file_name = "gs1.zip";
        let temp_file_name = "gs1-temp.zip";

        let file_path = dest_dir.join(file_name);
        let temp_file_path = dest_dir.join(temp_file_name);

        // Create the temporary file
        File::create(temp_file_path.clone()).expect("could not create temp file");
        assert!(temp_file_path.exists());

        let mut downloader = MockDownloader::new(vec![]);
        let mut validator = MockValidator::new(vec![]);

        let config = CachingDownloadConfig {
            url: Url::parse("http://localhost/fake").expect("could not create url"),
            file_path: file_path.to_path_buf(),
            temp_file_path: temp_file_path.to_path_buf(),
            force_download: true,
            hash: TEST_HASH,
        };

        // Run the test
        let result = caching_download(
            config,
            |url: &Url, file_name: &str| downloader.download(url, file_name),
            |path_buf: &PathBuf, hash: &str| validator.validate(path_buf, hash),
        );

        assert_eq!(validator.get_calls(), &[]);
        assert!(result.is_err());
        assert_eq!(downloader.get_calls(), &[]);
    }
// Test that CachingDownloader fails if the temporary file already exists
Test that CachingDownloader fails if the temporary file already exists
Test that CachingDownloader fails if the temporary file already exists
fn caching_download_fails_if_temp_file_exists() {
        let temp_dir = TempDir::new("example").expect("could not create tempdir");
        let dest_dir = temp_dir.path();
        let file_name = "gs1.zip";
        let temp_file_name = "gs1-temp.zip";
        let file_path = dest_dir.join(file_name);
        let temp_file_path = dest_dir.join(temp_file_name);
        // Create the temporary file
        File::create(temp_file_path.clone()).expect("could not create temp file");
        assert!(temp_file_path.exists());
        let mut downloader = MockDownloader::new(vec![]);
        let mut validator = MockValidator::new(vec![]);
        let config = CachingDownloadConfig {
            url: Url::parse("http://localhost/fake").expect("could not create url"),
            file_path: file_path.to_path_buf(),
            temp_file_path: temp_file_path.to_path_buf(),
            force_download: true,
            hash: TEST_HASH,
        };
        // Run the test
        let result = caching_download(
            config,
            |url: &Url, file_name: &str| downloader.download(url, file_name),
            |path_buf: &PathBuf, hash: &str| validator.validate(path_buf, hash),
        );
        assert_eq!(validator.get_calls(), &[]);
        assert!(result.is_err());
        assert_eq!(downloader.get_calls(), &[]);
    }
fn caching_download_fails_if_temp_file_exists ( ) { let temp_dir = TempDir :: new ( " " ) . expect ( " " ) ; let dest_dir = temp_dir . path ( ) ; let file_name = " " ; let temp_file_name = " " ; let file_path = dest_dir . join ( file_name ) ; let temp_file_path = dest_dir . join ( temp_file_name ) ; // Create the temporary file File :: create ( temp_file_path . clone ( ) ) . expect ( " " ) ; assert ! ( temp_file_path exists ( ) ) ; let mut downloader = MockDownloader :: new ( vec ! [ ] ) ; let mut validator = MockValidator :: new ( vec ! [ ] ) ; let config = CachingDownloadConfig { url : Url :: parse ( " " ) . expect ( " " ) , file_path : file_path . to_path_buf ( ) , temp_file_path : temp_file_path . to_path_buf ( ) , force_download : true , hash : TEST_HASH , } ; // Run the test let result = caching_download ( config , | url : & Url , file_name : & str | downloader . download ( url , file_name ) , | path_buf : & PathBuf , hash : & str | validator . validate ( path_buf , hash ) , ) ; assert_eq ! ( validator get_calls ( ) [ ] ) ; assert ! ( result is_err ( ) ) ; assert_eq ! ( downloader get_calls ( ) [ ] ) ; }
Test that CachingDownloader fails if the temporary file already exists
Test that CachingDownloader fails if the temporary file already exists