Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix not found status for retrieving workflow status in MySQL backend #63

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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