Skip to content

Commit

Permalink
All tests work...
Browse files Browse the repository at this point in the history
And this mod was proof that simd_json does, indeed, mess with the source slice! Docs on switching to simd_json will
need to make that very clear.
  • Loading branch information
Martin Bartlett committed Oct 25, 2024
1 parent bcf29ef commit ebf675f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lambda-events/src/event/sns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,21 @@ mod test {
fn my_example_sns_event_cloudwatch_single_metric() {
let mut data =
include_bytes!("../../fixtures/example-cloudwatch-alarm-sns-payload-single-metric.json").to_vec();

let parsed: SnsEvent = aws_lambda_json_impl::from_slice(data.as_mut_slice()).unwrap();
assert_eq!(1, parsed.records.len());

let mut output = aws_lambda_json_impl::to_string(&parsed).unwrap().into_bytes();
let reparsed: SnsEvent = aws_lambda_json_impl::from_slice(output.as_mut_slice()).unwrap();
assert_eq!(parsed, reparsed);

//
// Without this, the test fails when using simd_json - precisely because simd_json needs a
// MUTABLE reference and it WILL modify the slice!
//
let mut data =
include_bytes!("../../fixtures/example-cloudwatch-alarm-sns-payload-single-metric.json").to_vec();

let parsed: SnsEventObj<CloudWatchAlarmPayload> =
aws_lambda_json_impl::from_slice(data.as_mut_slice()).expect("failed to parse CloudWatch Alarm payload");

Expand Down

0 comments on commit ebf675f

Please sign in to comment.