Skip to content

Commit

Permalink
fix not found status for retrieving workflow status in MySQL backend (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson authored Aug 13, 2024
1 parent 5fb703e commit f2ab312
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion engine/storage/mysql/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ func (s *MySQLStorage) CancelSteps(ctx context.Context, id, workflowName string)
// RetrieveWorkflowStarted returns the last time a workflow was started for id.
func (s *MySQLStorage) RetrieveWorkflowStarted(ctx context.Context, id, workflowName string) (time.Time, error) {
ret, err := s.q.GetWorkflowLastStarted(ctx, sqlc.GetWorkflowLastStartedParams{EnrollmentID: id, WorkflowName: workflowName})
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return time.Time{}, nil
} else if err != nil {
return time.Time{}, err
}
parsedTime, err := time.Parse(mySQLTimestampFormat, ret)
Expand Down
1 change: 1 addition & 0 deletions engine/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type StepResult struct {

type WorkflowStatusStorage interface {
// RetrieveWorkflowStarted returns the last time a workflow was started for id.
// Returned time should be nil with no error if workflowName has not yet been started for id.
RetrieveWorkflowStarted(ctx context.Context, id, workflowName string) (time.Time, error)

// RecordWorkflowStarted stores the started time for workflowName for ids.
Expand Down
8 changes: 8 additions & 0 deletions engine/storage/test/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"github.com/micromdm/nanocmd/workflow"
)

func TestEventStatusStorage(t *testing.T, ctx context.Context, store storage.WorkflowStatusStorage) {
_, err := store.RetrieveWorkflowStarted(ctx, "id.should.not.exist", "wfname.whaa")
if err != nil {
// should not error for a non-found item
t.Fatal(err)
}
}

func TestEventStorage(t *testing.T, store storage.EventSubscriptionStorage) {
ctx := context.Background()

Expand Down
6 changes: 6 additions & 0 deletions engine/storage/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func TestEngineStorage(t *testing.T, newStorage func() storage.AllStorage) {
t.Run("testEvent", func(t *testing.T) {
TestEventStorage(t, s)
})

ctx := context.Background()

t.Run("testEventStatus", func(t *testing.T) {
TestEventStatusStorage(t, ctx, s)
})
}

func mainTest(t *testing.T, s storage.AllStorage) {
Expand Down

0 comments on commit f2ab312

Please sign in to comment.