@@ -10,6 +10,7 @@ import (
10
10
11
11
"github.com/stretchr/testify/assert"
12
12
13
+ mocks "github.com/chainifynet/aws-encryption-sdk-go/mocks/github.com/chainifynet/aws-encryption-sdk-go/pkg/model/format"
13
14
"github.com/chainifynet/aws-encryption-sdk-go/pkg/logger"
14
15
"github.com/chainifynet/aws-encryption-sdk-go/pkg/model/format"
15
16
"github.com/chainifynet/aws-encryption-sdk-go/pkg/suite"
@@ -324,3 +325,35 @@ func Test_deserializeHeader(t *testing.T) {
324
325
})
325
326
}
326
327
}
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