-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c10019c
commit 60054ad
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package example | ||
|
||
import "github.com/indeedeng/iwf-golang-sdk/iwf" | ||
|
||
func NewInitState() iwf.WorkflowState { | ||
return initState{} | ||
} | ||
|
||
type initState struct { | ||
iwf.WorkflowStateDefaults | ||
} | ||
|
||
const keyCustomer = "customer" | ||
|
||
func (b initState) WaitUntil(ctx iwf.WorkflowContext, input iwf.Object, persistence iwf.Persistence, communication iwf.Communication) (*iwf.CommandRequest, error) { | ||
var customer string | ||
input.Get(&customer) | ||
persistence.SetDataAttribute(keyCustomer, customer) | ||
return iwf.EmptyCommandRequest(), nil | ||
} | ||
|
||
func (b initState) Execute(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) { | ||
return iwf.GracefulCompletingWorkflow, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package example | ||
|
||
import ( | ||
"github.com/golang/mock/gomock" | ||
"github.com/indeedeng/iwf-golang-sdk/iwf" | ||
"github.com/indeedeng/iwf-golang-sdk/iwftest" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
var mockWfCtx *iwftest.MockWorkflowContext | ||
var mockPersistence *iwftest.MockPersistence | ||
var mockCommunication *iwftest.MockCommunication | ||
var emptyCmdResults = iwf.CommandResults{} | ||
var testCustomer = "customer1" | ||
var emptyObj = iwftest.NewTestObject(testCustomer) | ||
|
||
func beforeEach(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
|
||
mockWfCtx = iwftest.NewMockWorkflowContext(ctrl) | ||
mockPersistence = iwftest.NewMockPersistence(ctrl) | ||
mockCommunication = iwftest.NewMockCommunication(ctrl) | ||
} | ||
|
||
func TestInitState_WaitUntil(t *testing.T) { | ||
beforeEach(t) | ||
|
||
state := NewInitState() | ||
|
||
mockPersistence.EXPECT().SetDataAttribute(keyCustomer, testCustomer) | ||
cmdReq, err := state.WaitUntil(mockWfCtx, emptyObj, mockPersistence, mockCommunication) | ||
assert.Nil(t, err) | ||
assert.Equal(t, iwf.EmptyCommandRequest(), cmdReq) | ||
} | ||
|
||
func TestInitState_Execute(t *testing.T) { | ||
beforeEach(t) | ||
|
||
state := NewInitState() | ||
input := iwftest.NewTestObject(testCustomer) | ||
|
||
decision, err := state.Execute(mockWfCtx, input, emptyCmdResults, mockPersistence, mockCommunication) | ||
assert.Nil(t, err) | ||
assert.Equal(t, iwf.GracefulCompletingWorkflow, decision) | ||
} |