From 965f96adf60efed215747690b3d601362daf6c38 Mon Sep 17 00:00:00 2001 From: Christopher Zell Date: Tue, 22 Nov 2022 09:07:48 +0100 Subject: [PATCH] test: new tests for PI creation Use the new fake implementation to test the PI creation Right now the deployment is hard to test, since it doesn't return interfaces --- go-chaos/internal/zeebe_test.go | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/go-chaos/internal/zeebe_test.go b/go-chaos/internal/zeebe_test.go index 327cf3675..aa709e893 100644 --- a/go-chaos/internal/zeebe_test.go +++ b/go-chaos/internal/zeebe_test.go @@ -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) { @@ -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) +}