transport

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package transport contains data structures that implement agent transport capabilities. transport implementations are responsible for connecting to the Tink server and retrieving workflows for the agent to run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	Log       logr.Logger
	Workflows []workflow.Workflow
}

func Noop

func Noop() Fake

func (Fake) RecordEvent

func (f Fake) RecordEvent(_ context.Context, e event.Event) error

func (Fake) Start

func (f Fake) Start(ctx context.Context, _ string, handler WorkflowHandler) error

type File added in v0.10.0

type File struct {
	// Log is a logger for debugging.
	Log logr.Logger

	// Path to the workflow to run.
	Path string
}

File is a transport implementation that executes a single workflow stored as a file.

func (*File) RecordEvent added in v0.10.0

func (f *File) RecordEvent(_ context.Context, e event.Event) error

func (*File) Start added in v0.10.0

func (f *File) Start(ctx context.Context, _ string, handler WorkflowHandler) error

Start begins watching f.Dir for files. When it finds a file it hasn't handled before, it attempts to parse it and offload to the handler. It will run workflows once where a workflow is determined by its file name.

type GRPC

type GRPC struct {
	// contains filtered or unexported fields
}

func NewGRPC

func NewGRPC(log logr.Logger, client workflowproto.WorkflowServiceClient) *GRPC

func (*GRPC) RecordEvent

func (g *GRPC) RecordEvent(ctx context.Context, e event.Event) error

func (*GRPC) Start

func (g *GRPC) Start(ctx context.Context, agentID string, handler WorkflowHandler) error

type WorkflowHandler

type WorkflowHandler interface {
	// HandleWorkflow executes the given workflow. The event.Recorder can be used to publish events
	// as the workflow transits its lifecycle. HandleWorkflow should not block and should be efficient
	// in handing off workflow processing.
	HandleWorkflow(context.Context, workflow.Workflow, event.Recorder)

	// CancelWorkflow cancels a workflow identified by workflowID. It should not block and should
	// be efficient in handing off the cancellation request.
	CancelWorkflow(workflowID string)
}

WorkflowHandler is responsible for workflow execution.

type WorkflowHandlerMock

type WorkflowHandlerMock struct {
	// CancelWorkflowFunc mocks the CancelWorkflow method.
	CancelWorkflowFunc func(workflowID string)

	// HandleWorkflowFunc mocks the HandleWorkflow method.
	HandleWorkflowFunc func(contextMoqParam context.Context, workflowMoqParam workflow.Workflow, recorder event.Recorder)
	// contains filtered or unexported fields
}

WorkflowHandlerMock is a mock implementation of WorkflowHandler.

func TestSomethingThatUsesWorkflowHandler(t *testing.T) {

	// make and configure a mocked WorkflowHandler
	mockedWorkflowHandler := &WorkflowHandlerMock{
		CancelWorkflowFunc: func(workflowID string)  {
			panic("mock out the CancelWorkflow method")
		},
		HandleWorkflowFunc: func(contextMoqParam context.Context, workflowMoqParam workflow.Workflow, recorder event.Recorder)  {
			panic("mock out the HandleWorkflow method")
		},
	}

	// use mockedWorkflowHandler in code that requires WorkflowHandler
	// and then make assertions.

}

func (*WorkflowHandlerMock) CancelWorkflow

func (mock *WorkflowHandlerMock) CancelWorkflow(workflowID string)

CancelWorkflow calls CancelWorkflowFunc.

func (*WorkflowHandlerMock) CancelWorkflowCalls

func (mock *WorkflowHandlerMock) CancelWorkflowCalls() []struct {
	WorkflowID string
}

CancelWorkflowCalls gets all the calls that were made to CancelWorkflow. Check the length with:

len(mockedWorkflowHandler.CancelWorkflowCalls())

func (*WorkflowHandlerMock) HandleWorkflow

func (mock *WorkflowHandlerMock) HandleWorkflow(contextMoqParam context.Context, workflowMoqParam workflow.Workflow, recorder event.Recorder)

HandleWorkflow calls HandleWorkflowFunc.

func (*WorkflowHandlerMock) HandleWorkflowCalls

func (mock *WorkflowHandlerMock) HandleWorkflowCalls() []struct {
	ContextMoqParam  context.Context
	WorkflowMoqParam workflow.Workflow
	Recorder         event.Recorder
}

HandleWorkflowCalls gets all the calls that were made to HandleWorkflow. Check the length with:

len(mockedWorkflowHandler.HandleWorkflowCalls())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL