Skip to content

Commit

Permalink
fix trim test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bravo555 committed Oct 21, 2024
1 parent a2353c7 commit 8f12d86
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 3 additions & 1 deletion crates/core/c8y_api/src/smartrest/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ pub const MAX_PAYLOAD_LIMIT_IN_BYTES: usize = 16000;
///
/// - https://cumulocity.com/docs/smartrest/smartrest-introduction/
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SmartrestPayload(String);
// TODO: pub(crate) for now so it can be constructed manually in serializer::succeed_operation, need to figure out a
// good API
pub struct SmartrestPayload(pub(crate) String);

impl SmartrestPayload {
/// Creates a payload that consists of a single record.
Expand Down
9 changes: 3 additions & 6 deletions crates/core/c8y_api/src/smartrest/smartrest_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,10 @@ pub fn succeed_operation(
}
let trimmed_reason = &reason[..max_result_limit];

let new_reason = format!("{trimmed_reason}{trim_indicator}");

SmartrestPayload::serialize((template_id, operation, new_reason))
.expect("shouldn't be too large and serialization should succeed")
format!("{prefix},\"{trimmed_reason}{trim_indicator}\"")
};

Ok(result)
Ok(SmartrestPayload(result))
}

pub fn succeed_operation_with_name(
Expand Down Expand Up @@ -634,7 +631,7 @@ mod tests {

/// Make sure that `reason` field is trimmed correctly, even in presence of double quote
/// sequences.
#[test_case(MAX_PAYLOAD_LIMIT_IN_BYTES - 1, 0; "skips_final_quote_because_wont_fit")]
#[test_case(MAX_PAYLOAD_LIMIT_IN_BYTES - 1, 2; "skips_final_quote_because_wont_fit")]
#[test_case(MAX_PAYLOAD_LIMIT_IN_BYTES - 2, 4; "preserves_final_quote_because_fits")]
fn succeed_operation_trims_reason_field_3171(message_len: usize, expected_num_quotes: usize) {
let prefix_len = "503,c8y_Command,".len();
Expand Down

0 comments on commit 8f12d86

Please sign in to comment.