CoapClient (unit tests)

- Added a test for the message IDs
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-25 20:12:41 +02:00
parent 6c20adfe11
commit 9578ad029f
1 changed files with 42 additions and 0 deletions

View File

@ -317,6 +317,48 @@ version(unittest)
import std.stdio : writeln;
}
/**
* Client testing
*
* Tests the rolling of the message id
*/
unittest
{
CoapClient client = new CoapClient("coap.me", 5683);
CoapRequestFuture future = client.newRequestBuilder()
.payload(cast(ubyte[])"First message")
.token([69])
.post();
writeln("Future start (first)");
CoapPacket response = future.get();
writeln("Future done (first)");
writeln("Got response (first): ", response);
assert(response.getMessageId() == 0);
future = client.newRequestBuilder()
.payload(cast(ubyte[])"Second message")
.token([69])
.post();
writeln("Future start (second)");
response = future.get();
writeln("Future done (second)");
writeln("Got response (second): ", response);
assert(response.getMessageId() == 1);
client.close();
}
/**
* Client testing
*