Skip to content

Commit

Permalink
Change return from nil to pointer struct
Browse files Browse the repository at this point in the history
- Instead of returning nil the functions now return a pointer struct
  • Loading branch information
Diogenesoftoronto committed Mar 12, 2024
1 parent d6106f0 commit 7171ffe
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions internal/am/delete_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (a *DeleteTransferActivity) Execute(ctx context.Context, params *DeleteTran

err := a.client.Delete(ctx, params.Destination)
if err != nil {
return nil, fmt.Errorf("delete transfer: path: %q: %v", params.Destination, err)
return &DeleteTransferActivityResult{}, fmt.Errorf("delete transfer: path: %q: %v", params.Destination, err)
}

return nil, nil
return &DeleteTransferActivityResult{}, nil
}
16 changes: 8 additions & 8 deletions internal/storage/activities/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,40 @@ func NewCopyToPermanentLocationActivity(storagesvc storage.Service) *CopyToPerma
func (a *CopyToPermanentLocationActivity) Execute(ctx context.Context, params *storage.CopyToPermanentLocationActivityParams) (*CopyToPermanentLocationActivityResult, error) {

Check warning on line 20 in internal/storage/activities/copy.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/activities/copy.go#L20

Added line #L20 was not covered by tests
p, err := a.storagesvc.ReadPackage(ctx, params.AIPID)
if err != nil {
return nil, err
return &CopyToPermanentLocationActivityResult{}, err

Check warning on line 23 in internal/storage/activities/copy.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/activities/copy.go#L23

Added line #L23 was not covered by tests
}

reader, err := a.storagesvc.PackageReader(ctx, p)
if err != nil {
return nil, err
return &CopyToPermanentLocationActivityResult{}, err

Check warning on line 28 in internal/storage/activities/copy.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/activities/copy.go#L28

Added line #L28 was not covered by tests
}
defer reader.Close()

l, err := a.storagesvc.Location(ctx, params.LocationID)
if err != nil {
return nil, err
return &CopyToPermanentLocationActivityResult{}, err

Check warning on line 34 in internal/storage/activities/copy.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/activities/copy.go#L34

Added line #L34 was not covered by tests
}

bucket, err := l.OpenBucket(ctx)
if err != nil {
return nil, err
return &CopyToPermanentLocationActivityResult{}, err

Check warning on line 39 in internal/storage/activities/copy.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/activities/copy.go#L39

Added line #L39 was not covered by tests
}
defer bucket.Close()

writer, err := bucket.NewWriter(ctx, params.AIPID.String(), nil)
if err != nil {
return nil, err
return &CopyToPermanentLocationActivityResult{}, err

Check warning on line 45 in internal/storage/activities/copy.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/activities/copy.go#L45

Added line #L45 was not covered by tests
}

_, copyErr := io.Copy(writer, reader)
closeErr := writer.Close()

if copyErr != nil {
return nil, copyErr
return &CopyToPermanentLocationActivityResult{}, copyErr

Check warning on line 52 in internal/storage/activities/copy.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/activities/copy.go#L52

Added line #L52 was not covered by tests
}
if closeErr != nil {
return nil, closeErr
return &CopyToPermanentLocationActivityResult{}, closeErr

Check warning on line 55 in internal/storage/activities/copy.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/activities/copy.go#L55

Added line #L55 was not covered by tests
}

return nil, nil
return &CopyToPermanentLocationActivityResult{}, nil

Check warning on line 58 in internal/storage/activities/copy.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/activities/copy.go#L58

Added line #L58 was not covered by tests
}
10 changes: 5 additions & 5 deletions internal/workflow/activities/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (a *BundleActivity) Execute(ctx context.Context, params *BundleActivityPara
if params.TransferDir == "" {
params.TransferDir, err = os.MkdirTemp("", "*-enduro-transfer")
if err != nil {
return nil, err
return &BundleActivityResult{}, err

Check warning on line 75 in internal/workflow/activities/bundle.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/bundle.go#L75

Added line #L75 was not covered by tests
}
}

Expand All @@ -96,24 +96,24 @@ func (a *BundleActivity) Execute(ctx context.Context, params *BundleActivityPara
}
}
if err != nil {
return nil, temporal_tools.NewNonRetryableError(err)
return &BundleActivityResult{}, temporal_tools.NewNonRetryableError(err)

Check warning on line 99 in internal/workflow/activities/bundle.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/bundle.go#L99

Added line #L99 was not covered by tests
}

