-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix iwftest pkg by exposing private interfaces in persistence and com…
…munications (#39)
- Loading branch information
1 parent
230bffa
commit 0e39ed2
Showing
8 changed files
with
176 additions
and
22 deletions.
There are no files selected for viewing
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
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
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
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
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
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,70 @@ | ||
## Unit tests APIs for iWF | ||
|
||
The APIs are generated by the below commands: | ||
```shell | ||
mockgen -source=iwf/persistence.go -package=iwftest -destination=iwftest/persistence.go | ||
mockgen -source=iwf/communication.go -package=iwftest -destination=iwftest/communication.go | ||
mockgen -source=iwf/workflow_context.go -package=iwftest -destination=iwftest/workflow_context.go | ||
``` | ||
|
||
## Usage | ||
|
||
See the [samples](https://github.com/indeedeng/iwf-golang-samples) for more details: | ||
|
||
```go | ||
package subscription | ||
|
||
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" | ||
"time" | ||
) | ||
|
||
var mockWfCtx *iwftest.MockWorkflowContext | ||
var mockPersistence *iwftest.MockPersistence | ||
var mockCommunication *iwftest.MockCommunication | ||
var emptyCmdResults = iwf.CommandResults{} | ||
var emptyObj = iwftest.NewTestObject(nil) | ||
var mockSvc *MockMyService | ||
|
||
func beforeEach(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
|
||
mockSvc = NewMockMyService(ctrl) | ||
mockWfCtx = iwftest.NewMockWorkflowContext(ctrl) | ||
mockPersistence = iwftest.NewMockPersistence(ctrl) | ||
mockCommunication = iwftest.NewMockCommunication(ctrl) | ||
} | ||
|
||
|
||
func TestInitState_Start(t *testing.T) { | ||
beforeEach(t) | ||
|
||
state := NewInitState() | ||
|
||
mockPersistence.EXPECT().SetDataObject(keyCustomer, testCustomer) | ||
cmdReq, err := state.Start(mockWfCtx, testCustomerObj, mockPersistence, mockCommunication) | ||
assert.Nil(t, err) | ||
assert.Equal(t, iwf.EmptyCommandRequest(), cmdReq) | ||
} | ||
|
||
|
||
func TestTrialState_Start(t *testing.T) { | ||
beforeEach(t) | ||
|
||
state := NewTrialState(mockSvc) | ||
|
||
mockSvc.EXPECT().sendEmail(testCustomer.Email, gomock.Any(), gomock.Any()) | ||
mockPersistence.EXPECT().GetDataObject(keyCustomer, gomock.Any()).SetArg(1, testCustomer) | ||
cmdReq, err := state.Start(mockWfCtx, emptyObj, mockPersistence, mockCommunication) | ||
assert.Nil(t, err) | ||
firingTime := cmdReq.Commands[0].TimerCommand.FiringUnixTimestampSeconds | ||
assert.Equal(t, iwf.AllCommandsCompletedRequest( | ||
iwf.NewTimerCommand("", time.Unix(firingTime, 0)), | ||
), cmdReq) | ||
} | ||
|
||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.