Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Callum-A committed Sep 13, 2024
1 parent 54af39e commit 43a4283
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions async-nats/tests/kv_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,57 @@ mod kv {
assert!(info.config.allow_direct);
}

#[tokio::test]
async fn get_or_create_bucket() {
let server = nats_server::run_server("tests/configs/jetstream.conf");
let client = ConnectOptions::new()
.event_callback(|event| async move { println!("event: {event:?}") })
.connect(server.client_url())
.await
.unwrap();

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

let mut kv = context
.get_or_create_key_value(
"test",
async_nats::jetstream::kv::Config {
bucket: "test".into(),
description: "test_description".into(),
history: 10,
storage: StorageType::File,
num_replicas: 1,
..Default::default()
},
)
.await
.unwrap();
let info = kv.stream.info().await.unwrap();
assert_eq!("KV_test", kv.stream_name);
assert_eq!(info.config.discard, DiscardPolicy::New);
assert!(info.config.allow_direct);

let mut kv2 = context
.get_or_create_key_value(
"test",
async_nats::jetstream::kv::Config {
bucket: "test".into(),
description: "test_description".into(),
history: 10,
storage: StorageType::File,
num_replicas: 1,
..Default::default()
},
)
.await
.unwrap();

let info2 = kv2.stream.info().await.unwrap();
assert_eq!(kv2.stream_name, kv.stream_name);
assert_eq!(info2.config.discard, info.config.discard);
assert_eq!(info2.config.allow_direct, info.config.allow_direct);
}

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

0 comments on commit 43a4283

Please sign in to comment.