Skip to content

Commit f3fb2f6

Browse files
committed
test(serialization): writeAAD test
1 parent 9ffc5a7 commit f3fb2f6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pkg/serialization/messageheader_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/stretchr/testify/assert"
1212

13+
mocks "github.com/chainifynet/aws-encryption-sdk-go/mocks/github.com/chainifynet/aws-encryption-sdk-go/pkg/model/format"
1314
"github.com/chainifynet/aws-encryption-sdk-go/pkg/logger"
1415
"github.com/chainifynet/aws-encryption-sdk-go/pkg/model/format"
1516
"github.com/chainifynet/aws-encryption-sdk-go/pkg/suite"
@@ -324,3 +325,35 @@ func Test_deserializeHeader(t *testing.T) {
324325
})
325326
}
326327
}
328+
329+
func TestWriteAAD(t *testing.T) {
330+
tests := []struct {
331+
name string
332+
aadLen int
333+
mockBytes []byte
334+
want []byte
335+
wantBytesCall bool
336+
wantMock bool
337+
}{
338+
{"Empty Buffer and Blank AAD", 0, nil, []byte{}, false, false},
339+
{"Empty Buffer and AADLen not zero", 5, nil, []byte{}, true, true},
340+
{"Filled Buffer and AADLen zero", 0, []byte("mockaad"), []byte{}, false, true},
341+
{"Filled Buffer and AADLen not zero", 5, []byte("mockaad"), []byte("mockaad"), true, true},
342+
}
343+
344+
for _, tt := range tests {
345+
t.Run(tt.name, func(t *testing.T) {
346+
var mockData *mocks.MockMessageAAD
347+
if tt.wantMock {
348+
mockData = mocks.NewMockMessageAAD(t)
349+
if tt.wantBytesCall {
350+
mockData.EXPECT().Bytes().Return(tt.mockBytes).Once()
351+
}
352+
}
353+
354+
buf := &[]byte{}
355+
writeAAD(buf, tt.aadLen, mockData)
356+
assert.Equal(t, tt.want, *buf, "Buffers should be equal")
357+
})
358+
}
359+
}

0 commit comments

Comments
 (0)