2020-10-25 15:36:34 +00:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-10-25 21:44:56 +00:00
|
|
|
"mpbl3p/mocks"
|
2020-10-25 15:36:34 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestPacket_Marshal(t *testing.T) {
|
|
|
|
testContent := []byte("A test string is the content of this packet.")
|
|
|
|
testPacket := NewPacket(testContent)
|
2020-10-25 21:44:56 +00:00
|
|
|
testMac := mocks.AlmostUselessMac{}
|
2020-10-25 15:36:34 +00:00
|
|
|
|
|
|
|
t.Run("Length", func(t *testing.T) {
|
|
|
|
marshalled := testPacket.Marshal(testMac)
|
|
|
|
|
|
|
|
assert.Len(t, marshalled, len(testContent)+8+4)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnmarshalPacket(t *testing.T) {
|
|
|
|
testContent := []byte("A test string is the content of this packet.")
|
|
|
|
testPacket := NewPacket(testContent)
|
2020-10-25 21:44:56 +00:00
|
|
|
testMac := mocks.AlmostUselessMac{}
|
2020-10-25 15:36:34 +00:00
|
|
|
testMarshalled := testPacket.Marshal(testMac)
|
|
|
|
|
|
|
|
t.Run("Success", func(t *testing.T) {
|
|
|
|
content, err := UnmarshalPacket(testMarshalled, testMac)
|
|
|
|
|
|
|
|
require.Nil(t, err)
|
|
|
|
assert.Equal(t, testContent, content.Raw())
|
|
|
|
})
|
|
|
|
}
|