Skip to content

Commit

Permalink
Use new config style for mockery (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Jan 12, 2024
1 parent afea478 commit f89a234
Show file tree
Hide file tree
Showing 262 changed files with 11,566 additions and 3,014 deletions.
25 changes: 25 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
with-expecter: true
inpackage: True
dir: "{{.InterfaceDir}}"
mockname: "mock{{.InterfaceName|firstUpper}}"
outpkg: "{{.PackageName}}"
filename: "mock_{{.InterfaceName}}_test.go"
all: true
packages:
github.com/ministryofjustice/opg-modernising-lpa/cmd/event-received:
github.com/ministryofjustice/opg-modernising-lpa/internal/app:
github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo:
github.com/ministryofjustice/opg-modernising-lpa/internal/event:
github.com/ministryofjustice/opg-modernising-lpa/internal/lambda:
github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore:
github.com/ministryofjustice/opg-modernising-lpa/internal/notify:
github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin:
github.com/ministryofjustice/opg-modernising-lpa/internal/page/attorney:
github.com/ministryofjustice/opg-modernising-lpa/internal/page/certificateprovider:
github.com/ministryofjustice/opg-modernising-lpa/internal/page/donor:
github.com/ministryofjustice/opg-modernising-lpa/internal/page:
github.com/ministryofjustice/opg-modernising-lpa/internal/place:
github.com/ministryofjustice/opg-modernising-lpa/internal/s3:
github.com/ministryofjustice/opg-modernising-lpa/internal/secrets:
github.com/ministryofjustice/opg-modernising-lpa/internal/uid:
github.com/ministryofjustice/opg-modernising-lpa/internal/validation:
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ go-test: ##@testing Runs full go test suite
go test ./... -race -covermode=atomic -coverprofile=coverage.out

go-generate: ##@testing Runs go generate
mockery
go generate ./...

update-event-schemas: ##@testing Gets the latest event schemas from OPG event catalog that we have tests for
Expand Down
68 changes: 34 additions & 34 deletions cmd/event-received/cloud_watch_event_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestHandleUidRequested(t *testing.T) {
}

uidClient := newMockUidClient(t)
uidClient.
On("CreateCase", ctx, &uid.CreateCaseRequestBody{
uidClient.EXPECT().
CreateCase(ctx, &uid.CreateCaseRequestBody{
Type: "hw",
Donor: uid.DonorDetails{
Name: "a donor",
Expand All @@ -44,8 +44,8 @@ func TestHandleUidRequested(t *testing.T) {
Return("M-1111-2222-3333", nil)

uidStore := newMockUidStore(t)
uidStore.
On("Set", ctx, "an-id", "donor-id", "M-1111-2222-3333").
uidStore.EXPECT().
Set(ctx, "an-id", "donor-id", "M-1111-2222-3333").
Return(nil)

err := handleUidRequested(ctx, uidStore, uidClient, event)
Expand All @@ -59,8 +59,8 @@ func TestHandleUidRequestedWhenUidClientErrors(t *testing.T) {
}

uidClient := newMockUidClient(t)
uidClient.
On("CreateCase", ctx, mock.Anything).
uidClient.EXPECT().
CreateCase(ctx, mock.Anything).
Return("", expectedError)

err := handleUidRequested(ctx, nil, uidClient, event)
Expand All @@ -74,13 +74,13 @@ func TestHandleUidRequestedWhenUidStoreErrors(t *testing.T) {
}

uidClient := newMockUidClient(t)
uidClient.
On("CreateCase", ctx, mock.Anything).
uidClient.EXPECT().
CreateCase(ctx, mock.Anything).
Return("M-1111-2222-3333", nil)

uidStore := newMockUidStore(t)
uidStore.
On("Set", ctx, "an-id", "donor-id", "M-1111-2222-3333").
uidStore.EXPECT().
Set(ctx, "an-id", "donor-id", "M-1111-2222-3333").
Return(expectedError)

err := handleUidRequested(ctx, uidStore, uidClient, event)
Expand All @@ -101,8 +101,8 @@ func TestHandleEvidenceReceived(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, map[string]string{
client.EXPECT().
Put(ctx, map[string]string{
"PK": "LPA#123",
"SK": "#EVIDENCE_RECEIVED",
}).
Expand All @@ -119,8 +119,8 @@ func TestHandleEvidenceReceivedWhenClientGetError(t *testing.T) {
}

client := newMockDynamodbClient(t)
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
client.EXPECT().
OneByUID(ctx, "M-1111-2222-3333", mock.Anything).
Return(expectedError)

err := handleEvidenceReceived(ctx, client, event)
Expand Down Expand Up @@ -160,8 +160,8 @@ func TestHandleEvidenceReceivedWhenClientPutError(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, map[string]string{
client.EXPECT().
Put(ctx, map[string]string{
"PK": "LPA#123",
"SK": "#EVIDENCE_RECEIVED",
}).
Expand Down Expand Up @@ -194,13 +194,13 @@ func TestHandleFeeApproved(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
client.EXPECT().
Put(ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(nil)

shareCodeSender := newMockShareCodeSender(t)
shareCodeSender.
On("SendCertificateProviderPrompt", ctx, page.AppData{}, &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
shareCodeSender.EXPECT().
SendCertificateProviderPrompt(ctx, page.AppData{}, &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(nil)

err := handleFeeApproved(ctx, client, event, shareCodeSender, page.AppData{}, func() time.Time { return now })
Expand Down Expand Up @@ -230,8 +230,8 @@ func TestHandleFeeApprovedWhenDynamoClientPutError(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
client.EXPECT().
Put(ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(expectedError)

err := handleFeeApproved(ctx, client, event, nil, page.AppData{}, func() time.Time { return now })
Expand Down Expand Up @@ -261,13 +261,13 @@ func TestHandleFeeApprovedWhenShareCodeSenderError(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
client.EXPECT().
Put(ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(nil)

shareCodeSender := newMockShareCodeSender(t)
shareCodeSender.
On("SendCertificateProviderPrompt", ctx, page.AppData{}, &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
shareCodeSender.EXPECT().
SendCertificateProviderPrompt(ctx, page.AppData{}, &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(expectedError)

err := handleFeeApproved(ctx, client, event, shareCodeSender, page.AppData{}, func() time.Time { return now })
Expand Down Expand Up @@ -297,8 +297,8 @@ func TestHandleMoreEvidenceRequired(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}).
client.EXPECT().
Put(ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}).
Return(nil)

err := handleMoreEvidenceRequired(ctx, client, event, func() time.Time { return now })
Expand Down Expand Up @@ -328,8 +328,8 @@ func TestHandleMoreEvidenceRequiredWhenPutError(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}).
client.EXPECT().
Put(ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}).
Return(expectedError)

err := handleMoreEvidenceRequired(ctx, client, event, func() time.Time { return now })
Expand Down Expand Up @@ -359,8 +359,8 @@ func TestHandleFeeDenied(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}).
client.EXPECT().
Put(ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}).
Return(nil)

err := handleFeeDenied(ctx, client, event, func() time.Time { return now })
Expand Down Expand Up @@ -390,8 +390,8 @@ func TestHandleFeeDeniedWhenPutError(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}).
client.EXPECT().
Put(ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}).
Return(expectedError)

err := handleFeeDenied(ctx, client, event, func() time.Time { return now })
Expand Down
36 changes: 18 additions & 18 deletions cmd/event-received/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestHandleObjectTagsAdded(t *testing.T) {
}

s3Client := newMockS3Client(t)
s3Client.
On("GetObjectTags", ctx, "M-1111-2222-3333/evidence/a-uid").
s3Client.EXPECT().
GetObjectTags(ctx, "M-1111-2222-3333/evidence/a-uid").
Return([]types.Tag{
{Key: aws.String("virus-scan-status"), Value: aws.String(scanResult)},
}, nil)
Expand All @@ -54,8 +54,8 @@ func TestHandleObjectTagsAdded(t *testing.T) {
})

documentStore := newMockDocumentStore(t)
documentStore.
On("UpdateScanResults", ctx, "123", "M-1111-2222-3333/evidence/a-uid", hasVirus).
documentStore.EXPECT().
UpdateScanResults(ctx, "123", "M-1111-2222-3333/evidence/a-uid", hasVirus).
Return(nil)

err := handleObjectTagsAdded(ctx, dynamoClient, event.S3Event, s3Client, documentStore)
Expand All @@ -72,8 +72,8 @@ func TestHandleObjectTagsAddedWhenScannedTagMissing(t *testing.T) {
}

s3Client := newMockS3Client(t)
s3Client.
On("GetObjectTags", ctx, "M-1111-2222-3333/evidence/a-uid").
s3Client.EXPECT().
GetObjectTags(ctx, "M-1111-2222-3333/evidence/a-uid").
Return([]types.Tag{
{Key: aws.String("not-virus-scan-status"), Value: aws.String("ok")},
}, nil)
Expand Down Expand Up @@ -101,8 +101,8 @@ func TestHandleObjectTagsAddedWhenS3ClientGetObjectTagsError(t *testing.T) {
}

s3Client := newMockS3Client(t)
s3Client.
On("GetObjectTags", ctx, "M-1111-2222-3333/evidence/a-uid").
s3Client.EXPECT().
GetObjectTags(ctx, "M-1111-2222-3333/evidence/a-uid").
Return([]types.Tag{}, expectedError)

err := handleObjectTagsAdded(ctx, nil, event.S3Event, s3Client, nil)
Expand All @@ -117,8 +117,8 @@ func TestHandleObjectTagsAddedWhenDynamoClientOneByUIDError(t *testing.T) {
}

s3Client := newMockS3Client(t)
s3Client.
On("GetObjectTags", ctx, "M-1111-2222-3333/evidence/a-uid").
s3Client.EXPECT().
GetObjectTags(ctx, "M-1111-2222-3333/evidence/a-uid").
Return([]types.Tag{
{Key: aws.String("virus-scan-status"), Value: aws.String("ok")},
}, nil)
Expand Down Expand Up @@ -151,8 +151,8 @@ func TestHandleObjectTagsAddedWhenDocumentStoreUpdateScanResultsError(t *testing
}

s3Client := newMockS3Client(t)
s3Client.
On("GetObjectTags", ctx, "M-1111-2222-3333/evidence/a-uid").
s3Client.EXPECT().
GetObjectTags(ctx, "M-1111-2222-3333/evidence/a-uid").
Return([]types.Tag{
{Key: aws.String("virus-scan-status"), Value: aws.String("ok")},
}, nil)
Expand All @@ -174,8 +174,8 @@ func TestHandleObjectTagsAddedWhenDocumentStoreUpdateScanResultsError(t *testing
})

documentStore := newMockDocumentStore(t)
documentStore.
On("UpdateScanResults", ctx, "123", "M-1111-2222-3333/evidence/a-uid", false).
documentStore.EXPECT().
UpdateScanResults(ctx, "123", "M-1111-2222-3333/evidence/a-uid", false).
Return(expectedError)

err := handleObjectTagsAdded(ctx, dynamoClient, event.S3Event, s3Client, documentStore)
Expand Down Expand Up @@ -209,8 +209,8 @@ func TestGetLpaByUID(t *testing.T) {

func TestGetLpaByUIDWhenClientOneByUidError(t *testing.T) {
client := newMockDynamodbClient(t)
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
client.EXPECT().
OneByUID(ctx, "M-1111-2222-3333", mock.Anything).
Return(expectedError)

lpa, err := getDonorByLpaUID(ctx, client, "M-1111-2222-3333")
Expand Down Expand Up @@ -244,8 +244,8 @@ func TestGetLpaByUIDWhenClientOneError(t *testing.T) {
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
client.EXPECT().
One(ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(expectedError)

lpa, err := getDonorByLpaUID(ctx, client, "M-1111-2222-3333")
Expand Down
6 changes: 0 additions & 6 deletions cmd/event-received/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,29 @@ type uidEvent struct {
UID string `json:"uid"`
}

//go:generate mockery --testonly --inpackage --name dynamodbClient --structname mockDynamodbClient
type dynamodbClient interface {
One(ctx context.Context, pk, sk string, v interface{}) error
OneByUID(ctx context.Context, uid string, v interface{}) error
Put(ctx context.Context, v interface{}) error
Update(ctx context.Context, pk, sk string, values map[string]dynamodbtypes.AttributeValue, expression string) error
}

//go:generate mockery --testonly --inpackage --name s3Client --structname mockS3Client
type s3Client interface {
GetObjectTags(ctx context.Context, key string) ([]types.Tag, error)
}

//go:generate mockery --testonly --inpackage --name shareCodeSender --structname mockShareCodeSender
type shareCodeSender interface {
SendCertificateProviderPrompt(context.Context, page.AppData, *actor.DonorProvidedDetails) error
}

//go:generate mockery --testonly --inpackage --name DocumentStore --structname mockDocumentStore
type DocumentStore interface {
UpdateScanResults(ctx context.Context, lpaID, objectKey string, virusDetected bool) error
}

//go:generate mockery --testonly --inpackage --name UidStore --structname mockUidStore
type UidStore interface {
Set(ctx context.Context, lpaID, sessionID, uid string) error
}

//go:generate mockery --testonly --inpackage --name UidClient --structname mockUidClient
type UidClient interface {
CreateCase(context.Context, *uid.CreateCaseRequestBody) (string, error)
}
Expand Down
39 changes: 39 additions & 0 deletions cmd/event-received/mock_DocumentStore_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f89a234

Please sign in to comment.