dissertation-2-code/proxy/packet_test.go

35 lines
856 B
Go
Raw Normal View History

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("Length", func(t *testing.T) {
p, err := UnmarshalPacket(testMarshalled, testMac)
2020-10-25 15:36:34 +00:00
require.Nil(t, err)
assert.Len(t, p.Raw(), len(testContent))
2020-10-25 15:36:34 +00:00
})
}