Skip to content

Commit

Permalink
No need to so thoroughly test the redis 'exec' implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
  • Loading branch information
rylev committed Jun 26, 2024
1 parent 83b80af commit a49bdd4
Showing 1 changed file with 0 additions and 71 deletions.
71 changes: 0 additions & 71 deletions components/outbound-redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,77 +87,6 @@ fn handle(request: IncomingRequest) -> anyhow::Result<OutgoingResponse> {
values.as_slice(),
&[redis::RedisResult::Binary(ref b)] if b == b"Eureka! I've got it!"));

connection.execute(
"set",
&[
redis::RedisParameter::Binary(b"int-key".to_vec()),
redis::RedisParameter::Int64(0),
],
)?;

let values = connection.execute(
"incr",
&[redis::RedisParameter::Binary(b"int-key".to_vec())],
)?;

anyhow::ensure!(
matches!(values.as_slice(), &[redis::RedisResult::Int64(1)]),
"call to `execute('incr')` returned unexpected result: {values:?} != &[redis::RedisResult::Int64(1)]"
);

let values =
connection.execute("get", &[redis::RedisParameter::Binary(b"int-key".to_vec())])?;

anyhow::ensure!(matches!(
values.as_slice(),
&[redis::RedisResult::Binary(ref b)] if b == b"1"
));

connection.execute("del", &[redis::RedisParameter::Binary(b"foo".to_vec())])?;

connection.execute(
"sadd",
&[
redis::RedisParameter::Binary(b"foo".to_vec()),
redis::RedisParameter::Binary(b"bar".to_vec()),
redis::RedisParameter::Binary(b"baz".to_vec()),
],
)?;

let values = connection.execute(
"smembers",
&[redis::RedisParameter::Binary(b"foo".to_vec())],
)?;
let mut values = values
.iter()
.map(|v| match v {
redis::RedisResult::Binary(v) => Ok(v.as_slice()),
v => Err(anyhow::anyhow!("unexpected value: {v:?}")),
})
.collect::<anyhow::Result<Vec<_>>>()?;
// Ensure the values are always in a deterministic order
values.sort();

anyhow::ensure!(matches!(values.as_slice(), &[b"bar", b"baz",]));

connection.execute(
"srem",
&[
redis::RedisParameter::Binary(b"foo".to_vec()),
redis::RedisParameter::Binary(b"baz".to_vec()),
],
)?;

let values = connection.execute(
"smembers",
&[redis::RedisParameter::Binary(b"foo".to_vec())],
)?;

anyhow::ensure!(matches!(
values.as_slice(),
&[redis::RedisResult::Binary(ref bar)] if bar == b"bar"
));

Ok(response(200, b""))
}

Expand Down

0 comments on commit a49bdd4

Please sign in to comment.