fn caching_download_downloads_file() -> Result<(), CliError> {
        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);

        assert!(!file_path.exists());

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

        let url = Url::parse("http://localhost/fake").expect("could not create url");

        let config = CachingDownloadConfig {
            url: url.clone(),
            file_path: file_path.to_path_buf(),
            temp_file_path: temp_file_path.to_path_buf(),
            #[cfg(feature = "xsd-downloader-force-download")]
            force_download: false,
            hash: TEST_HASH,
        };

        // Run the test
        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(),
            &[MockValidatorCall {
                path_buf: temp_file_path.to_path_buf(),
                hash: TEST_HASH.to_string(),
            }]
        );
        assert_eq!(
            downloader.get_calls(),
            &[MockDownloaderCall {
                url,
                file_name: dest_dir.join(temp_file_name).to_string_lossy().to_string()
            }]
        );
        assert!(file_path.exists());
        assert!(!temp_file_path.exists());
        Ok(())
    }
// Test that CachingDownloader downloads if file is not cached
Test that CachingDownloader downloads if file is not cached
Test that CachingDownloader downloads if file is not cached
fn caching_download_downloads_file() -> Result<(), CliError> {
        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);
        assert!(!file_path.exists());
        let mut downloader = MockDownloader::new(vec![Ok(())]);
        let mut validator = MockValidator::new(vec![Ok(())]);
        let url = Url::parse("http://localhost/fake").expect("could not create url");
        let config = CachingDownloadConfig {
            url: url.clone(),
            file_path: file_path.to_path_buf(),
            temp_file_path: temp_file_path.to_path_buf(),
            #[cfg(feature = "xsd-downloader-force-download")]
            force_download: false,
            hash: TEST_HASH,
        };
        // Run the test
        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(),
            &[MockValidatorCall {
                path_buf: temp_file_path.to_path_buf(),
                hash: TEST_HASH.to_string(),
            }]
        );
        assert_eq!(
            downloader.get_calls(),
            &[MockDownloaderCall {
                url,
                file_name: dest_dir.join(temp_file_name).to_string_lossy().to_string()
            }]
        );
        assert!(file_path.exists());
        assert!(!temp_file_path.exists());
        Ok(())
    }
fn caching_download_downloads_file ( ) -> Result < ( ) , CliError > { 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 ) ; assert ! ( file_path exists ( ) ) ; let mut downloader = MockDownloader :: new ( vec ! [ Ok ( ( ) ) ] ) ; let mut validator = MockValidator :: new ( vec ! [ Ok ( ( ) ) ] ) ; let url = Url :: parse ( " " ) . expect ( " " ) ; let config = CachingDownloadConfig { url : url . clone ( ) , file_path : file_path . to_path_buf ( ) , temp_file_path : temp_file_path . to_path_buf ( ) , # [ cfg ( feature " " ) ] force_download : false , hash : TEST_HASH , } ; // Run the test 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 ( ) [ MockValidatorCall { path_buf temp_file_path to_path_buf ( ) hash TEST_HASH to_string ( ) } ] ) ; assert_eq ! ( downloader get_calls ( ) [ MockDownloaderCall { url file_name dest_dir join ( temp_file_name ) to_string_lossy ( ) to_string ( ) } ] ) ; assert ! ( file_path exists ( ) ) ; assert ! ( temp_file_path exists ( ) ) ; Ok ( ( ) ) }
Test that CachingDownloader downloads if file is not cached
Test that CachingDownloader downloads if file is not cached