-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from muzzammilshahid/interop-pubsub-messages
Add interoperability tests for pubsub messages
- Loading branch information
Showing
7 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package messages_test | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/xconnio/wampproto-go/messages" | ||
"github.com/xconnio/wampproto-go/serializers" | ||
"github.com/xconnio/wampproto-go/tests" | ||
) | ||
|
||
func eventsEqual(msg1 *messages.Event, msg2 *messages.Event) bool { | ||
return msg1.SubscriptionID() == msg2.SubscriptionID() && | ||
msg1.PublicationID() == msg2.PublicationID() && | ||
reflect.DeepEqual(msg1.Details(), msg2.Details()) && | ||
reflect.DeepEqual(msg1.Args(), msg2.Args()) && | ||
reflect.DeepEqual(msg1.KwArgs(), msg2.KwArgs()) | ||
} | ||
|
||
func testEventMessage(t *testing.T, serializerStr string, serializer serializers.Serializer) { | ||
var message = messages.NewEvent(1, 1, map[string]any{"foo": true}, []any{"abc"}, map[string]any{"abc": "xyz"}) | ||
command := fmt.Sprintf("message event 1 1 abc -d foo=true -k abc=xyz --serializer %s --output hex", serializerStr) | ||
|
||
msg := tests.RunCommandAndDeserialize(t, command, serializer) | ||
require.True(t, eventsEqual(message, msg.(*messages.Event))) | ||
} | ||
|
||
func TestEventMessage(t *testing.T) { | ||
t.Run("JSONSerializer", func(t *testing.T) { | ||
serializer := &serializers.JSONSerializer{} | ||
testEventMessage(t, "json", serializer) | ||
}) | ||
|
||
t.Run("CBORSerializer", func(t *testing.T) { | ||
serializer := &serializers.CBORSerializer{} | ||
testEventMessage(t, "cbor", serializer) | ||
}) | ||
|
||
t.Run("MsgSerializer", func(t *testing.T) { | ||
serializer := &serializers.MsgPackSerializer{} | ||
testEventMessage(t, "msgpack", serializer) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package messages_test | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/xconnio/wampproto-go/messages" | ||
"github.com/xconnio/wampproto-go/serializers" | ||
"github.com/xconnio/wampproto-go/tests" | ||
) | ||
|
||
func publishEqual(msg1 *messages.Publish, msg2 *messages.Publish) bool { | ||
return msg1.RequestID() == msg2.RequestID() && | ||
msg1.Topic() == msg2.Topic() && | ||
reflect.DeepEqual(msg1.Options(), msg2.Options()) && | ||
reflect.DeepEqual(msg1.Args(), msg2.Args()) && | ||
reflect.DeepEqual(msg1.KwArgs(), msg2.KwArgs()) | ||
} | ||
|
||
func testPublishMessage(t *testing.T, serializerStr string, serializer serializers.Serializer) { | ||
var message = messages.NewPublish(1, map[string]any{"abc": "xyz"}, "test", []any{"abc"}, map[string]any{"abc": "xyz"}) | ||
command := fmt.Sprintf("message publish 1 test abc -o abc:xyz -k abc=xyz --serializer %s --output hex", serializerStr) | ||
|
||
msg := tests.RunCommandAndDeserialize(t, command, serializer) | ||
require.True(t, publishEqual(message, msg.(*messages.Publish))) | ||
} | ||
|
||
func TestPublishMessage(t *testing.T) { | ||
t.Run("JSONSerializer", func(t *testing.T) { | ||
serializer := &serializers.JSONSerializer{} | ||
testPublishMessage(t, "json", serializer) | ||
}) | ||
|
||
t.Run("CBORSerializer", func(t *testing.T) { | ||
serializer := &serializers.CBORSerializer{} | ||
testPublishMessage(t, "cbor", serializer) | ||
}) | ||
|
||
t.Run("MsgPackSerializer", func(t *testing.T) { | ||
serializer := &serializers.MsgPackSerializer{} | ||
testPublishMessage(t, "msgpack", serializer) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package messages_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/xconnio/wampproto-go/messages" | ||
"github.com/xconnio/wampproto-go/serializers" | ||
"github.com/xconnio/wampproto-go/tests" | ||
) | ||
|
||
func publishedEqual(msg1 *messages.Published, msg2 *messages.Published) bool { | ||
return msg1.RequestID() == msg2.RequestID() && | ||
msg1.PublicationID() == msg2.PublicationID() | ||
} | ||
|
||
func testPublishedMessage(t *testing.T, serializerStr string, serializer serializers.Serializer) { | ||
var message = messages.NewPublished(1, 1) | ||
command := fmt.Sprintf("message published 1 1 --serializer %s --output hex", serializerStr) | ||
|
||
msg := tests.RunCommandAndDeserialize(t, command, serializer) | ||
require.True(t, publishedEqual(message, msg.(*messages.Published))) | ||
} | ||
|
||
func TestPublishedMessage(t *testing.T) { | ||
t.Run("JSONSerializer", func(t *testing.T) { | ||
serializer := &serializers.JSONSerializer{} | ||
testPublishedMessage(t, "json", serializer) | ||
}) | ||
|
||
t.Run("CBORSerializer", func(t *testing.T) { | ||
serializer := &serializers.CBORSerializer{} | ||
testPublishedMessage(t, "cbor", serializer) | ||
}) | ||
|
||
t.Run("MsgPackSerializer", func(t *testing.T) { | ||
serializer := &serializers.MsgPackSerializer{} | ||
testPublishedMessage(t, "msgpack", serializer) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package messages_test | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/xconnio/wampproto-go/messages" | ||
"github.com/xconnio/wampproto-go/serializers" | ||
"github.com/xconnio/wampproto-go/tests" | ||
) | ||
|
||
func subscribesEqual(msg1 *messages.Subscribe, msg2 *messages.Subscribe) bool { | ||
return msg1.RequestID() == msg2.RequestID() && | ||
msg1.Topic() == msg2.Topic() && | ||
reflect.DeepEqual(msg1.Options(), msg2.Options()) | ||
} | ||
|
||
func testSubscribeMessage(t *testing.T, serializerStr string, serializer serializers.Serializer) { | ||
var message = messages.NewSubscribe(1, map[string]any{"abc": "xyz"}, "test") | ||
command := fmt.Sprintf("message subscribe 1 test -o abc=xyz --serializer %s --output hex", serializerStr) | ||
|
||
msg := tests.RunCommandAndDeserialize(t, command, serializer) | ||
require.True(t, subscribesEqual(message, msg.(*messages.Subscribe))) | ||
} | ||
|
||
func TestSubscribeMessage(t *testing.T) { | ||
t.Run("JSONSerializer", func(t *testing.T) { | ||
serializer := &serializers.JSONSerializer{} | ||
testSubscribeMessage(t, "json", serializer) | ||
}) | ||
|
||
t.Run("CBORSerializer", func(t *testing.T) { | ||
serializer := &serializers.CBORSerializer{} | ||
testSubscribeMessage(t, "cbor", serializer) | ||
}) | ||
|
||
t.Run("MsgPackSerializer", func(t *testing.T) { | ||
serializer := &serializers.MsgPackSerializer{} | ||
testSubscribeMessage(t, "msgpack", serializer) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package messages_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/xconnio/wampproto-go/messages" | ||
"github.com/xconnio/wampproto-go/serializers" | ||
"github.com/xconnio/wampproto-go/tests" | ||
) | ||
|
||
func subscribedEqual(msg1 *messages.Subscribed, msg2 *messages.Subscribed) bool { | ||
return msg1.RequestID() == msg2.RequestID() && | ||
msg1.SubscriptionID() == msg2.SubscriptionID() | ||
} | ||
|
||
func testSubscribedMessage(t *testing.T, serializerStr string, serializer serializers.Serializer) { | ||
var message = messages.NewSubscribed(1, 1) | ||
command := fmt.Sprintf("message subscribed 1 1 --serializer %s --output hex", serializerStr) | ||
|
||
msg := tests.RunCommandAndDeserialize(t, command, serializer) | ||
require.True(t, subscribedEqual(message, msg.(*messages.Subscribed))) | ||
} | ||
|
||
func TestSubscribedMessage(t *testing.T) { | ||
t.Run("JSONSerializer", func(t *testing.T) { | ||
serializer := &serializers.JSONSerializer{} | ||
testSubscribedMessage(t, "json", serializer) | ||
}) | ||
|
||
t.Run("CBORSerializer", func(t *testing.T) { | ||
serializer := &serializers.CBORSerializer{} | ||
testSubscribedMessage(t, "cbor", serializer) | ||
}) | ||
|
||
t.Run("MsgPackSerializer", func(t *testing.T) { | ||
serializer := &serializers.MsgPackSerializer{} | ||
testSubscribedMessage(t, "msgpack", serializer) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package messages_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/xconnio/wampproto-go/messages" | ||
"github.com/xconnio/wampproto-go/serializers" | ||
"github.com/xconnio/wampproto-go/tests" | ||
) | ||
|
||
func unsubscribeEqual(msg1 *messages.Unsubscribe, msg2 *messages.Unsubscribe) bool { | ||
return msg1.RequestID() == msg2.RequestID() && | ||
msg1.SubscriptionID() == msg2.SubscriptionID() | ||
} | ||
|
||
func testUnsubscribeMessage(t *testing.T, serializerStr string, serializer serializers.Serializer) { | ||
var message = messages.NewUnsubscribe(1, 1) | ||
command := fmt.Sprintf("message unsubscribe 1 1 --serializer %s --output hex", serializerStr) | ||
|
||
msg := tests.RunCommandAndDeserialize(t, command, serializer) | ||
require.True(t, unsubscribeEqual(message, msg.(*messages.Unsubscribe))) | ||
} | ||
|
||
func TestUnsubscribeMessage(t *testing.T) { | ||
t.Run("JSONSerializer", func(t *testing.T) { | ||
serializer := &serializers.JSONSerializer{} | ||
testUnsubscribeMessage(t, "json", serializer) | ||
}) | ||
|
||
t.Run("CBORSerializer", func(t *testing.T) { | ||
serializer := &serializers.CBORSerializer{} | ||
testUnsubscribeMessage(t, "cbor", serializer) | ||
}) | ||
|
||
t.Run("MsgPackSerializer", func(t *testing.T) { | ||
serializer := &serializers.MsgPackSerializer{} | ||
testUnsubscribeMessage(t, "msgpack", serializer) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package messages_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/xconnio/wampproto-go/messages" | ||
"github.com/xconnio/wampproto-go/serializers" | ||
"github.com/xconnio/wampproto-go/tests" | ||
) | ||
|
||
func unsubscribedEqual(msg1 *messages.Unsubscribed, msg2 *messages.Unsubscribed) bool { | ||
return msg1.RequestID() == msg2.RequestID() | ||
} | ||
|
||
func testUnsubscribedMessage(t *testing.T, serializerStr string, serializer serializers.Serializer) { | ||
var message = messages.NewUnsubscribed(1) | ||
command := fmt.Sprintf("message unsubscribed 1 --serializer %s --output hex", serializerStr) | ||
|
||
msg := tests.RunCommandAndDeserialize(t, command, serializer) | ||
require.True(t, unsubscribedEqual(message, msg.(*messages.Unsubscribed))) | ||
} | ||
|
||
func TestUnsubscribedMessage(t *testing.T) { | ||
t.Run("JSONSerializer", func(t *testing.T) { | ||
serializer := &serializers.JSONSerializer{} | ||
testUnsubscribedMessage(t, "json", serializer) | ||
}) | ||
|
||
t.Run("CBORSerializer", func(t *testing.T) { | ||
serializer := &serializers.CBORSerializer{} | ||
testUnsubscribedMessage(t, "cbor", serializer) | ||
}) | ||
|
||
t.Run("MsgPackSerializer", func(t *testing.T) { | ||
serializer := &serializers.MsgPackSerializer{} | ||
testUnsubscribedMessage(t, "msgpack", serializer) | ||
}) | ||
} |