err = unbag(res.FullPath)
if err != nil {
return nil, temporal_tools.NewNonRetryableError(err)
return &BundleActivityResult{}, temporal_tools.NewNonRetryableError(err)

Check warning on line 104 in internal/workflow/activities/bundle.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/bundle.go#L104

Added line #L104 was not covered by tests
}

res.RelPath, err = filepath.Rel(params.TransferDir, res.FullPath)
if err != nil {
return nil, temporal_tools.NewNonRetryableError(fmt.Errorf(
return &BundleActivityResult{}, temporal_tools.NewNonRetryableError(fmt.Errorf(

Check warning on line 109 in internal/workflow/activities/bundle.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/bundle.go#L109

Added line #L109 was not covered by tests
"error calculating relative path to transfer (base=%q, target=%q): %v",
params.TransferDir, res.FullPath, err,
))
}

if err = setPermissions(res.FullPath); err != nil {
return nil, temporal_tools.NewNonRetryableError(
return &BundleActivityResult{}, temporal_tools.NewNonRetryableError(

Check warning on line 116 in internal/workflow/activities/bundle.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/bundle.go#L116

Added line #L116 was not covered by tests
fmt.Errorf("set permissions: %v", err),
)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/workflow/activities/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type CleanUpActivityResult struct{}

func (a *CleanUpActivity) Execute(ctx context.Context, params *CleanUpActivityParams) (*CleanUpActivityResult, error) {

Check warning on line 22 in internal/workflow/activities/cleanup.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/cleanup.go#L22

Added line #L22 was not covered by tests
if params == nil || params.FullPath == "" {
return nil, fmt.Errorf("error processing parameters: missing or empty")
return &CleanUpActivityResult{}, fmt.Errorf("error processing parameters: missing or empty")

Check warning on line 24 in internal/workflow/activities/cleanup.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/cleanup.go#L24

Added line #L24 was not covered by tests
}

if err := os.RemoveAll(params.FullPath); err != nil {
return nil, fmt.Errorf("error removing transfer directory: %v", err)
return &CleanUpActivityResult{}, fmt.Errorf("error removing transfer directory: %v", err)

Check warning on line 28 in internal/workflow/activities/cleanup.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/cleanup.go#L28

Added line #L28 was not covered by tests
}

return nil, nil
return &CleanUpActivityResult{}, nil

Check warning on line 31 in internal/workflow/activities/cleanup.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/cleanup.go#L31

Added line #L31 was not covered by tests
}
4 changes: 2 additions & 2 deletions internal/workflow/activities/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (a *DownloadActivity) Execute(ctx context.Context, params *DownloadActivity

destDir, err := os.MkdirTemp("", "enduro")
if err != nil {
return nil, temporal_tools.NewNonRetryableError(fmt.Errorf("make temp dir: %v", err))
return &DownloadActivityResult{}, temporal_tools.NewNonRetryableError(fmt.Errorf("make temp dir: %v", err))

Check warning on line 45 in internal/workflow/activities/download.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/download.go#L45

Added line #L45 was not covered by tests
}

dest := filepath.Clean(filepath.Join(destDir, params.Key))
if err := a.wsvc.Download(ctx, dest, params.WatcherName, params.Key); err != nil {
return nil, temporal_tools.NewNonRetryableError(fmt.Errorf("download: %v", err))
return &DownloadActivityResult{}, temporal_tools.NewNonRetryableError(fmt.Errorf("download: %v", err))
}

return &DownloadActivityResult{Path: dest}, nil
Expand Down
6 changes: 3 additions & 3 deletions internal/workflow/activities/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (a *MoveToPermanentStorageActivity) Execute(ctx context.Context, params *Mo
LocationID: params.LocationID,
})

return nil, err
return &MoveToPermanentStorageActivityResult{}, err

Check warning on line 40 in internal/workflow/activities/storage.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/storage.go#L40

Added line #L40 was not covered by tests
}

type PollMoveToPermanentStorageActivityParams struct {
Expand Down Expand Up @@ -109,7 +109,7 @@ func (a *PollMoveToPermanentStorageActivity) Execute(ctx context.Context, params
}

err := g.Run()
return nil, err
return &PollMoveToPermanentStorageActivityResult{}, err

Check warning on line 112 in internal/workflow/activities/storage.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/storage.go#L112

Added line #L112 was not covered by tests
}

type RejectPackageActivityParams struct {
Expand All @@ -136,5 +136,5 @@ func (a *RejectPackageActivity) Execute(ctx context.Context, params *RejectPacka
AipID: params.AIPID,
})

return nil, err
return &RejectPackageActivityResult{}, err

Check warning on line 139 in internal/workflow/activities/storage.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/storage.go#L139

Added line #L139 was not covered by tests
}
16 changes: 8 additions & 8 deletions internal/workflow/activities/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,43 @@ func (a *UploadActivity) Execute(ctx context.Context, params *UploadActivityPara
Name: params.Name,
})
if err != nil {
return nil, err
return &UploadActivityResult{}, err

Check warning on line 39 in internal/workflow/activities/upload.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/upload.go#L39

Added line #L39 was not covered by tests
}

// Upload to MinIO using the upload pre-signed URL.
{
f, err := os.Open(params.AIPPath)
if err != nil {
return nil, err
return &UploadActivityResult{}, err

Check warning on line 46 in internal/workflow/activities/upload.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/upload.go#L46

Added line #L46 was not covered by tests
}
defer f.Close() //#nosec G307 -- Errors returned by Close() here do not require specific handling.

uploadReq, err := http.NewRequestWithContext(ctx, http.MethodPut, res.URL, f)
if err != nil {
return nil, nil
return &UploadActivityResult{}, nil

Check warning on line 52 in internal/workflow/activities/upload.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/upload.go#L52

Added line #L52 was not covered by tests
}
fi, err := f.Stat()
if err != nil {
return nil, err
return &UploadActivityResult{}, err

Check warning on line 56 in internal/workflow/activities/upload.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/upload.go#L56

Added line #L56 was not covered by tests
}
uploadReq.ContentLength = fi.Size()
if err != nil {
return nil, err
return &UploadActivityResult{}, err

Check warning on line 60 in internal/workflow/activities/upload.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/upload.go#L60

Added line #L60 was not covered by tests
}

minioClient := &http.Client{}
resp, err := minioClient.Do(uploadReq)
if err != nil {
return nil, err
return &UploadActivityResult{}, err

Check warning on line 66 in internal/workflow/activities/upload.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/upload.go#L66

Added line #L66 was not covered by tests
}
if resp.StatusCode != http.StatusOK {
return nil, errors.New("unexpected status code returned")
return &UploadActivityResult{}, errors.New("unexpected status code returned")

Check warning on line 69 in internal/workflow/activities/upload.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/upload.go#L69

Added line #L69 was not covered by tests
}
}

childCtx, cancel = context.WithTimeout(ctx, time.Second*5)
defer cancel()
err = a.storageClient.Update(childCtx, &goastorage.UpdatePayload{AipID: params.AIPID})

return nil, err
return &UploadActivityResult{}, err
}
6 changes: 3 additions & 3 deletions internal/workflow/activities/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (a *zipActivity) Execute(ctx context.Context, params *ZipActivityParams) (*
)

