Skip to content

Commit

Permalink
test: Mocks the EncryptionAtRestUsingCustomerKeyManagementApi instead…
Browse files Browse the repository at this point in the history
… of using custom service (#2043)
  • Loading branch information
EspenAlbert committed Mar 19, 2024
1 parent 74687c3 commit d423a46
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 144 deletions.
4 changes: 1 addition & 3 deletions .mockery.yaml
Expand Up @@ -9,10 +9,8 @@ packages:
go.mongodb.org/atlas-sdk/v20231115007/admin:
interfaces:
AtlasSearchApi:
EncryptionAtRestUsingCustomerKeyManagementApi:

github.com/mongodb/terraform-provider-mongodbatlas/internal/service/encryptionatrest:
interfaces:
EarService:

github.com/mongodb/terraform-provider-mongodbatlas/internal/service/project:
interfaces:
Expand Down
Expand Up @@ -228,7 +228,7 @@ func (r *encryptionAtRestRS) Create(ctx context.Context, req resource.CreateRequ
stateConf := &retry.StateChangeConf{
Pending: []string{retrystrategy.RetryStrategyPendingState},
Target: []string{retrystrategy.RetryStrategyCompletedState, retrystrategy.RetryStrategyErrorState},
Refresh: ResourceMongoDBAtlasEncryptionAtRestCreateRefreshFunc(ctx, projectID, ServiceFromClient(connV2), encryptionAtRestReq),
Refresh: ResourceMongoDBAtlasEncryptionAtRestCreateRefreshFunc(ctx, projectID, connV2.EncryptionAtRestUsingCustomerKeyManagementApi, encryptionAtRestReq),
Timeout: 1 * time.Minute,
MinTimeout: 1 * time.Second,
Delay: 0,
Expand All @@ -252,9 +252,9 @@ func (r *encryptionAtRestRS) Create(ctx context.Context, req resource.CreateRequ
}
}

func ResourceMongoDBAtlasEncryptionAtRestCreateRefreshFunc(ctx context.Context, projectID string, client EarService, encryptionAtRestReq *admin.EncryptionAtRest) retry.StateRefreshFunc {
func ResourceMongoDBAtlasEncryptionAtRestCreateRefreshFunc(ctx context.Context, projectID string, client admin.EncryptionAtRestUsingCustomerKeyManagementApi, encryptionAtRestReq *admin.EncryptionAtRest) retry.StateRefreshFunc {
return func() (any, string, error) {
encryptionResp, _, err := client.UpdateEncryptionAtRest(ctx, projectID, encryptionAtRestReq)
encryptionResp, _, err := client.UpdateEncryptionAtRest(ctx, projectID, encryptionAtRestReq).Execute()
if err != nil {
if errors.Is(err, errors.New("CANNOT_ASSUME_ROLE")) ||
errors.Is(err, errors.New("INVALID_AWS_CREDENTIALS")) ||
Expand Down
Expand Up @@ -546,11 +546,12 @@ func TestResourceMongoDBAtlasEncryptionAtRestCreateRefreshFunc(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
testObject := mocksvc.NewEarService(t)
m := mocksvc.NewEncryptionAtRestUsingCustomerKeyManagementApi(t)

testObject.On("UpdateEncryptionAtRest", mock.Anything, mock.Anything, mock.Anything).Return(tc.mockResponse, nil, tc.mockError)
m.EXPECT().UpdateEncryptionAtRest(mock.Anything, mock.Anything, mock.Anything).Return(admin.UpdateEncryptionAtRestApiRequest{ApiService: m})
m.EXPECT().UpdateEncryptionAtRestExecute(mock.Anything).Return(tc.mockResponse, nil, tc.mockError).Once()

response, strategy, err := encryptionatrest.ResourceMongoDBAtlasEncryptionAtRestCreateRefreshFunc(context.Background(), projectID, testObject, &admin.EncryptionAtRest{})()
response, strategy, err := encryptionatrest.ResourceMongoDBAtlasEncryptionAtRestCreateRefreshFunc(context.Background(), projectID, m, &admin.EncryptionAtRest{})()

if (err != nil) != tc.expectedError {
t.Errorf("Case %s: Received unexpected error: %v", tc.name, err)
Expand Down
26 changes: 0 additions & 26 deletions internal/service/encryptionatrest/service_encryption_at_rest.go

This file was deleted.

109 changes: 0 additions & 109 deletions internal/testutil/mocksvc/ear_service.go

This file was deleted.

0 comments on commit d423a46

Please sign in to comment.