Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adding unit tests for offset enum #2170

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading