@@ -10,7 +10,6 @@ import (
10
10
"github.com/stretchr/testify/mock"
11
11
12
12
"github.com/aws/aws-sdk-go/aws"
13
- "github.com/aws/aws-sdk-go/aws/awserr"
14
13
"github.com/r3labs/diff/v2"
15
14
awstest "github.com/snyk/driftctl/test/aws"
16
15
"github.com/stretchr/testify/assert"
@@ -23,10 +22,10 @@ func Test_s3ControlRepository_DescribeAccountPublicAccessBlock(t *testing.T) {
23
22
name string
24
23
mocks func (client * awstest.MockFakeS3Control )
25
24
want * s3control.PublicAccessBlockConfiguration
26
- wantErr error
25
+ wantErr bool
27
26
}{
28
27
{
29
- name : "describe account public accessblock " ,
28
+ name : "describe account public access block " ,
30
29
mocks : func (client * awstest.MockFakeS3Control ) {
31
30
client .On ("GetPublicAccessBlock" , mock .Anything ).Return (
32
31
& s3control.GetPublicAccessBlockOutput {
@@ -48,15 +47,29 @@ func Test_s3ControlRepository_DescribeAccountPublicAccessBlock(t *testing.T) {
48
47
},
49
48
},
50
49
{
51
- name : "Error detting account public accessblock " ,
50
+ name : "Error getting account public access block " ,
52
51
mocks : func (client * awstest.MockFakeS3Control ) {
52
+ fakeRequestFailure := & awstest.MockFakeRequestFailure {}
53
+ fakeRequestFailure .On ("Code" ).Return ("FakeErrorCode" )
53
54
client .On ("GetPublicAccessBlock" , mock .Anything ).Return (
54
55
nil ,
55
- awserr . NewRequestFailure ( nil , 403 , "" ) ,
56
+ fakeRequestFailure ,
56
57
).Once ()
57
58
},
58
59
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 ,
60
73
},
61
74
}
62
75
for _ , tt := range tests {
@@ -69,9 +82,9 @@ func Test_s3ControlRepository_DescribeAccountPublicAccessBlock(t *testing.T) {
69
82
r := NewS3ControlRepository (& factory , store )
70
83
got , err := r .DescribeAccountPublicAccessBlock (accountID )
71
84
factory .AssertExpectations (t )
72
- assert .Equal (t , tt .wantErr , err )
85
+ assert .Equal (t , tt .wantErr , err != nil )
73
86
74
- if err == nil {
87
+ if err == nil && got != nil {
75
88
// Check that results were cached
76
89
cachedData , err := r .DescribeAccountPublicAccessBlock (accountID )
77
90
assert .NoError (t , err )
0 commit comments