if params.SourceDir == "" {
return nil, fmt.Errorf("%s: missing source dir", ZipActivityName)
return &ZipActivityResult{}, fmt.Errorf("%s: missing source dir", ZipActivityName)
}

dest := params.DestPath
Expand All @@ -51,7 +51,7 @@ func (a *zipActivity) Execute(ctx context.Context, params *ZipActivityParams) (*

w, err := os.Create(dest) // #nosec G304 -- trusted path
if err != nil {
return nil, fmt.Errorf("%s: create: %v", ZipActivityName, err)
return &ZipActivityResult{}, fmt.Errorf("%s: create: %v", ZipActivityName, err)
}
defer w.Close()

Expand Down Expand Up @@ -91,7 +91,7 @@ func (a *zipActivity) Execute(ctx context.Context, params *ZipActivityParams) (*
return nil
})
if err != nil {
return nil, fmt.Errorf("%s: add files: %v", ZipActivityName, err)
return &ZipActivityResult{}, fmt.Errorf("%s: add files: %v", ZipActivityName, err)

Check warning on line 94 in internal/workflow/activities/zip.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/activities/zip.go#L94

Added line #L94 was not covered by tests
}

return &ZipActivityResult{Path: dest}, nil
Expand Down
20 changes: 10 additions & 10 deletions internal/workflow/local_activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,28 @@ func updatePackageLocalActivity(ctx context.Context, logger logr.Logger, pkgsvc
)
if err != nil {
logger.Error(err, "Error updating package")
return nil, err
return &updatePackageLocalActivityResult{}, err

Check warning on line 63 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L63

Added line #L63 was not covered by tests
}

