From d2bc160a144728baba4d3e184fab6640c9953909 Mon Sep 17 00:00:00 2001 From: David Juhasz Date: Thu, 14 Nov 2024 15:57:31 -0800 Subject: [PATCH] Minor fixes to AIS workflow Refs #77. - Remove extraneous `filepath.Join()` calls - Improve commentary a bit - Correct "search_md" zip name in workflow tests --- internal/ais/combinemd.go | 5 +++-- internal/ais/workflow_test.go | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/internal/ais/combinemd.go b/internal/ais/combinemd.go index a63a9e2f..896f2544 100644 --- a/internal/ais/combinemd.go +++ b/internal/ais/combinemd.go @@ -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) @@ -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) } diff --git a/internal/ais/workflow_test.go b/internal/ais/workflow_test.go index bbbdd584..cc391859 100644 --- a/internal/ais/workflow_test.go +++ b/internal/ais/workflow_test.go @@ -86,15 +86,13 @@ 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( @@ -102,11 +100,15 @@ func (s *TestSuite) mockActivitiesSuccess(aipUUID string) { 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, @@ -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") @@ -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( @@ -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, @@ -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, ) }