11package choice
22
33import (
4+ "fmt"
45 "testing"
56
7+ "github.com/stretchr/testify/mock"
68 "github.com/stretchr/testify/suite"
79 "go.temporal.io/sdk/testsuite"
810)
@@ -16,7 +18,7 @@ func TestUnitTestSuite(t *testing.T) {
1618 suite .Run (t , new (UnitTestSuite ))
1719}
1820
19- func (s * UnitTestSuite ) Test_ExclusiveChoiceWorkflow () {
21+ func (s * UnitTestSuite ) Test_ExclusiveChoiceWorkflowSucceeds () {
2022 env := s .NewTestWorkflowEnvironment ()
2123
2224 orderChoices := []string {
@@ -29,3 +31,29 @@ func (s *UnitTestSuite) Test_ExclusiveChoiceWorkflow() {
2931 s .True (env .IsWorkflowCompleted ())
3032 s .NoError (env .GetWorkflowError ())
3133}
34+
35+ func (s * UnitTestSuite ) Test_ExclusiveChoiceWorkflowFailOnGetOrderFailure () {
36+ env := s .NewTestWorkflowEnvironment ()
37+ activities := & OrderActivities {}
38+ env .OnActivity (activities .GetOrder , mock .Anything ).Return ("" , fmt .Errorf ("Get Order Error" ))
39+
40+ env .ExecuteWorkflow (ExclusiveChoiceWorkflow )
41+
42+ s .True (env .IsWorkflowCompleted ())
43+ s .Error (env .GetWorkflowError ())
44+ }
45+
46+ func (s * UnitTestSuite ) Test_ExclusiveChoiceWorkflowFailOnOrdering () {
47+ env := s .NewTestWorkflowEnvironment ()
48+ orderChoices := []string {
49+ OrderChoiceApple ,
50+ }
51+ activities := & OrderActivities {orderChoices }
52+ env .RegisterActivity (activities .GetOrder )
53+ env .OnActivity (activities .OrderOrange , mock .Anything ).Return (nil , fmt .Errorf ("Get Order Error" ))
54+
55+ env .ExecuteWorkflow (ExclusiveChoiceWorkflow )
56+
57+ s .True (env .IsWorkflowCompleted ())
58+ s .Error (env .GetWorkflowError ())
59+ }
0 commit comments