コード例 #1
0
ファイル: deciders_test.go プロジェクト: freeformz/swfsm
func TestOnChildStarted(t *testing.T) {
	decider := func(ctx *FSMContext, h *swf.HistoryEvent, data interface{}) Outcome {
		return ctx.Goto("some-state", data, ctx.EmptyDecisions())
	}

	composedDecider := OnChildStarted(decider)

	for _, et := range s.SWFHistoryEventTypes() {
		ctx := deciderTestContext()
		switch et {
		case enums.EventTypeChildWorkflowExecutionStarted:
			event := s.EventFromPayload(129, &swf.ChildWorkflowExecutionStartedEventAttributes{})
			data := new(TestData)
			outcome := composedDecider(ctx, event, data)
			expected := decider(ctx, event, data)
			if !reflect.DeepEqual(outcome, expected) {
				t.Fatal("Outcomes not equal", outcome, expected)
			}
		default:
			event := &swf.HistoryEvent{
				EventType: s.S(et),
			}
			if composedDecider(ctx, event, new(TestData)).State != "" {
				t.Fatal("Non nil decision")
			}
		}
	}
}
コード例 #2
0
ファイル: deciders_test.go プロジェクト: lstoll/swfsm
func TestOnSignalReceived(t *testing.T) {
	signal := "the-signal"
	ctx := deciderTestContext()
	decider := Transition("some-state")
	composedDecider := OnSignalReceived(signal, decider)

	for _, e := range s.SWFHistoryEventTypes() {
		switch e {
		case swf.EventTypeWorkflowExecutionSignaled:
			event := &swf.HistoryEvent{
				EventType: s.S(e),
				EventId:   s.L(129),
				WorkflowExecutionSignaledEventAttributes: &swf.WorkflowExecutionSignaledEventAttributes{
					SignalName: s.S("the-signal"),
				},
			}
			data := &TestingType{Field: "yes"}
			outcome := composedDecider(ctx, event, data)
			expected := decider(ctx, event, data)
			if !reflect.DeepEqual(outcome, expected) {
				t.Fatal("Outcomes not equal", outcome, expected)
			}
		default:
			event := &swf.HistoryEvent{
				EventType: s.S(e),
			}
			outcome := composedDecider(ctx, event, nil)
			if !reflect.DeepEqual(outcome, ctx.Pass()) {
				t.Fatal("Outcome does not equal Pass", outcome)
			}
		}
	}
}
コード例 #3
0
ファイル: deciders_test.go プロジェクト: lstoll/swfsm
func TestOnActivityFailedTimedOutCanceled(t *testing.T) {
	activity := "test-activity"
	decider := Transition("some-state")
	composedDecider := OnActivityFailedTimedOutCanceled(activity, decider)

	ctx := testContextWithActivity(123, &swf.ActivityTaskScheduledEventAttributes{
		ActivityId: s.S("the-id"),
		ActivityType: &swf.ActivityType{
			Name:    s.S(activity),
			Version: s.S("1"),
		},
	},
	)

	for _, e := range s.SWFHistoryEventTypes() {
		switch e {
		case swf.EventTypeActivityTaskFailed, swf.EventTypeActivityTaskTimedOut, swf.EventTypeActivityTaskCanceled:
			event := &swf.HistoryEvent{
				EventType: s.S(e),
				EventId:   s.L(129),
				ActivityTaskCanceledEventAttributes: &swf.ActivityTaskCanceledEventAttributes{ScheduledEventId: s.L(123)},
				ActivityTaskFailedEventAttributes:   &swf.ActivityTaskFailedEventAttributes{ScheduledEventId: s.L(123)},
				ActivityTaskTimedOutEventAttributes: &swf.ActivityTaskTimedOutEventAttributes{ScheduledEventId: s.L(123)},
			}
			data := &TestingType{Field: "yes"}
			outcome := composedDecider(ctx(), event, data)
			expected := decider(ctx(), event, data)
			if !reflect.DeepEqual(outcome, expected) {
				t.Fatal("Outcomes not equal", outcome, expected)
			}
		default:
			event := &swf.HistoryEvent{
				EventType: s.S(e),
			}
			outcome := composedDecider(ctx(), event, nil)
			if !reflect.DeepEqual(outcome, ctx().Pass()) {
				t.Fatal("Outcome does not equal Pass", outcome)
			}
		}
	}
}