dissertation-2-code/proxy/packet_test.go
Jake Hillion b9e81d8145
All checks were successful
continuous-integration/drone/push Build is passing
tcp receiver tests and tun improvements
2020-10-26 11:07:27 +00:00

35 lines
856 B
Go

package proxy
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"mpbl3p/mocks"
"testing"
)
func TestPacket_Marshal(t *testing.T) {
testContent := []byte("A test string is the content of this packet.")
testPacket := NewPacket(testContent)
testMac := mocks.AlmostUselessMac{}
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)
testMac := mocks.AlmostUselessMac{}
testMarshalled := testPacket.Marshal(testMac)
t.Run("Length", func(t *testing.T) {
p, err := UnmarshalPacket(testMarshalled, testMac)
require.Nil(t, err)
assert.Len(t, p.Raw(), len(testContent))
})
}