Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing module with mock redis connection and command
- Loading branch information
Tom Dyas
committed
May 30, 2022
1 parent
e2bcc14
commit 86689d7
Showing
4 changed files
with
426 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
[workspace] | ||
members = ["redis"] | ||
|
||
members = ["redis", "redis-test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "redis-test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "Testing helpers for the `redis` crate" | ||
homepage = "https://github.com/redis-rs/redis-rs" | ||
repository = "https://github.com/redis-rs/redis-rs" | ||
documentation = "https://docs.rs/redis-test" | ||
license = "BSD-3-Clause" | ||
|
||
[dependencies] | ||
redis = { version = "0.21.5", path = "../redis" } | ||
|
||
bytes = { version = "1", optional = true } | ||
futures = { version = "0.3", optional = true } | ||
|
||
[features] | ||
aio = ["futures", "redis/aio"] | ||
tokio-comp = ["redis/tokio-comp"] | ||
async-std-comp = ["redis/async-std-comp"] | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread", "time"] } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! Testing support | ||
//! | ||
//! This module provides `MockRedisConnection` which implements ConnectionLike and can be | ||
//! used in the same place as any other type that behaves like a Redis connection. This is useful | ||
//! for writing unit tests without needing a Redis server. | ||
//! | ||
//! # Example | ||
//! | ||
//! ```rust | ||
//! use redis::{ConnectionLike, RedisError}; | ||
//! use redis_test::mock_conn::{MockCmd, MockRedisConnection}; | ||
//! | ||
//! fn my_exists<C: ConnectionLike>(conn: &mut C, key: &str) -> Result<bool, RedisError> { | ||
//! let exists: bool = redis::cmd("EXISTS").arg(key).query(conn)?; | ||
//! Ok(exists) | ||
//! } | ||
//! | ||
//! let mut mock_connection = MockRedisConnection::new(vec![ | ||
//! MockCmd::new(redis::cmd("EXISTS").arg("foo"), Ok("1")), | ||
//! ]); | ||
//! | ||
//! let result = my_exists(&mut mock_connection, "foo").unwrap(); | ||
//! assert_eq!(result, true); | ||
//! ``` | ||
|
||
pub mod mock_conn; |
Oops, something went wrong.