Skip to content

Commit

Permalink
Add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng committed May 22, 2023
1 parent 60054ad commit 6bf60ee
Showing 1 changed file with 1 addition and 58 deletions.
59 changes: 1 addition & 58 deletions iwftest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,5 @@ The APIs are generated by the below commands:

## Usage

See the [samples](https://github.com/indeedeng/iwf-golang-samples) for more details:
See the [example](./example) 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_WaitUntil(t *testing.T) {
beforeEach(t)

state := NewInitState()

mockPersistence.EXPECT().SetDataObject(keyCustomer, testCustomer)
cmdReq, err := state.WaitUntil(mockWfCtx, testCustomerObj, mockPersistence, mockCommunication)
assert.Nil(t, err)
assert.Equal(t, iwf.EmptyCommandRequest(), cmdReq)
}


func TestTrialState_WaitUntil(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.WaitUntil(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)
}

```

0 comments on commit 6bf60ee

Please sign in to comment.