-
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.
Add check for existence of pubkey in authExtra alongside nil check
- Loading branch information
1 parent
4329ecd
commit 0ef6430
Showing
1 changed file
with
66 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,66 @@ | ||
package messages_test | ||
|
||
import ( | ||
"encoding/hex" | ||
"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 callsEqual(msg1 *messages.Call, msg2 *messages.Call) bool { | ||
return msg1.RequestID() == msg2.RequestID() && | ||
msg1.Procedure() == msg2.Procedure() && | ||
reflect.DeepEqual(msg1.Options(), msg2.Options()) && | ||
reflect.DeepEqual(msg1.Args(), msg2.Args()) && | ||
reflect.DeepEqual(msg1.KwArgs(), msg2.KwArgs()) | ||
} | ||
func TestCallJSONSerializer(t *testing.T) { | ||
var message = messages.NewCall(1, map[string]any{}, "test", nil, nil) | ||
command := fmt.Sprintf("message call %v %s --serializer json", message.RequestID(), message.Procedure()) | ||
|
||
output, err := tests.RunCommand(command) | ||
require.NoError(t, err) | ||
|
||
var jsonSerializer = serializers.JSONSerializer{} | ||
msg, err := jsonSerializer.Deserialize([]byte(output)) | ||
require.NoError(t, err) | ||
require.True(t, callsEqual(message, msg.(*messages.Call))) | ||
} | ||
|
||
func TestCallCBORSerializer(t *testing.T) { | ||
var message = messages.NewCall(1, map[string]any{}, "test", []any{"abc"}, map[string]any{"abc": "xyz"}) | ||
command := fmt.Sprintf("message call %v %s abc -k abc=xyz --serializer cbor --output hex", | ||
message.RequestID(), message.Procedure()) | ||
|
||
output, err := tests.RunCommand(command) | ||
require.NoError(t, err) | ||
outputBytes, err := hex.DecodeString(output) | ||
require.NoError(t, err) | ||
|
||
var cborSerializer = serializers.CBORSerializer{} | ||
msg, err := cborSerializer.Deserialize(outputBytes) | ||
require.NoError(t, err) | ||
require.True(t, callsEqual(message, msg.(*messages.Call))) | ||
} | ||
|
||
func TestCallMsgPackSerializer(t *testing.T) { | ||
var message = messages.NewCall(1, map[string]any{}, "test", []any{"abc"}, map[string]any{"abc": "xyz"}) | ||
command := fmt.Sprintf("message call %v %s abc -k abc=xyz --serializer msgpack --output hex", | ||
message.RequestID(), message.Procedure()) | ||
|
||
output, err := tests.RunCommand(command) | ||
require.NoError(t, err) | ||
outputBytes, err := hex.DecodeString(output) | ||
require.NoError(t, err) | ||
|
||
var msgPackSerializer = serializers.MsgPackSerializer{} | ||
msg, err := msgPackSerializer.Deserialize(outputBytes) | ||
require.NoError(t, err) | ||
require.True(t, callsEqual(message, msg.(*messages.Call))) | ||
} |