Skip to content

Commit

Permalink
feat(clients/go): implement list workflows and get workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
menski committed Oct 25, 2018
1 parent 09a0669 commit 5169ac2
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 8 deletions.
3 changes: 3 additions & 0 deletions clients/go/api.go
Expand Up @@ -20,5 +20,8 @@ type ZBClient interface {
NewFailJobCommand() commands.FailJobCommandStep1
NewUpdateJobRetriesCommand() commands.UpdateJobRetriesCommandStep1

NewListWorkflowsCommand() commands.ListWorkflowsStep1
NewGetWorkflowCommand() commands.GetWorkflowStep1

Close() error
}
8 changes: 8 additions & 0 deletions clients/go/client.go
Expand Up @@ -55,6 +55,14 @@ func (client *ZBClientImpl) NewActivateJobsCommand() commands.ActivateJobsComman
return commands.NewActivateJobsCommand(client.gateway)
}

func (client *ZBClientImpl) NewListWorkflowsCommand() commands.ListWorkflowsStep1 {
return commands.NewListWorkflowsCommand(client.gateway)
}

func (client *ZBClientImpl) NewGetWorkflowCommand() commands.GetWorkflowStep1 {
return commands.NewGetWorkflowCommand(client.gateway)
}

func (client *ZBClientImpl) Close() error {
return client.connection.Close()
}
Expand Down
6 changes: 1 addition & 5 deletions clients/go/commands/createInstance_command.go
Expand Up @@ -9,10 +9,6 @@ import (
"time"
)

const (
LatestVersion = -1
)

type DispatchCreateInstanceCommand interface {
Send() (*pb.CreateWorkflowInstanceResponse, error)
}
Expand Down Expand Up @@ -79,7 +75,7 @@ func (cmd *CreateInstanceCommand) Version(version int32) CreateInstanceCommandSt
}

func (cmd *CreateInstanceCommand) LatestVersion() CreateInstanceCommandStep3 {
cmd.request.Version = LatestVersion
cmd.request.Version = utils.LatestVersion
return cmd
}

Expand Down
3 changes: 2 additions & 1 deletion clients/go/commands/createInstance_command_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/zeebe-io/zeebe/clients/go/mock_pb"
"github.com/zeebe-io/zeebe/clients/go/pb"
"github.com/zeebe-io/zeebe/clients/go/utils"
"testing"
)

Expand Down Expand Up @@ -55,7 +56,7 @@ func TestCreateWorkflowInstanceCommandByBpmnProcessId(t *testing.T) {

request := &pb.CreateWorkflowInstanceRequest{
BpmnProcessId: "foo",
Version: LatestVersion,
Version: utils.LatestVersion,
}
stub := &pb.CreateWorkflowInstanceResponse{
WorkflowKey: 123,
Expand Down
64 changes: 64 additions & 0 deletions clients/go/commands/getWorkflow_command.go
@@ -0,0 +1,64 @@
package commands

import (
"context"
"github.com/zeebe-io/zeebe/clients/go/pb"
"github.com/zeebe-io/zeebe/clients/go/utils"
"time"
)

type GetWorkflowStep1 interface {
BpmnProcessId(string) GetWorkflowStep2
WorkflowKey(int64) GetWorkflowStep3
}

type GetWorkflowStep2 interface {
Version(int32) GetWorkflowStep3
LatestVersion() GetWorkflowStep3
}

type GetWorkflowStep3 interface {
DispatchGetWorkflowCommand
}

type DispatchGetWorkflowCommand interface {
Send() (*pb.GetWorkflowResponse, error)
}

type GetWorkflowCommand struct {
gateway pb.GatewayClient
request *pb.GetWorkflowRequest
}

func (cmd *GetWorkflowCommand) BpmnProcessId(bpmnProcessId string) GetWorkflowStep2 {
cmd.request.BpmnProcessId = bpmnProcessId
return cmd
}

func (cmd *GetWorkflowCommand) WorkflowKey(workflowKey int64) GetWorkflowStep3 {
cmd.request.WorkflowKey = workflowKey
return cmd
}

func (cmd *GetWorkflowCommand) Version(version int32) GetWorkflowStep3 {
cmd.request.Version = version
return cmd
}

func (cmd *GetWorkflowCommand) LatestVersion() GetWorkflowStep3 {
return cmd.Version(utils.LatestVersion)
}

func (cmd *GetWorkflowCommand) Send() (*pb.GetWorkflowResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), utils.RequestTimeoutInSec*time.Second)
defer cancel()

return cmd.gateway.GetWorkflow(ctx, cmd.request)
}

func NewGetWorkflowCommand(gateway pb.GatewayClient) GetWorkflowStep1 {
return &GetWorkflowCommand{
gateway: gateway,
request: &pb.GetWorkflowRequest{},
}
}
107 changes: 107 additions & 0 deletions clients/go/commands/getWorkflow_command_test.go
@@ -0,0 +1,107 @@
package commands

import (
"github.com/golang/mock/gomock"
"github.com/zeebe-io/zeebe/clients/go/mock_pb"
"github.com/zeebe-io/zeebe/clients/go/pb"
"github.com/zeebe-io/zeebe/clients/go/utils"
"testing"
)

func TestGetWorkflowCommandByWorkflowKey(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := mock_pb.NewMockGatewayClient(ctrl)

request := &pb.GetWorkflowRequest{
WorkflowKey: 123,
}
stub := &pb.GetWorkflowResponse{
WorkflowKey: 123,
Version: 1,
BpmnProcessId: "testProcess",
ResourceName: "process.bpmn",
BpmnXml: "<xml/>",
}

client.EXPECT().GetWorkflow(gomock.Any(), &rpcMsg{msg: request}).Return(stub, nil)

command := NewGetWorkflowCommand(client)

response, err := command.WorkflowKey(123).Send()

if err != nil {
t.Errorf("Failed to send request")
}

if response != stub {
t.Errorf("Failed to receive response")
}
}

