-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clients/go): implement list workflows and get workflow
- Loading branch information
Showing
10 changed files
with
286 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters