Skip to content

Commit

Permalink
Tests: incr and fix output
Browse files Browse the repository at this point in the history
  • Loading branch information
gillchristian committed Jul 25, 2024
1 parent 29a2694 commit 90ca26f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/commands/incr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Executable for Incr {
fn exec(self, store: Store) -> Result<Frame, Error> {
let res = store.incr_by(&self.key, 1);
match res {
Ok(_) => Ok(Frame::Simple("OK".to_string())),
Ok(val) => Ok(Frame::Integer(val)),
Err(msg) => Ok(Frame::Error(msg.to_string())),
}
}
Expand Down Expand Up @@ -60,7 +60,7 @@ mod tests {

let result = cmd.exec(store.clone()).unwrap();

assert_eq!(result, Frame::Simple("OK".to_string()));
assert_eq!(result, Frame::Integer(2));
assert_eq!(store.lock().get("key1"), Some(Bytes::from("2")));
}

Expand All @@ -83,7 +83,7 @@ mod tests {

let result = cmd.exec(store.clone()).unwrap();

assert_eq!(result, Frame::Simple("OK".to_string()));
assert_eq!(result, Frame::Integer(1));
assert_eq!(store.lock().get("key1"), Some(Bytes::from("1")));
}

Expand Down
25 changes: 25 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ where
.await
.unwrap();

// Since we use the same Redis instance for all tests, we flush it to start fresh.
// NOTE: our implementation doesn't yet persist data between runs.
let _: Value = redis::pipe()
.cmd("FLUSHDB")
.query_async(&mut their_connection)
.await
.unwrap();

let their_response: Res = pipeline
.clone()
.query_async(&mut their_connection)
Expand Down Expand Up @@ -114,3 +122,20 @@ async fn test_exists() {
})
.await;
}

#[tokio::test]
async fn test_incr() {
type Response = (Value, Value, Value, Value, Value, Value, Value);

test_compare::<Response>(|p| {
p.cmd("SET").arg("incr_key_1").arg(1);
p.cmd("SET").arg("incr_key_2").arg(1);
p.cmd("SET").arg("incr_key_3").arg("1");

p.cmd("INCR").arg("incr_key_1");
p.cmd("INCR").arg("incr_key_2");
p.cmd("INCR").arg("incr_key_3");
p.cmd("INCR").arg("incr_key_4");
})
.await;
}

0 comments on commit 90ca26f

Please sign in to comment.