test: add test for DecodeMessage
This commit is contained in:
parent
2cce0cd46d
commit
adef9b1eb4
|
@ -2,6 +2,8 @@ package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"github.com/vmihailenco/msgpack/v5"
|
||||||
|
@ -94,3 +96,47 @@ func TestHandshakeOpen_EncodeMsgpack(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func TestHandshakeOpen_DecodeMessage(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
challenge []byte
|
||||||
|
networkId string
|
||||||
|
handshake []byte
|
||||||
|
}
|
||||||
|
type args struct {
|
||||||
|
base64EncodedData string // Base64 encoded msgpack data
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args args
|
||||||
|
wantErr assert.ErrorAssertionFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Valid Handshake and NetworkID",
|
||||||
|
fields: fields{}, // Fields are now empty
|
||||||
|
args: args{
|
||||||
|
base64EncodedData: "xBNzYW1wbGVIYW5kc2hha2VEYXRhr3NhbXBsZU5ldHdvcmtJRA==",
|
||||||
|
},
|
||||||
|
wantErr: assert.NoError,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Valid Handshake and Empty NetworkID",
|
||||||
|
fields: fields{}, // Fields are now empty
|
||||||
|
args: args{
|
||||||
|
base64EncodedData: "xBNzYW1wbGVIYW5kc2hha2VEYXRh",
|
||||||
|
},
|
||||||
|
wantErr: assert.NoError,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
h := &HandshakeOpen{}
|
||||||
|
|
||||||
|
decodedData, _ := base64.StdEncoding.DecodeString(tt.args.base64EncodedData)
|
||||||
|
reader := bytes.NewReader(decodedData)
|
||||||
|
dec := msgpack.NewDecoder(reader)
|
||||||
|
|
||||||
|
tt.wantErr(t, h.DecodeMessage(dec), fmt.Sprintf("DecodeMessage(%v)", tt.args.base64EncodedData))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue