dissertation-2-code/proxy/packet_test.go

35 lines
866 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) {
2020-11-26 18:55:29 +00:00
p, err := UnmarshalSimplePacket(testMarshalled, testMac)
2020-10-25 15:36:34 +00:00
require.Nil(t, err)
2020-11-26 18:55:29 +00:00
assert.Len(t, p.Marshal(), len(testContent))
2020-10-25 15:36:34 +00:00
})
}