return nil, nil
return &updatePackageLocalActivityResult{}, nil

Check warning on line 66 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L66

Added line #L66 was not covered by tests
}

type setStatusInProgressLocalActivityResult struct{}

func setStatusInProgressLocalActivity(ctx context.Context, pkgsvc package_.Service, pkgID uint, startedAt time.Time) (*setStatusInProgressLocalActivityResult, error) {
return nil, pkgsvc.SetStatusInProgress(ctx, pkgID, startedAt)
return &setStatusInProgressLocalActivityResult{}, pkgsvc.SetStatusInProgress(ctx, pkgID, startedAt)

Check warning on line 72 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L71-L72

Added lines #L71 - L72 were not covered by tests
}

type setStatusLocalActivityResult struct{}

func setStatusLocalActivity(ctx context.Context, pkgsvc package_.Service, pkgID uint, status package_.Status) (*setStatusLocalActivityResult, error) {
return nil, pkgsvc.SetStatus(ctx, pkgID, status)
return &setStatusLocalActivityResult{}, pkgsvc.SetStatus(ctx, pkgID, status)

Check warning on line 78 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L77-L78

Added lines #L77 - L78 were not covered by tests
}

type setLocationIDLocalActivityResult struct{}

func setLocationIDLocalActivity(ctx context.Context, pkgsvc package_.Service, pkgID uint, locationID uuid.UUID) (*setLocationIDLocalActivityResult, error) {
return nil, pkgsvc.SetLocationID(ctx, pkgID, locationID)
return &setLocationIDLocalActivityResult{}, pkgsvc.SetLocationID(ctx, pkgID, locationID)

Check warning on line 84 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L83-L84

Added lines #L83 - L84 were not covered by tests
}

type saveLocationMovePreservationActionLocalActivityParams struct {
Expand All @@ -106,7 +106,7 @@ func saveLocationMovePreservationActionLocalActivity(ctx context.Context, pkgsvc
PackageID: params.PackageID,
})
if err != nil {
return nil, err
return &saveLocationMovePreservationActionLocalActivityResult{}, err

Check warning on line 109 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L109

Added line #L109 was not covered by tests
}

