fn caching_download_doesnot_download_cached_file() {
        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(file_path.clone()).expect("could not create file");
        assert!(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(),
            #[cfg(feature = "xsd-downloader-force-download")]
            force_download: false,
            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_ok());
        assert_eq!(downloader.get_calls(), &[]);
    }
// Test that CachingDownloader does not download when file is cached
Test that CachingDownloader does not download when file is cached
Test that CachingDownloader does not download when file is cached
fn caching_download_doesnot_download_cached_file() {
        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(file_path.clone()).expect("could not create file");
        assert!(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(),
            #[cfg(feature = "xsd-downloader-force-download")]
            force_download: false,
            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_ok());
        assert_eq!(downloader.get_calls(), &[]);
    }
fn caching_download_doesnot_download_cached_file ( ) { 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 ( file_path . clone ( ) ) . expect ( " " ) ; assert ! ( 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 ( ) , # [ cfg ( feature " " ) ] force_download : false , 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_ok ( ) ) ; assert_eq ! ( downloader get_calls ( ) [ ] ) ; }
Test that CachingDownloader does not download when file is cached
Test that CachingDownloader does not download when file is cached