forked from ekristen/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam-user-mfa-device_mock_test.go
76 lines (61 loc) · 1.66 KB
/
iam-user-mfa-device_mock_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package resources
import (
"context"
"testing"
"time"
"github.com/golang/mock/gomock"
"github.com/gotidy/ptr"
"github.com/stretchr/testify/assert"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/ekristen/aws-nuke/v3/mocks/mock_iamiface"
)
func Test_Mock_IAMUserMFADevice_List(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockIAM := mock_iamiface.NewMockIAMAPI(ctrl)
mockIAM.EXPECT().ListUsersPages(gomock.Any(), gomock.Any()).
Do(func(_ *iam.ListUsersInput, fn func(page *iam.ListUsersOutput, lastPage bool) bool) {
fn(&iam.ListUsersOutput{
Users: []*iam.User{
{
UserName: ptr.String("foo"),
},
},
}, true)
}).Return(nil)
mockIAM.EXPECT().ListMFADevices(&iam.ListMFADevicesInput{
UserName: ptr.String("foo"),
}).Return(&iam.ListMFADevicesOutput{
MFADevices: []*iam.MFADevice{
{
UserName: ptr.String("foo"),
SerialNumber: ptr.String("bar"),
EnableDate: ptr.Time(time.Now()),
},
},
}, nil)
lister := IAMUserMFADeviceLister{
mockSvc: mockIAM,
}
resources, err := lister.List(context.TODO(), testListerOpts)
a.NoError(err)
a.Len(resources, 1)
}
func Test_Mock_IAMUserMFADevice_Remove(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockIAM := mock_iamiface.NewMockIAMAPI(ctrl)
mockIAM.EXPECT().DeactivateMFADevice(&iam.DeactivateMFADeviceInput{
UserName: ptr.String("foo"),
SerialNumber: ptr.String("bar"),
})
resource := &IAMUserMFADevice{
svc: mockIAM,
UserName: ptr.String("foo"),
SerialNumber: ptr.String("bar"),
}
err := resource.Remove(context.TODO())
a.NoError(err)
}