From 9eb87b4b9da6a85ca80328bd9df3ef6a49b36ad5 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Thu, 5 Sep 2024 11:00:41 +0530 Subject: [PATCH] Restructure message-identification related test-cases --- ballerina/tests/queue_producer_consumer_tests.bal | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ballerina/tests/queue_producer_consumer_tests.bal b/ballerina/tests/queue_producer_consumer_tests.bal index 9936938..00096e0 100644 --- a/ballerina/tests/queue_producer_consumer_tests.bal +++ b/ballerina/tests/queue_producer_consumer_tests.bal @@ -542,13 +542,22 @@ function produceMessagesWithIdentification() returns error? { byte[]? payload = message?.payload; test:assertEquals(message?.userId, userId, "Invalid userId"); - test:assertEquals((string:fromBytes(check message?.accountingToken.ensureType())), accountingToken, "Invalid accounting token"); + byte[] retrievedAccountingToken = trimTrailingZeros(check message?.accountingToken.ensureType()); + test:assertEquals(retrievedAccountingToken, accountingToken.toBytes(), "Invalid accounting token"); test:assertEquals(string:fromBytes(check payload.ensureType()), messageContent, "Invalid message content"); check queue->close(); check queueManager.disconnect(); } +function trimTrailingZeros(byte[] bytes) returns byte[] { + int i = bytes.length() - 1; + while (i >= 0 && bytes[i] == 0) { + i -= 1; + } + return bytes.slice(0, i + 1); +} + @test:Config { groups: ["ibmmqQueue", "charset"] }