-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tom Havlik
authored and
Tom Havlik
committed
May 9, 2020
1 parent
127f979
commit 3b80a36
Showing
7 changed files
with
282 additions
and
160 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
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
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
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,11 +1,81 @@ | ||
use super::*; | ||
|
||
#[cfg(test)] | ||
mod release { | ||
use super::*; | ||
|
||
const SCRIPT: &'static str = include_str!("../../lua/release.lua"); | ||
|
||
#[test] | ||
fn load() { | ||
let mut client = redis::Client::open("redis://127.0.0.1:6379").unwrap(); | ||
let hash: String = redis::cmd("SCRIPT") | ||
.arg("LOAD") | ||
.arg(SCRIPT) | ||
.query(&mut client) | ||
.unwrap(); | ||
assert_eq!(hash.len(), 40); | ||
} | ||
|
||
#[test] | ||
fn ok() {} | ||
fn ok() { | ||
let resource = Uuid::new_v4().to_string(); | ||
let claim = Uuid::new_v4().to_string(); | ||
let key = rk::claim(&resource); | ||
let mut client = redis::Client::open("redis://127.0.0.1:6379").unwrap(); | ||
let _: () = redis::cmd("SET") | ||
.arg(&key) | ||
.arg(&claim) | ||
.query(&mut client) | ||
.unwrap(); | ||
let _: () = redis::cmd("EVAL") | ||
.arg(SCRIPT) | ||
.arg(1) | ||
.arg(&key) | ||
.arg(&claim) | ||
.query(&mut client) | ||
.unwrap(); | ||
let result: Option<String> = redis::cmd("GET") | ||
.arg(&key) | ||
.query(&mut client) | ||
.unwrap(); | ||
assert!(result.is_none()); | ||
} | ||
|
||
#[test] | ||
fn err_no_claim() {} | ||
fn err_no_claim() { | ||
let resource = Uuid::new_v4().to_string(); | ||
let claim = Uuid::new_v4().to_string(); | ||
let key = rk::claim(&resource); | ||
let mut client = redis::Client::open("redis://127.0.0.1:6379").unwrap(); | ||
let err = redis::cmd("EVAL") | ||
.arg(SCRIPT) | ||
.arg(1) | ||
.arg(&key) | ||
.arg(&claim) | ||
.query::<()>(&mut client) | ||
.unwrap_err(); | ||
assert_eq!(err.code().unwrap(), "NoClaim"); | ||
} | ||
|
||
#[test] | ||
fn err_bad_claim() {} | ||
fn err_bad_claim() { | ||
let resource = Uuid::new_v4().to_string(); | ||
let claim = Uuid::new_v4().to_string(); | ||
let key = rk::claim(&resource); | ||
let mut client = redis::Client::open("redis://127.0.0.1:6379").unwrap(); | ||
let _: () = redis::cmd("SET") | ||
.arg(&key) | ||
.arg("foobarbaz") | ||
.query(&mut client) | ||
.unwrap(); | ||
let err = redis::cmd("EVAL") | ||
.arg(SCRIPT) | ||
.arg(1) | ||
.arg(&key) | ||
.arg(&claim) | ||
.query::<()>(&mut client) | ||
.unwrap_err(); | ||
assert_eq!(err.code().unwrap(), "BadClaim"); | ||
} | ||
} |
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
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
Oops, something went wrong.