-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtrigger_internal_test.go
48 lines (39 loc) · 1.45 KB
/
trigger_internal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package workflow
import (
"context"
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func Test_trigger(t *testing.T) {
b := NewBuilder[string, testStatus]("trigger test")
b.AddStep(statusStart, func(ctx context.Context, r *Run[string, testStatus]) (testStatus, error) {
return statusMiddle, nil
}, statusMiddle)
w := b.Build(nil, nil, nil, WithDebugMode())
t.Run("Expected non-nil error when Trigger called before Run()", func(t *testing.T) {
ctx := context.Background()
_, err := trigger(ctx, w, nil, "1", statusStart)
require.Equal(t, "trigger failed: workflow is not running", err.Error())
})
t.Run("Expects ErrStatusProvidedNotConfigured when starting status is not configured", func(t *testing.T) {
ctx := context.Background()
w.calledRun = true
_, err := trigger(ctx, w, nil, "1", statusEnd)
require.Equal(t, fmt.Sprintf("trigger failed: status provided is not configured for workflow: %s", statusEnd), err.Error())
})
t.Run("Expects ErrWorkflowInProgress if a workflow run is already in progress", func(t *testing.T) {
ctx := context.Background()
w.calledRun = true
_, err := trigger(ctx, w, func(ctx context.Context, workflowName, foreignID string) (*Record, error) {
return &Record{
WorkflowName: "trigger test",
ForeignID: "1",
RunState: RunStateRunning,
Status: int(statusMiddle),
}, nil
}, "1", statusStart)
require.True(t, errors.Is(err, ErrWorkflowInProgress))
})
}