Skip to content

Commit

Permalink
Use tokio test where store is used to support spawning
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelvalle committed May 24, 2024
1 parent 7cfdea0 commit c122e27
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 132 deletions.
8 changes: 4 additions & 4 deletions src/commands/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ mod tests {
use crate::commands::Command;
use bytes::Bytes;

#[test]
fn when_key_does_not_exists() {
#[tokio::test]
async fn when_key_does_not_exists() {
let store = Arc::new(Mutex::new(Store::new()));

let frame = Frame::Array(vec![
Expand All @@ -87,8 +87,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("foo"), Some(&Bytes::from("baz")));
}

#[test]
fn when_key_exists() {
#[tokio::test]
async fn when_key_exists() {
let store = Arc::new(Mutex::new(Store::new()));

let frame = Frame::Array(vec![
Expand Down
8 changes: 4 additions & 4 deletions src/commands/dbsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ mod tests {
use crate::commands::Command;
use bytes::Bytes;

#[test]
fn zero_keys() {
#[tokio::test]
async fn zero_keys() {
let frame = Frame::Array(vec![Frame::Bulk(Bytes::from("DBSIZE"))]);
let cmd = Command::try_from(frame).unwrap();

Expand All @@ -46,8 +46,8 @@ mod tests {
assert_eq!(result, Frame::Integer(0));
}

#[test]
fn multiple_keys() {
#[tokio::test]
async fn multiple_keys() {
let frame = Frame::Array(vec![Frame::Bulk(Bytes::from("DBSIZE"))]);
let cmd = Command::try_from(frame).unwrap();

Expand Down
16 changes: 8 additions & 8 deletions src/commands/decr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ mod tests {
use crate::commands::Command;
use bytes::Bytes;

#[test]
fn existing_key() {
#[tokio::test]
async fn existing_key() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("DECR")),
Frame::Bulk(Bytes::from("key1")),
Expand All @@ -69,8 +69,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("key1"), Some(&Bytes::from("0")));
}

#[test]
fn non_existing_key() {
#[tokio::test]
async fn non_existing_key() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("DECR")),
Frame::Bulk(Bytes::from("key1")),
Expand All @@ -93,8 +93,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("key1"), Some(&Bytes::from("-1")));
}

#[test]
fn invalid_key_type() {
#[tokio::test]
async fn invalid_key_type() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("DECR")),
Frame::Bulk(Bytes::from("key1")),
Expand Down Expand Up @@ -127,8 +127,8 @@ mod tests {
);
}

#[test]
fn out_of_range() {
#[tokio::test]
async fn out_of_range() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("DECR")),
Frame::Bulk(Bytes::from("key1")),
Expand Down
16 changes: 8 additions & 8 deletions src/commands/decrby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ mod tests {
use crate::commands::Command;
use bytes::Bytes;

#[test]
fn existing_key() {
#[tokio::test]
async fn existing_key() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("DECRBY")),
Frame::Bulk(Bytes::from("key1")),
Expand Down Expand Up @@ -73,8 +73,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("key1"), Some(&Bytes::from("10")));
}

#[test]
fn non_existing_key() {
#[tokio::test]
async fn non_existing_key() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("DECRBY")),
Frame::Bulk(Bytes::from("key1")),
Expand All @@ -99,8 +99,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("key1"), Some(&Bytes::from("-10")));
}

#[test]
fn invalid_key_type() {
#[tokio::test]
async fn invalid_key_type() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("DECRBY")),
Frame::Bulk(Bytes::from("key1")),
Expand Down Expand Up @@ -135,8 +135,8 @@ mod tests {
);
}

#[test]
fn out_of_range() {
#[tokio::test]
async fn out_of_range() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("DECRBY")),
Frame::Bulk(Bytes::from("key1")),
Expand Down
8 changes: 4 additions & 4 deletions src/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ mod tests {
use crate::commands::Command;
use bytes::Bytes;

#[test]
fn existing_key() {
#[tokio::test]
async fn existing_key() {
let store = Arc::new(Mutex::new(Store::new()));

let frame = Frame::Array(vec![
Expand All @@ -68,8 +68,8 @@ mod tests {
assert_eq!(result, Frame::Bulk(Bytes::from("1")));
}

#[test]
fn non_existing_key() {
#[tokio::test]
async fn non_existing_key() {
let store = Arc::new(Mutex::new(Store::new()));

let frame = Frame::Array(vec![
Expand Down
8 changes: 4 additions & 4 deletions src/commands/getdel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ mod tests {

use super::*;

#[test]
fn when_key_exists() {
#[tokio::test]
async fn when_key_exists() {
let store = Arc::new(Mutex::new(Store::default()));

let frame = Frame::Array(vec![
Expand All @@ -71,8 +71,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("foo"), None);
}

#[test]
fn when_key_does_not_exists() {
#[tokio::test]
async fn when_key_does_not_exists() {
let store = Arc::new(Mutex::new(Store::default()));

let frame = Frame::Array(vec![
Expand Down
16 changes: 8 additions & 8 deletions src/commands/getrange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ mod tests {

use super::*;

#[test]
fn when_key_exists_using_positive_index() {
#[tokio::test]
async fn when_key_exists_using_positive_index() {
let store = Arc::new(Mutex::new(Store::default()));

let frame = Frame::Array(vec![
Expand Down Expand Up @@ -107,8 +107,8 @@ mod tests {
assert_eq!(res, Frame::Bulk(Bytes::from("This")));
}

#[test]
fn when_key_exists_using_negative_index() {
#[tokio::test]
async fn when_key_exists_using_negative_index() {
let store = Arc::new(Mutex::new(Store::default()));

let frame = Frame::Array(vec![
Expand Down Expand Up @@ -136,8 +136,8 @@ mod tests {
assert_eq!(res, Frame::Bulk(Bytes::from("ing")));
}

#[test]
fn when_key_exists_using_positive_and_negative_index() {
#[tokio::test]
async fn when_key_exists_using_positive_and_negative_index() {
let store = Arc::new(Mutex::new(Store::default()));

let frame = Frame::Array(vec![
Expand Down Expand Up @@ -165,8 +165,8 @@ mod tests {
assert_eq!(res, Frame::Bulk(Bytes::from("This is a string")));
}

#[test]
fn when_key_exists_using_out_of_bound_index() {
#[tokio::test]
async fn when_key_exists_using_out_of_bound_index() {
let store = Arc::new(Mutex::new(Store::default()));

let frame = Frame::Array(vec![
Expand Down
16 changes: 8 additions & 8 deletions src/commands/incr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ mod tests {
use crate::commands::Command;
use bytes::Bytes;

#[test]
fn existing_key() {
#[tokio::test]
async fn existing_key() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("INCR")),
Frame::Bulk(Bytes::from("key1")),
Expand All @@ -69,8 +69,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("key1"), Some(&Bytes::from("2")));
}

#[test]
fn non_existing_key() {
#[tokio::test]
async fn non_existing_key() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("INCR")),
Frame::Bulk(Bytes::from("key1")),
Expand All @@ -93,8 +93,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("key1"), Some(&Bytes::from("1")));
}

#[test]
fn invalid_key_type() {
#[tokio::test]
async fn invalid_key_type() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("INCR")),
Frame::Bulk(Bytes::from("key1")),
Expand Down Expand Up @@ -127,8 +127,8 @@ mod tests {
);
}

#[test]
fn out_of_range() {
#[tokio::test]
async fn out_of_range() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("INCR")),
Frame::Bulk(Bytes::from("key1")),
Expand Down
16 changes: 8 additions & 8 deletions src/commands/incrby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ mod tests {
use crate::commands::Command;
use bytes::Bytes;

#[test]
fn existing_key() {
#[tokio::test]
async fn existing_key() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("INCRBY")),
Frame::Bulk(Bytes::from("key1")),
Expand Down Expand Up @@ -73,8 +73,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("key1"), Some(&Bytes::from("30")));
}

#[test]
fn non_existing_key() {
#[tokio::test]
async fn non_existing_key() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("INCRBY")),
Frame::Bulk(Bytes::from("key1")),
Expand All @@ -99,8 +99,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("key1"), Some(&Bytes::from("10")));
}

#[test]
fn invalid_key_type() {
#[tokio::test]
async fn invalid_key_type() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("INCRBY")),
Frame::Bulk(Bytes::from("key1")),
Expand Down Expand Up @@ -135,8 +135,8 @@ mod tests {
);
}

#[test]
fn out_of_range() {
#[tokio::test]
async fn out_of_range() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("INCRBY")),
Frame::Bulk(Bytes::from("key1")),
Expand Down
12 changes: 6 additions & 6 deletions src/commands/incrbyfloat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ mod tests {
use crate::commands::Command;
use bytes::Bytes;

#[test]
fn existing_key() {
#[tokio::test]
async fn existing_key() {
let store = Arc::new(Mutex::new(Store::new()));

let frame = Frame::Array(vec![
Expand Down Expand Up @@ -87,8 +87,8 @@ mod tests {
);
}

#[test]
fn non_existing_key() {
#[tokio::test]
async fn non_existing_key() {
let store = Arc::new(Mutex::new(Store::new()));

let frame = Frame::Array(vec![
Expand All @@ -112,8 +112,8 @@ mod tests {
assert_eq!(store.lock().unwrap().get("key1"), Some(&Bytes::from("10")));
}

#[test]
fn invalid_key_type() {
#[tokio::test]
async fn invalid_key_type() {
let store = Arc::new(Mutex::new(Store::new()));

let frame = Frame::Array(vec![
Expand Down
4 changes: 2 additions & 2 deletions src/commands/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ mod tests {
use crate::commands::{Command, CommandParserError};
use bytes::Bytes;

#[test]
fn with_wildcard_pattern() {
#[tokio::test]
async fn with_wildcard_pattern() {
let frame = Frame::Array(vec![
Frame::Bulk(Bytes::from("KEYS")),
Frame::Bulk(Bytes::from("*")),
Expand Down
Loading

0 comments on commit c122e27

Please sign in to comment.