Skip to content

Commit

Permalink
IWF-103: Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lwolczynski committed Sep 20, 2024
1 parent 68c13a3 commit 2a0f977
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions service/interpreter/activityImpl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package interpreter

import (
"github.com/indeedeng/iwf/gen/iwfidl"
"github.com/indeedeng/iwf/service/common/ptr"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func TestInvalidAnyCommandCombination(t *testing.T) {
validTimerCommands, validSignalCommands, internalCommands := createCommands()

resp := iwfidl.WorkflowStateStartResponse{
CommandRequest: &iwfidl.CommandRequest{
SignalCommands: validSignalCommands,
TimerCommands: validTimerCommands,
InterStateChannelCommands: internalCommands,
DeciderTriggerType: iwfidl.ANY_COMMAND_COMBINATION_COMPLETED.Ptr(),
CommandCombinations: []iwfidl.CommandCombination{
{
CommandIds: []string{
"timer-cmd1", "signal-cmd1",
},
},
{
CommandIds: []string{
"timer-cmd1", "invalid",
},
},
},
},
}

err := checkCommandRequestFromWaitUntilResponse(&resp)

assert.Error(t, err)
assert.Equal(t, err.Error(), "ANY_COMMAND_COMBINATION_COMPLETED can only be used when every command has an commandId that is found in TimerCommands, SignalCommands or InternalChannelCommand")
}

func TestValidAnyCommandCombination(t *testing.T) {
validTimerCommands, validSignalCommands, internalCommands := createCommands()

resp := iwfidl.WorkflowStateStartResponse{
CommandRequest: &iwfidl.CommandRequest{
SignalCommands: validSignalCommands,
TimerCommands: validTimerCommands,
InterStateChannelCommands: internalCommands,
DeciderTriggerType: iwfidl.ANY_COMMAND_COMBINATION_COMPLETED.Ptr(),
CommandCombinations: []iwfidl.CommandCombination{
{
CommandIds: []string{
"timer-cmd1", "signal-cmd1",
},
},
{
CommandIds: []string{
"timer-cmd1", "internal-cmd1",
},
},
},
},
}

err := checkCommandRequestFromWaitUntilResponse(&resp)

assert.NoError(t, err)
}

func createCommands() ([]iwfidl.TimerCommand, []iwfidl.SignalCommand, []iwfidl.InterStateChannelCommand) {
validTimerCommands := []iwfidl.TimerCommand{
{
CommandId: ptr.Any("timer-cmd1"),
FiringUnixTimestampSeconds: iwfidl.PtrInt64(time.Now().Unix() + 86400*365), // one year later
},
}
validSignalCommands := []iwfidl.SignalCommand{
{
CommandId: ptr.Any("signal-cmd1"),
SignalChannelName: "test-signal-name1",
},
}
internalCommands := []iwfidl.InterStateChannelCommand{
{
CommandId: ptr.Any("internal-cmd1"),
ChannelName: "test-internal-name1",
},
}
return validTimerCommands, validSignalCommands, internalCommands
}

0 comments on commit 2a0f977

Please sign in to comment.