Skip to content

Commit

Permalink
(tests): Add alloc module tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Hahn <[email protected]>
  • Loading branch information
hahnandrew committed Oct 25, 2024
1 parent 7d31c52 commit 1b212cb
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,3 +736,53 @@ fn test_expire() -> Result<()> {

Ok(())
}

#[test]
fn test_alloc_data_type() -> Result<()> {
let port: u16 = 6503;
let _guards = vec![start_valkey_server_with_module("data_type", port)
.with_context(|| FAILED_TO_START_SERVER)?];
let mut con = get_valkey_connection(port).with_context(|| FAILED_TO_CONNECT_TO_SERVER)?;

// Set value and verify allocation
let res: i64 = redis::cmd("alloc.set")
.arg(&["test_key", "10"])
.query(&mut con)
.with_context(|| "failed to run alloc.set")?;
assert_eq!(res, 10);

// Get value and verify content
let res: String = redis::cmd("alloc.get")
.arg(&["test_key"])
.query(&mut con)
.with_context(|| "failed to run alloc.get")?;
assert_eq!(res, "A".repeat(10));

// Update existing key to test reallocation
let res: i64 = redis::cmd("alloc.set")
.arg(&["test_key", "5"])
.query(&mut con)
.with_context(|| "failed to run alloc.set")?;
assert_eq!(res, 5);

// Test updated content
let res: String = redis::cmd("alloc.get")
.arg(&["test_key"])
.query(&mut con)
.with_context(|| "failed to run alloc.get")?;
assert_eq!(res, "B".repeat(5));

let _: i64 = redis::cmd("DEL")
.arg(&["test_key"])
.query(&mut con)
.with_context(|| "failed to run DEL")?;

// Test that get returns None after deleting
let res: Option<String> = redis::cmd("alloc.get")
.arg(&["test_key"])
.query(&mut con)
.with_context(|| "failed to run alloc.get")?;
assert!(res.is_none());

Ok(())
}

0 comments on commit 1b212cb

Please sign in to comment.