Skip to content

Commit

Permalink
chore: adding unit tests for offset enum (#2170)
Browse files Browse the repository at this point in the history
Signed-off-by: Yashash H L <[email protected]>
  • Loading branch information
yhl25 authored Oct 17, 2024
1 parent e8017cd commit 252cf43
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions rust/numaflow-core/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ mod tests {
});
let ack_request: AckRequest = offset.try_into().unwrap();
assert_eq!(ack_request.request.unwrap().offset.unwrap().partition_id, 1);

let offset = Offset::Int(IntOffset::new(42, 1));
let result: Result<AckRequest> = offset.try_into();

// Assert that the conversion results in an error
assert!(result.is_err());

if let Err(e) = result {
assert_eq!(e.to_string(), "Source Error - IntOffset not supported");
}
}

#[test]
Expand Down Expand Up @@ -634,4 +644,35 @@ mod tests {
assert_eq!(proto_id.offset, "123");
assert_eq!(proto_id.index, 0);
}

#[test]
fn test_offset_cases() {
let int_offset = IntOffset::new(42, 1);
assert_eq!(int_offset.offset, 42);
assert_eq!(int_offset.partition_idx, 1);
assert_eq!(format!("{}", int_offset), "42-1");

let string_offset = StringOffset::new("42".to_string(), 1);
assert_eq!(string_offset.offset, "42");
assert_eq!(string_offset.partition_idx, 1);
assert_eq!(format!("{}", string_offset), "42-1");

let offset_int = Offset::Int(int_offset);
assert_eq!(format!("{}", offset_int), "42-1");

let offset_string = Offset::String(string_offset);
assert_eq!(format!("{}", offset_string), "42-1");

// Test conversion from Offset to AckRequest for StringOffset
let offset = Offset::String(StringOffset::new(BASE64_STANDARD.encode("42"), 1));
let result: Result<AckRequest> = offset.try_into();
assert!(result.is_ok());
let ack_request = result.unwrap();
assert_eq!(ack_request.request.unwrap().offset.unwrap().partition_id, 1);

// Test conversion from Offset to AckRequest for IntOffset (should fail)
let offset = Offset::Int(IntOffset::new(42, 1));
let result: Result<AckRequest> = offset.try_into();
assert!(result.is_err());
}
}

0 comments on commit 252cf43

Please sign in to comment.