Skip to content

Commit

Permalink
Add object_store::purge_existing_object_on_put test
Browse files Browse the repository at this point in the history
  • Loading branch information
thinety committed Jan 29, 2025
1 parent 55dd5e4 commit a32cdb5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions async-nats/tests/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,45 @@ mod object_store {
);
}

#[tokio::test]
async fn purge_existing_object_on_put() {
let server = nats_server::run_server("tests/configs/jetstream.conf");
let client = async_nats::connect(server.client_url()).await.unwrap();

let jetstream = async_nats::jetstream::new(client);

let bucket_name = "bucket".to_owned();
let stream_name = format!("OBJ_{}", &bucket_name);

let bucket = jetstream
.create_object_store(async_nats::jetstream::object_store::Config {
bucket: bucket_name,
..Default::default()
})
.await
.unwrap();

let mut stream = jetstream.get_stream(stream_name).await.unwrap();

// initially we have no messages in the stream
assert_eq!(stream.info().await.unwrap().state.messages, 0);

bucket.put("file", &mut b"foo".as_slice()).await.unwrap();

// after one put operation, we should have:
// - one CHUNK message containing file data
// - one META message
assert_eq!(stream.info().await.unwrap().state.messages, 2);

bucket.put("file", &mut b"bar".as_slice()).await.unwrap();

// after the second put operation, we should have:
// - one CHUNK message containing the new file data
// (the old one should have been overriden)
// - one META message
assert_eq!(stream.info().await.unwrap().state.messages, 2);
}

#[tokio::test]
async fn watch() {
let server = nats_server::run_server("tests/configs/jetstream.conf");
Expand Down

0 comments on commit a32cdb5

Please sign in to comment.