forked from ekristen/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcognito-userpool_mock_test.go
133 lines (105 loc) · 3.6 KB
/
cognito-userpool_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package resources
import (
"context"
"testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
"github.com/ekristen/libnuke/pkg/settings"
"github.com/ekristen/aws-nuke/v3/mocks/mock_cognitoidentityprovideriface"
)
func Test_Mock_CognitoUserPool_List(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockSvc := mock_cognitoidentityprovideriface.NewMockCognitoIdentityProviderAPI(ctrl)
lister := &CognitoUserPoolLister{
cognitoService: mockSvc,
}
mockSvc.EXPECT().ListUserPools(&cognitoidentityprovider.ListUserPoolsInput{
MaxResults: aws.Int64(50),
}).Return(&cognitoidentityprovider.ListUserPoolsOutput{
UserPools: []*cognitoidentityprovider.UserPoolDescriptionType{
{
Id: aws.String("test-pool-id"),
Name: aws.String("test-pool"),
},
},
}, nil)
mockSvc.EXPECT().ListTagsForResource(&cognitoidentityprovider.ListTagsForResourceInput{
ResourceArn: aws.String("arn:aws:cognito-idp:us-east-2:012345678901:userpool/test-pool-id"),
}).Return(&cognitoidentityprovider.ListTagsForResourceOutput{
Tags: map[string]*string{
"test-key": aws.String("test-value"),
},
}, nil)
resources, err := lister.List(context.TODO(), testListerOpts)
a.NoError(err)
a.Len(resources, 1)
}
func Test_Mock_CognitoUserPool_Remove(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockSvc := mock_cognitoidentityprovideriface.NewMockCognitoIdentityProviderAPI(ctrl)
mockSvc.EXPECT().DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{
UserPoolId: aws.String("test-pool-id"),
}).Return(&cognitoidentityprovider.DeleteUserPoolOutput{}, nil)
s := &settings.Setting{}
s.Set("DisableDeletionProtection", false)
pool := &CognitoUserPool{
svc: mockSvc,
settings: s,
Name: aws.String("test-pool"),
ID: aws.String("test-pool-id"),
Tags: map[string]*string{
"test-key": aws.String("test-value"),
},
}
err := pool.Remove(context.TODO())
a.NoError(err)
}
func Test_Mock_CognitoUserPool_Remove_DeletionProtection(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockSvc := mock_cognitoidentityprovideriface.NewMockCognitoIdentityProviderAPI(ctrl)
mockSvc.EXPECT().UpdateUserPool(&cognitoidentityprovider.UpdateUserPoolInput{
UserPoolId: aws.String("test-pool-id"),
DeletionProtection: aws.String("INACTIVE"),
}).Return(&cognitoidentityprovider.UpdateUserPoolOutput{}, nil)
mockSvc.EXPECT().DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{
UserPoolId: aws.String("test-pool-id"),
}).Return(&cognitoidentityprovider.DeleteUserPoolOutput{}, nil)
s := &settings.Setting{}
s.Set("DisableDeletionProtection", true)
pool := &CognitoUserPool{
svc: mockSvc,
settings: s,
Name: aws.String("test-pool"),
ID: aws.String("test-pool-id"),
Tags: map[string]*string{
"test-key": aws.String("test-value"),
},
}
err := pool.Remove(context.TODO())
a.NoError(err)
}
func Test_Mock_CognitoUserPool_Properties(t *testing.T) {
a := assert.New(t)
s := &settings.Setting{}
s.Set("DisableDeletionProtection", false)
pool := &CognitoUserPool{
settings: s,
Name: aws.String("test-pool"),
ID: aws.String("test-pool-id"),
Tags: map[string]*string{
"test-key": aws.String("test-value"),
},
}
a.Equal("test-pool", pool.Properties().Get("Name"))
a.Equal("test-pool-id", pool.Properties().Get("ID"))
a.Equal("test-value", pool.Properties().Get("tag:test-key"))
a.Equal("test-pool", pool.String())
}