func TestGetWorkflowCommandByBpmnProcessId(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := mock_pb.NewMockGatewayClient(ctrl)

request := &pb.GetWorkflowRequest{
BpmnProcessId: "testProcess",
Version: utils.LatestVersion,
}
stub := &pb.GetWorkflowResponse{
WorkflowKey: 123,
Version: 1,
BpmnProcessId: "testProcess",
ResourceName: "process.bpmn",
BpmnXml: "<xml/>",
}

client.EXPECT().GetWorkflow(gomock.Any(), &rpcMsg{msg: request}).Return(stub, nil)

command := NewGetWorkflowCommand(client)

response, err := command.BpmnProcessId("testProcess").LatestVersion().Send()

if err != nil {
t.Errorf("Failed to send request")
}

if response != stub {
t.Errorf("Failed to receive response")
}
}

func TestGetWorkflowCommandByBpmnProcessIdAndVersion(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := mock_pb.NewMockGatewayClient(ctrl)

request := &pb.GetWorkflowRequest{
BpmnProcessId: "testProcess",
Version: 32,
}
stub := &pb.GetWorkflowResponse{
WorkflowKey: 123,
Version: 32,
BpmnProcessId: "testProcess",
ResourceName: "process.bpmn",
BpmnXml: "<xml/>",
}

client.EXPECT().GetWorkflow(gomock.Any(), &rpcMsg{msg: request}).Return(stub, nil)

command := NewGetWorkflowCommand(client)

response, err := command.BpmnProcessId("testProcess").Version(32).Send()

if err != nil {
t.Errorf("Failed to send request")
}

if response != stub {
t.Errorf("Failed to receive response")
}
}
41 changes: 41 additions & 0 deletions clients/go/commands/listWorkflows_command.go
@@ -0,0 +1,41 @@
package commands

import (
"context"
"github.com/zeebe-io/zeebe/clients/go/pb"
"github.com/zeebe-io/zeebe/clients/go/utils"
"time"
)

type ListWorkflowsStep1 interface {
DispatchListWorkflowsCommand
BpmnProcessId(string) ListWorkflowsStep1
}

type DispatchListWorkflowsCommand interface {
Send() (*pb.ListWorkflowsResponse, error)
}

type ListWorkflowsCommand struct {
gateway pb.GatewayClient
request *pb.ListWorkflowsRequest
}

func (cmd *ListWorkflowsCommand) BpmnProcessId(bpmnProcessId string) ListWorkflowsStep1 {
cmd.request.BpmnProcessId = bpmnProcessId
return cmd
}

func (cmd *ListWorkflowsCommand) Send() (*pb.ListWorkflowsResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), utils.StreamTimeoutInSec*time.Second)
defer cancel()

return cmd.gateway.ListWorkflows(ctx, cmd.request)
}

func NewListWorkflowsCommand(gateway pb.GatewayClient) ListWorkflowsStep1 {
return &ListWorkflowsCommand{
gateway: gateway,
request: &pb.ListWorkflowsRequest{},
}
}
58 changes: 58 additions & 0 deletions clients/go/commands/listWorkflows_command_test.go
@@ -0,0 +1,58 @@
package commands

import (
"github.com/golang/mock/gomock"
"github.com/zeebe-io/zeebe/clients/go/mock_pb"
"github.com/zeebe-io/zeebe/clients/go/pb"
"testing"
)

func TestListWorkflowsCommand(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := mock_pb.NewMockGatewayClient(ctrl)

request := &pb.ListWorkflowsRequest{}
stub := &pb.ListWorkflowsResponse{}

client.EXPECT().ListWorkflows(gomock.Any(), &rpcMsg{msg: request}).Return(stub, nil)

command := NewListWorkflowsCommand(client)

response, err := command.Send()

if err != nil {
t.Errorf("Failed to send request")
}

if response != stub {
t.Errorf("Failed to receive response")
}
}

func TestListWorkflowsCommandWithBpmnProcessId(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := mock_pb.NewMockGatewayClient(ctrl)

request := &pb.ListWorkflowsRequest{
BpmnProcessId: "foo",
}
stub := &pb.ListWorkflowsResponse{}

client.EXPECT().ListWorkflows(gomock.Any(), &rpcMsg{msg: request}).Return(stub, nil)

command := NewListWorkflowsCommand(client)

response, err := command.BpmnProcessId("foo").Send()

if err != nil {
t.Errorf("Failed to send request")
}

if response != stub {
t.Errorf("Failed to receive response")
}
}
1 change: 1 addition & 0 deletions clients/go/utils/contants.go
Expand Up @@ -3,6 +3,7 @@ package utils
import "time"

const (
LatestVersion = -1
DefaultRetries = 3
RequestTimeoutInSec = 5
StreamTimeoutInSec = 15
Expand Down
3 changes: 1 addition & 2 deletions clients/zbctl/utils/contants.go
Expand Up @@ -15,7 +15,6 @@ package utils

import (
"fmt"
"github.com/zeebe-io/zeebe/clients/go/commands"
"github.com/zeebe-io/zeebe/clients/go/utils"
"math"
"time"
Expand All @@ -27,7 +26,7 @@ const (
DefaultJobRetries = utils.DefaultRetries
DefaultJobWorker = "zbctl"
DefaultJobTimeout = 5 * time.Minute
LatestVersion = commands.LatestVersion
LatestVersion = utils.LatestVersion
EmptyJsonObject = "{}"
)

Expand Down

0 comments on commit 5169ac2

Please sign in to comment.