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

Add interop tests for call message #101

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ environment:
# Add regular dependencies here.
dependencies:
cbor: ^6.2.0
collection: ^1.18.0
crypto: ^3.0.3
msgpack_dart: ^1.0.1
pinenacl: ^0.5.1
Expand Down
9 changes: 1 addition & 8 deletions test/interoptests/auth_test.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import "dart:io";

import "package:pinenacl/ed25519.dart";
import "package:test/test.dart";

import "package:wampproto/src/auth/cryptosign.dart";

Future<String> runCommand(String command) async {
ProcessResult result = await Process.run("wampproto", command.split(" "));
expect(result.exitCode, 0, reason: result.stderr);

return result.stdout;
}
import "helper.dart";

void main() {
group("CryptoSignAuth", () {
Expand Down
10 changes: 10 additions & 0 deletions test/interoptests/helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import "dart:io";

import "package:test/test.dart";

Future<String> runCommand(String command) async {
ProcessResult result = await Process.run("wampproto", command.split(" "));
expect(result.exitCode, 0, reason: result.stderr);

return result.stdout;
}
64 changes: 64 additions & 0 deletions test/interoptests/messages_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import "dart:convert";

import "package:collection/collection.dart";
import "package:pinenacl/api.dart";
import "package:test/test.dart";

import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "helper.dart";

void main() {
group("Messages", () {
const equality = DeepCollectionEquality();
const testProcedure = "io.xconn.test";

var jsonSerializer = JSONSerializer();
var cborSerializer = CBORSerializer();
var msgPackSerializer = MsgPackSerializer();

group("Call", () {
bool isEqual(Call msg1, Call msg2) =>
msg1.requestID == msg2.requestID &&
msg1.uri == msg2.uri &&
equality.equals(msg1.options, msg2.options) &&
equality.equals(msg1.args, msg2.args) &&
equality.equals(msg1.kwargs, msg2.kwargs);

test("JSONSerializer", () async {
var callMessage = Call(CallFields(1, testProcedure));
var command = "message call ${callMessage.requestID} ${callMessage.uri} --serializer json";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());
var jsonString = utf8.decode(outputBytes);

var message = jsonSerializer.deserialize(jsonString) as Call;
expect(isEqual(message, callMessage), true);
});

test("CBORSerializer", () async {
var callMessage = Call(CallFields(1, testProcedure, args: ["abc"]));
var command = "message call ${callMessage.requestID} ${callMessage.uri} abc --serializer cbor";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var message = cborSerializer.deserialize(outputBytes) as Call;
expect(isEqual(message, callMessage), true);
});

test("MsgPackSerializer", () async {
var callMessage = Call(CallFields(1, testProcedure, args: ["abc"], kwargs: {"a": 1}));
var command = "message call ${callMessage.requestID} ${callMessage.uri} abc -k a=1 --serializer msgpack";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var message = msgPackSerializer.deserialize(outputBytes) as Call;
expect(isEqual(message, callMessage), true);
});
});
});
}