Skip to content

Commit

Permalink
Merge pull request #113 from muzzammilshahid/interop-pubsub
Browse files Browse the repository at this point in the history
Add Interoperability tests for PubSub
  • Loading branch information
muzzammilshahid authored Jul 3, 2024
2 parents 69b8875 + 181f23c commit 6a13c1b
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/interoptests/messages/event_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import "package:collection/collection.dart";
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

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

import "../helper.dart";

void main() {
group("Event", () {
const equality = DeepCollectionEquality();

bool isEqual(Event msg1, Event msg2) =>
msg1.subscriptionID == msg2.subscriptionID &&
msg1.publicationID == msg2.publicationID &&
equality.equals(msg1.details, msg2.details) &&
equality.equals(msg1.args, msg2.args) &&
equality.equals(msg1.kwargs, msg2.kwargs);

test("JSONSerializer", () async {
var msg = Event(1, 1);
var command = "message event ${msg.subscriptionID} ${msg.publicationID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Event;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Event(1, 1, args: ["abc"]);
var command = "message event ${msg.subscriptionID} ${msg.publicationID} abc --serializer cbor --output hex";

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

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Event;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Event(1, 1, details: {"abc": 1}, args: ["abc"], kwargs: {"a": 1});
var command =
"message event ${msg.subscriptionID} ${msg.publicationID} abc -d abc=1 -k a=1 --serializer msgpack --output hex";

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

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Event;
expect(isEqual(message, msg), true);
});
});
}
56 changes: 56 additions & 0 deletions test/interoptests/messages/publish_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import "package:collection/collection.dart";
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

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

import "../helper.dart";

void main() {
group("Publish", () {
const equality = DeepCollectionEquality();

bool isEqual(Publish msg1, Publish 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 msg = Publish(1, "io.xconn.topic");
var command = "message publish ${msg.requestID} ${msg.uri} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Publish;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Publish(1, "io.xconn.topic", args: ["abc"]);
var command = "message publish ${msg.requestID} ${msg.uri} abc --serializer cbor --output hex";

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

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Publish;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Publish(1, "io.xconn.topic", options: {"abc": 1}, args: ["abc"], kwargs: {"a": 1});
var command = "message publish ${msg.requestID} ${msg.uri} abc -o abc=1 -k a=1 --serializer msgpack --output hex";

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

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Publish;
expect(isEqual(message, msg), true);
});
});
}
49 changes: 49 additions & 0 deletions test/interoptests/messages/published_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

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

import "../helper.dart";

void main() {
group("Published", () {
bool isEqual(Published msg1, Published msg2) =>
msg1.requestID == msg2.requestID && msg1.publicationID == msg2.publicationID;

test("JSONSerializer", () async {
var msg = Published(1, 1);
var command = "message published ${msg.requestID} ${msg.publicationID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Published;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Published(1, 1);
var command = "message published ${msg.requestID} ${msg.publicationID} --serializer cbor --output hex";

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

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Published;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Published(1, 1);
var command = "message published ${msg.requestID} ${msg.publicationID} --serializer msgpack --output hex";

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

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Published;
expect(isEqual(message, msg), true);
});
});
}
53 changes: 53 additions & 0 deletions test/interoptests/messages/subscribe_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import "package:collection/collection.dart";
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

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

import "../helper.dart";

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

bool isEqual(Subscribe msg1, Subscribe msg2) =>
msg1.requestID == msg2.requestID && msg1.topic == msg2.topic && equality.equals(msg1.options, msg2.options);

test("JSONSerializer", () async {
var msg = Subscribe(1, topic);
var command = "message subscribe ${msg.requestID} ${msg.topic} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Subscribe;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Subscribe(1, topic);
var command = "message subscribe ${msg.requestID} ${msg.topic} --serializer cbor --output hex";

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

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Subscribe;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Subscribe(1, topic, options: {"a": 1});
var command = "message subscribe ${msg.requestID} ${msg.topic} -o a=1 --serializer msgpack --output hex";

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

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Subscribe;
expect(isEqual(message, msg), true);
});
});
}
49 changes: 49 additions & 0 deletions test/interoptests/messages/subscribed_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

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

import "../helper.dart";

void main() {
group("Subscribed", () {
bool isEqual(Subscribed msg1, Subscribed msg2) =>
msg1.requestID == msg2.requestID && msg1.subscriptionID == msg2.subscriptionID;

test("JSONSerializer", () async {
var msg = Subscribed(1, 1);
var command = "message subscribed ${msg.requestID} ${msg.subscriptionID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Subscribed;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Subscribed(1, 1);
var command = "message subscribed ${msg.requestID} ${msg.subscriptionID} --serializer cbor --output hex";

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

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Subscribed;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Subscribed(1, 1);
var command = "message subscribed ${msg.requestID} ${msg.subscriptionID} --serializer msgpack --output hex";

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

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Subscribed;
expect(isEqual(message, msg), true);
});
});
}
48 changes: 48 additions & 0 deletions test/interoptests/messages/unsubscribed_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

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

import "../helper.dart";

void main() {
group("Unsubscribed", () {
bool isEqual(UnSubscribed msg1, UnSubscribed msg2) => msg1.requestID == msg2.requestID;

test("JSONSerializer", () async {
var msg = UnSubscribed(1);
var command = "message unsubscribed ${msg.requestID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as UnSubscribed;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = UnSubscribed(1);
var command = "message unsubscribed ${msg.requestID} --serializer cbor --output hex";

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

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as UnSubscribed;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = UnSubscribed(1);
var command = "message unsubscribed ${msg.requestID} --serializer msgpack --output hex";

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

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as UnSubscribed;
expect(isEqual(message, msg), true);
});
});
}
49 changes: 49 additions & 0 deletions test/interoptests/messages/unsusbcribe_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

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

import "../helper.dart";

void main() {
group("Unsubscribe", () {
bool isEqual(UnSubscribe msg1, UnSubscribe msg2) =>
msg1.requestID == msg2.requestID && msg1.subscriptionID == msg2.subscriptionID;

test("JSONSerializer", () async {
var msg = UnSubscribe(1, 1);
var command = "message unsubscribe ${msg.requestID} ${msg.subscriptionID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as UnSubscribe;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = UnSubscribe(1, 1);
var command = "message unsubscribe ${msg.requestID} ${msg.subscriptionID} --serializer cbor --output hex";

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

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as UnSubscribe;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = UnSubscribe(1, 1);
var command = "message unsubscribe ${msg.requestID} ${msg.subscriptionID} --serializer msgpack --output hex";

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

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as UnSubscribe;
expect(isEqual(message, msg), true);
});
});
}

0 comments on commit 6a13c1b

Please sign in to comment.