Skip to content

Commit

Permalink
Implement more client script job tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Jul 16, 2024
1 parent 10e66d7 commit 6749cd3
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions hack/ccp/internal/controller/jobs_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package controller
import (
"context"
"encoding/json"
"io"
"testing"
"time"

"github.com/artefactual-labs/gearmin/gearmintest"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/mikespook/gearman-go/worker"
"go.artefactual.dev/tools/mockutil"
Expand All @@ -18,13 +20,66 @@ import (
func TestDirectoryClientScriptJob(t *testing.T) {
t.Parallel()

t.Skip("Not implemented yet!")
t.Run("Runs a single task", func(t *testing.T) {
t.Parallel()

jobs := 0
jobHandler := func(job worker.Job) ([]byte, error) {
jobs++
tasks := decodeTasks(t, job)
task1 := tasks[0]
assert.DeepEqual(t,
task1,
&task{
ID: task1.ID,
Args: `"%SIPDirectory%" "%watchDirectoryPath%workFlowDecisions/compressionAIPDecisions/." "%SIPUUID%" "%sharedPath%"`,
},
cmp.AllowUnexported(task{}),
cmpopts.IgnoreFields(task{}, "CreatedAt"),
)
return encodeTaskResults(t, map[uuid.UUID]*taskResult{
task1.ID: {
ExitCode: 0,
FinishedAt: time.Now(),
Stdout: ``,
},
}), nil
}

job, store := createJobWithHandlers(t,
"002716a1-ae29-4f36-98ab-0d97192669c4", // Move to compressionAIPDecisions directory.
map[string]gearmintest.Handler{"movesip_v0.0": jobHandler},
)
createAutomatedProcessingConfig(t, job.pkg.path)

store.EXPECT().CreateJob(mockutil.Context(), gomock.Any()).Return(nil).Times(1)
store.EXPECT().UpdateJobStatus(mockutil.Context(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
store.EXPECT().CreateTasks(mockutil.Context(), gomock.Any()).Return(nil).AnyTimes()

_, err := job.exec(context.Background())
assert.ErrorIs(t, err, io.EOF) // End of chain.
assert.Equal(t, jobs, 1)
})
}

func TestFilesClientScriptJob(t *testing.T) {
t.Parallel()

t.Skip("Not implemented yet!")
t.Run("Runs multiple tasks", func(t *testing.T) {
t.Parallel()

jobs := 0
jobHandler := func(job worker.Job) ([]byte, error) {
jobs++
return []byte(""), nil
}

job, _ := createJobWithHandlers(t,
"0e41c244-6c3e-46b9-a554-65e66e5c9324", // Identify file format of attachments.
map[string]gearmintest.Handler{"identifyfileformat_v0.0": jobHandler},
)
createAutomatedProcessingConfig(t, job.pkg.path)
})
}

func TestOutputClientScriptJob(t *testing.T) {
Expand Down

0 comments on commit 6749cd3

Please sign in to comment.