quilt-rs 0.8.7

Rust library for accessing Quilt data packages.
Documentation
use crate::io::manifest::tag_latest;
use crate::io::remote::Remote;
use crate::lineage::PackageLineage;
use crate::uri::ManifestUri;
use crate::Res;

/// Tags the `manifest_uri` as "latest" remotely.
/// And update localy in .quilt/lineage.json `base_hash` and `latest_hash` to that hash as well.
pub async fn certify_latest(
    mut lineage: PackageLineage,
    remote: &impl Remote,
    manifest_uri: ManifestUri,
) -> Res<PackageLineage> {
    tag_latest(remote, &manifest_uri).await?;
    lineage.update_latest(manifest_uri.clone());
    Ok(lineage)
}

#[cfg(test)]
mod tests {
    use super::*;

    use crate::mocks;
    use crate::uri::S3Uri;

    #[tokio::test]
    async fn test_certifying_latest() -> Res {
        let remote = mocks::remote::MockRemote::default();
        remote
            .put_object(
                &S3Uri::try_from("s3://b/.quilt/named_packages/f/a/latest")?,
                b"OUTDATED_HASH".to_vec(),
            )
            .await?;
        let source_lineage = mocks::lineage::with_remote(ManifestUri {
            bucket: "b".to_string(),
            namespace: ("f", "a").into(),
            hash: "LATEST_HASH".to_string(),
        });
        let resolved_lineage = certify_latest(
            source_lineage.clone(),
            &remote,
            source_lineage.remote.clone(),
        )
        .await?;
        assert_eq!(
            resolved_lineage,
            PackageLineage {
                base_hash: "LATEST_HASH".to_string(),
                latest_hash: "LATEST_HASH".to_string(),
                ..source_lineage
            }
        );
        // FIXME: read_to_end
        // assert_eq!(
        //     remote
        //         .get_object(&S3Uri::try_from("s3://b/.quilt/named_packages/a/latest")?)
        //         .await?,
        //     b"LATEST_HASH",
        // );
        Ok(())
    }
}