actionStatusToTaskStatus := map[package_.PreservationActionStatus]package_.PreservationTaskStatus{
Expand All @@ -126,7 +126,7 @@ func saveLocationMovePreservationActionLocalActivity(ctx context.Context, pkgsvc
pt.StartedAt.Time = params.StartedAt
pt.CompletedAt.Time = params.CompletedAt

return nil, pkgsvc.CreatePreservationTask(ctx, &pt)
return &saveLocationMovePreservationActionLocalActivityResult{}, pkgsvc.CreatePreservationTask(ctx, &pt)

Check warning on line 129 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L129

Added line #L129 was not covered by tests
}

type createPreservationActionLocalActivityParams struct {
Expand Down Expand Up @@ -158,7 +158,7 @@ func createPreservationActionLocalActivity(ctx context.Context, pkgsvc package_.
type setPreservationActionStatusLocalActivityResult struct{}

func setPreservationActionStatusLocalActivity(ctx context.Context, pkgsvc package_.Service, ID uint, status package_.PreservationActionStatus) (*setPreservationActionStatusLocalActivityResult, error) {
return nil, pkgsvc.SetPreservationActionStatus(ctx, ID, status)
return &setPreservationActionStatusLocalActivityResult{}, pkgsvc.SetPreservationActionStatus(ctx, ID, status)

Check warning on line 161 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L160-L161

Added lines #L160 - L161 were not covered by tests
}

type completePreservationActionLocalActivityParams struct {
Expand All @@ -170,7 +170,7 @@ type completePreservationActionLocalActivityParams struct {
type completePreservationActionLocalActivityResult struct{}

func completePreservationActionLocalActivity(ctx context.Context, pkgsvc package_.Service, params *completePreservationActionLocalActivityParams) (*completePreservationActionLocalActivityResult, error) {
return nil, pkgsvc.CompletePreservationAction(ctx, params.PreservationActionID, params.Status, params.CompletedAt)
return &completePreservationActionLocalActivityResult{}, pkgsvc.CompletePreservationAction(ctx, params.PreservationActionID, params.Status, params.CompletedAt)

Check warning on line 173 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L172-L173

Added lines #L172 - L173 were not covered by tests
}

type createPreservationTaskLocalActivityParams struct {
Expand Down Expand Up @@ -211,5 +211,5 @@ type completePreservationTaskLocalActivityParams struct {
type completePreservationTaskLocalActivityResult struct{}

func completePreservationTaskLocalActivity(ctx context.Context, pkgsvc package_.Service, params *completePreservationTaskLocalActivityParams) (*completePreservationTaskLocalActivityResult, error) {
return nil, pkgsvc.CompletePreservationTask(ctx, params.ID, params.Status, params.CompletedAt, params.Note)
return &completePreservationTaskLocalActivityResult{}, pkgsvc.CompletePreservationTask(ctx, params.ID, params.Status, params.CompletedAt, params.Note)

Check warning on line 214 in internal/workflow/local_activities.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow/local_activities.go#L213-L214

Added lines #L213 - L214 were not covered by tests
}
2 changes: 1 addition & 1 deletion internal/workflow/processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *ProcessingWorkflowTestSuite) TestPackageConfirmation() {
s.env.OnActivity(createPreservationTaskLocalActivity, mock.Anything, mock.Anything, mock.Anything).Return(uint(0), nil)
s.env.OnActivity(activities.UploadActivityName, mock.Anything, mock.Anything).Return(nil, nil)
s.env.OnActivity(setStatusLocalActivity, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil)
s.env.OnActivity(setPreservationActionStatusLocalActivity, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil,nil)
s.env.OnActivity(setPreservationActionStatusLocalActivity, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil)
s.env.OnActivity(completePreservationTaskLocalActivity, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil)
s.env.OnActivity(activities.MoveToPermanentStorageActivityName, mock.Anything, mock.Anything).Return(nil, nil)
s.env.OnActivity(activities.PollMoveToPermanentStorageActivityName, mock.Anything, mock.Anything).Return(nil, nil)
Expand Down

0 comments on commit 7171ffe

Please sign in to comment.