@@ -10,7 +10,6 @@ import (
1010 "github.com/stretchr/testify/mock"
1111
1212 "github.com/aws/aws-sdk-go/aws"
13- "github.com/aws/aws-sdk-go/aws/awserr"
1413 "github.com/r3labs/diff/v2"
1514 awstest "github.com/snyk/driftctl/test/aws"
1615 "github.com/stretchr/testify/assert"
@@ -23,10 +22,10 @@ func Test_s3ControlRepository_DescribeAccountPublicAccessBlock(t *testing.T) {
2322 name string
2423 mocks func (client * awstest.MockFakeS3Control )
2524 want * s3control.PublicAccessBlockConfiguration
26- wantErr error
25+ wantErr bool
2726 }{
2827 {
29- name : "describe account public accessblock " ,
28+ name : "describe account public access block " ,
3029 mocks : func (client * awstest.MockFakeS3Control ) {
3130 client .On ("GetPublicAccessBlock" , mock .Anything ).Return (
3231 & s3control.GetPublicAccessBlockOutput {
@@ -48,15 +47,29 @@ func Test_s3ControlRepository_DescribeAccountPublicAccessBlock(t *testing.T) {
4847 },
4948 },
5049 {
51- name : "Error detting account public accessblock " ,
50+ name : "Error getting account public access block " ,
5251 mocks : func (client * awstest.MockFakeS3Control ) {
52+ fakeRequestFailure := & awstest.MockFakeRequestFailure {}
53+ fakeRequestFailure .On ("Code" ).Return ("FakeErrorCode" )
5354 client .On ("GetPublicAccessBlock" , mock .Anything ).Return (
5455 nil ,
55- awserr . NewRequestFailure ( nil , 403 , "" ) ,
56+ fakeRequestFailure ,
5657 ).Once ()
5758 },
5859 want : nil ,
59- wantErr : awserr .NewRequestFailure (nil , 403 , "" ),
60+ wantErr : true ,
61+ },
62+ {
63+ name : "Error no account public access block" ,
64+ mocks : func (client * awstest.MockFakeS3Control ) {
65+ fakeRequestFailure := & awstest.MockFakeRequestFailure {}
66+ fakeRequestFailure .On ("Code" ).Return ("NoSuchPublicAccessBlockConfiguration" )
67+ client .On ("GetPublicAccessBlock" , mock .Anything ).Return (
68+ nil ,
69+ fakeRequestFailure ,
70+ ).Once ()
71+ },
72+ want : nil ,
6073 },
6174 }
6275 for _ , tt := range tests {
@@ -69,9 +82,9 @@ func Test_s3ControlRepository_DescribeAccountPublicAccessBlock(t *testing.T) {
6982 r := NewS3ControlRepository (& factory , store )
7083 got , err := r .DescribeAccountPublicAccessBlock (accountID )
7184 factory .AssertExpectations (t )
72- assert .Equal (t , tt .wantErr , err )
85+ assert .Equal (t , tt .wantErr , err != nil )
7386
74- if err == nil {
87+ if err == nil && got != nil {
7588 // Check that results were cached
7689 cachedData , err := r .DescribeAccountPublicAccessBlock (accountID )
7790 assert .NoError (t , err )
0 commit comments