Skip to content

Commit

Permalink
test: new tests for PI creation
Browse files Browse the repository at this point in the history
Use the new fake implementation to test the PI creation

Right now the deployment is hard to test, since it doesn't return interfaces
  • Loading branch information
ChrisKujawa committed Nov 22, 2022
1 parent fb5ab75 commit 965f96a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions go-chaos/internal/zeebe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/camunda/zeebe/clients/go/v8/pkg/pb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_ExtractNodeId(t *testing.T) {
Expand Down Expand Up @@ -327,3 +328,54 @@ func Test_ShouldReadGivenFile(t *testing.T) {
err = os.RemoveAll(fileName)
assert.NoError(t, err)
}

func Test_ShouldSetVersionAndProcessIdWhenUsingPICreator(t *testing.T) {
// given
options := ProcessInstanceCreationOptions{BpmnProcessId: "processId", Version: 10}
fakeClient := &FakeClient{}
creator, err := CreateProcessInstanceCreator(fakeClient, options)
require.NoError(t, err)

// when
processInstanceKey, err := creator()

// then
assert.Equal(t, int64(0xCAFE), processInstanceKey)
assert.Equal(t, int32(10), fakeClient.version)
assert.Equal(t, "processId", fakeClient.processId)
}

func Test_ShouldSetVariablesForVersionAndProcessIdWhenUsingPICreator(t *testing.T) {
// given
options := ProcessInstanceCreationOptions{BpmnProcessId: "processId", Version: 10, Variables: "{\"foo\":123}"}
fakeClient := &FakeClient{}
creator, err := CreateProcessInstanceCreator(fakeClient, options)
require.NoError(t, err)

// when
processInstanceKey, err := creator()

// then
assert.Equal(t, int64(0xCAFE), processInstanceKey)
assert.Equal(t, int32(10), fakeClient.version)
assert.Equal(t, "processId", fakeClient.processId)
assert.Equal(t, "{\"foo\":123}", fakeClient.vars)
}

func Test_ShouldAwaitResultForProcessInstanceWithVersionAndProcessIdWhenUsingPICreator(t *testing.T) {
// given
options := ProcessInstanceCreationOptions{BpmnProcessId: "processId", Version: 10, Variables: "{\"foo\":123}", AwaitResult: true}
fakeClient := &FakeClient{}
creator, err := CreateProcessInstanceCreator(fakeClient, options)
require.NoError(t, err)

// when
processInstanceKey, err := creator()

// then
assert.Equal(t, int64(0xCAFE), processInstanceKey)
assert.Equal(t, int32(10), fakeClient.version)
assert.Equal(t, "processId", fakeClient.processId)
assert.Equal(t, "{\"foo\":123}", fakeClient.vars)
assert.True(t, fakeClient.awaitResult)
}

0 comments on commit 965f96a

Please sign in to comment.