Skip to content

Commit

Permalink
Minor fixes to AIS workflow
Browse files Browse the repository at this point in the history
Refs #77.

- Remove extraneous `filepath.Join()` calls
- Improve commentary a bit
- Correct "search_md" zip name in workflow tests
  • Loading branch information
djjuhasz committed Nov 15, 2024
1 parent b8989cb commit d2bc160
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 3 additions & 2 deletions internal/ais/combinemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a *CombineMDActivity) Execute(

dest := filepath.Join(params.LocalDir, name)

// Combine metadata files into AIS file.
// Create AIS file.
w, err := os.Create(dest) // #nosec G304 -- generated path.
if err != nil {
return nil, fmt.Errorf("create AIS file: %v", err)
Expand All @@ -61,7 +61,8 @@ func (a *CombineMDActivity) Execute(
return nil, fmt.Errorf("set AIS file permissions: %v", err)
}

if err = concat(w, filepath.Join(params.AreldaPath), filepath.Join(params.METSPath)); err != nil {
// Append Arelda and METS file contents to AIS file.
if err = concat(w, params.AreldaPath, params.METSPath); err != nil {
return nil, fmt.Errorf("concat: %v", err)
}

Expand Down
24 changes: 13 additions & 11 deletions internal/ais/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,29 @@ func (s *TestSuite) TestWorkflowSuccess() {
err := s.env.GetWorkflowResult(&result)
s.NoError(err)

s.Equal(result, ais.WorkflowResult{Key: "test-" + aipUUID + ".zip"})
s.Equal(result, ais.WorkflowResult{Key: "search-md_test-" + aipUUID + ".zip"})
}

func (s *TestSuite) mockActivitiesSuccess(aipUUID string) {
aipName := "test-" + aipUUID
aipPath := "9390/594f/84c2/457d/bd6a/618f/21f7/c954/test-9390594f-84c2-457d-bd6a-618f21f7c954.zip"
localDir := filepath.Join(s.testDir, fmt.Sprintf("search-md_%s", aipName))
metsName := fmt.Sprintf("METS.%s.xml", aipUUID)
metsPath := filepath.Join(localDir, metsName)
searchMDName := fmt.Sprintf("search-md_%s", aipName)
localDir := filepath.Join(s.testDir, searchMDName)

// Mock activities.
s.env.OnActivity(
ais.GetAIPPathActivity,
mock.AnythingOfType("*context.valueCtx"),
&ais.GetAIPPathActivityParams{AIPUUID: aipUUID},
).Return(
&ais.GetAIPPathActivityResult{Path: aipPath}, nil,
&ais.GetAIPPathActivityResult{
Path: "9390/594f/84c2/457d/bd6a/618f/21f7/c954/test-9390594f-84c2-457d-bd6a-618f21f7c954.zip",
}, nil,
)

// Mock session activities.
sessionCtx := mock.AnythingOfType("*context.timerCtx")
metsName := fmt.Sprintf("METS.%s.xml", aipUUID)
metsPath := filepath.Join(localDir, metsName)
s.env.OnActivity(
ais.FetchActivityName,
sessionCtx,
Expand All @@ -119,13 +121,13 @@ func (s *TestSuite) mockActivitiesSuccess(aipUUID string) {
&ais.FetchActivityResult{}, nil,
)

mdpath := "objects/header/metadata.xml"
mdRelPath := "objects/header/metadata.xml"
s.env.OnActivity(
ais.ParseActivityName,
sessionCtx,
&ais.ParseActivityParams{METSPath: metsPath},
).Return(
&ais.ParseActivityResult{MetadataRelPath: mdpath}, nil,
&ais.ParseActivityResult{MetadataRelPath: mdRelPath}, nil,
)

areldaPath := filepath.Join(localDir, "metadata.xml")
Expand All @@ -134,7 +136,7 @@ func (s *TestSuite) mockActivitiesSuccess(aipUUID string) {
sessionCtx,
&ais.FetchActivityParams{
AIPUUID: aipUUID,
RelativePath: fmt.Sprintf("%s/data/%s", aipName, mdpath),
RelativePath: fmt.Sprintf("%s/data/%s", aipName, mdRelPath),
Destination: areldaPath,
},
).Return(
Expand All @@ -153,7 +155,7 @@ func (s *TestSuite) mockActivitiesSuccess(aipUUID string) {
&ais.CombineMDActivityResult{Path: filepath.Join(localDir, "AIS_1000_893_3251903")}, nil,
)

zipPath := filepath.Join(s.testDir, aipName+".zip")
zipPath := localDir + ".zip"
s.env.OnActivity(
archivezip.Name,
sessionCtx,
Expand All @@ -167,6 +169,6 @@ func (s *TestSuite) mockActivitiesSuccess(aipUUID string) {
sessionCtx,
&bucketupload.Params{Path: zipPath},
).Return(
&bucketupload.Result{Key: aipName + ".zip"}, nil,
&bucketupload.Result{Key: searchMDName + ".zip"}, nil,
)
}

0 comments on commit d2bc160

Please sign in to comment.