From aea95dfb755371ba94fe36aeb7641bf697ac3ea4 Mon Sep 17 00:00:00 2001 From: bsbds <69835502+bsbds@users.noreply.github.com> Date: Sun, 8 Oct 2023 11:10:58 +0800 Subject: [PATCH] test: add test for txn command keys Signed-off-by: bsbds <69835502+bsbds@users.noreply.github.com> --- xlineapi/src/command.rs | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/xlineapi/src/command.rs b/xlineapi/src/command.rs index 3b2dd3d6f..67861ea5a 100644 --- a/xlineapi/src/command.rs +++ b/xlineapi/src/command.rs @@ -852,4 +852,52 @@ mod test { ::decode(&sync_resp.encode()).expect("decode should success"); assert_eq!(sync_resp, decoded_sync_resp); } + + #[test] + fn txn_command_keys_is_ok() { + let txn_req = TxnRequest { + compare: vec![Compare { + key: b"a".to_vec(), + ..Default::default() + }], + success: vec![ + RequestOp { + request: Some(Request::RequestRange(RangeRequest { + key: b"1".to_vec(), + ..Default::default() + })), + }, + RequestOp { + request: Some(Request::RequestTxn(TxnRequest { + compare: vec![Compare { + key: b"b".to_vec(), + range_end: b"e".to_vec(), + ..Default::default() + }], + success: vec![RequestOp { + request: Some(Request::RequestRange(RangeRequest { + key: b"3".to_vec(), + range_end: b"4".to_vec(), + ..Default::default() + })), + }], + failure: vec![], + })), + }, + ], + failure: vec![RequestOp { + request: Some(Request::RequestPut(PutRequest { + key: b"2".to_vec(), + ..Default::default() + })), + }], + }; + + let keys = txn_req.keys(); + assert!(keys.contains(&KeyRange::new_one_key("a"))); + assert!(keys.contains(&KeyRange::new("b", "e"))); + assert!(keys.contains(&KeyRange::new_one_key("1"))); + assert!(keys.contains(&KeyRange::new_one_key("2"))); + assert!(keys.contains(&KeyRange::new("3", "4"))); + } }