Skip to content

Commit

Permalink
test: add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Jul 19, 2024
1 parent 31e16aa commit 8f6c0ee
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
66 changes: 66 additions & 0 deletions crates/rattler/src/install/clobber_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,4 +1173,70 @@ mod tests {

assert_check_files(&target_prefix.path().join("bin"), &["python"]);
}

// This used to hit an expect in the clobbering code
#[tokio::test]
async fn test_directory_clobber() {
// Create a transaction
let repodata_record_with_dir = get_repodata_record(
get_test_data_dir().join("clobber/clobber-with-dir-0.1.0-h4616a5c_0.conda"),
);
let repodata_record_without_dir = get_repodata_record(
get_test_data_dir().join("clobber/clobber-without-dir-0.1.0-h4616a5c_0.conda"),
);

let transaction = transaction::Transaction::<PrefixRecord, RepoDataRecord> {
operations: vec![TransactionOperation::Install(repodata_record_with_dir)],
python_info: None,
current_python_info: None,
platform: Platform::current(),
};

// execute transaction
let target_prefix = tempfile::tempdir().unwrap();

let packages_dir = tempfile::tempdir().unwrap();
let cache = PackageCache::new(packages_dir.path());

execute_transaction(
transaction,
target_prefix.path(),
&reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()),
&cache,
&InstallDriver::default(),

Check warning on line 1206 in crates/rattler/src/install/clobber_registry.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

Diff in /home/runner/work/rattler/rattler/crates/rattler/src/install/clobber_registry.rs

Check warning on line 1206 in crates/rattler/src/install/clobber_registry.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler/src/install/clobber_registry.rs
&InstallOptions::default(),
)
.await;

let prefix_records = PrefixRecord::collect_from_prefix(target_prefix.path()).unwrap();

// remove one of the clobbering files

Check warning on line 1213 in crates/rattler/src/install/clobber_registry.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

Diff in /home/runner/work/rattler/rattler/crates/rattler/src/install/clobber_registry.rs

Check warning on line 1213 in crates/rattler/src/install/clobber_registry.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler/src/install/clobber_registry.rs
let transaction = transaction::Transaction::<PrefixRecord, RepoDataRecord> {
operations: vec![
TransactionOperation::Remove(
prefix_records[0].clone(),
),
TransactionOperation::Install(repodata_record_without_dir),
],
python_info: None,
current_python_info: None,
platform: Platform::current(),
};

let install_driver = InstallDriver::builder()
.with_prefix_records(&prefix_records)
.finish();

execute_transaction(
transaction,
target_prefix.path(),
&reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()),
&cache,
&install_driver,

Check warning on line 1235 in crates/rattler/src/install/clobber_registry.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

Diff in /home/runner/work/rattler/rattler/crates/rattler/src/install/clobber_registry.rs

Check warning on line 1235 in crates/rattler/src/install/clobber_registry.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler/src/install/clobber_registry.rs
&InstallOptions::default(),
)
.await;

assert_check_files(&target_prefix.path(), &["dir"]);
}
}
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions test-data/clobber/recipe/recipe-with-dir.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
recipe:
name: clobber-with-dir
version: 0.1.0

outputs:
- package:
name: clobber-with-dir
version: 0.1.0

build:
noarch: generic
script:
- mkdir $PREFIX/dir
- echo "clobber-1" > $PREFIX/dir/clobber.txt

- package:
name: clobber-without-dir
version: 0.1.0

build:
noarch: generic
script:
- echo "clobber-1" > $PREFIX/dir

0 comments on commit 8f6c0ee

Please sign in to comment.