clients

package
v0.0.0-...-110cdec Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package clients contains wrappers for client side bindings for APIs used by Buildbucket. These interfaces also provide mocks for API calls in tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrTaskBackendLite = errors.New("cannot create a TaskBackend client for a TaskBackendLite server")
View Source
var MockSwarmingClientKey = "used in tests only for setting the mock SwarmingClient"
View Source
var MockTaskBackendClientKey = contextKey("used in tests only for setting the mock SwarmingClient")
View Source
var MockTaskCreatorKey = contextKey("used in tests only for setting the mock TaskCreator")

Functions

func CreateRawPrpcClient

func CreateRawPrpcClient(ctx context.Context, host, project string) (client *prpc.Client, err error)

CreateRawPrpcClient creates a raw PRPC client for use with the specified host. Buildbucket will invoke the client's service with a Project-scoped identity.

func GetBackendHost

func GetBackendHost(target string, globalCfg *pb.SettingsCfg) (hostname string, err error)

GetBackendHost returns the backend's hostname from service config.

func IsTaskBackendLite

func IsTaskBackendLite(target string, globalCfg *pb.SettingsCfg) (bool, error)

IsTaskBackendLite returns whether the backend is a TaskBackendLite.

func NewPubsubClient

func NewPubsubClient(ctx context.Context, cloudProject, luciProject string) (*pubsub.Client, error)

NewPubsubClient creates a pubsub client with the authority of a given luciProject or the current service if luciProject is empty.

func SetupTestPubsub

func SetupTestPubsub(ctx context.Context, cloudProject string) (context.Context, *pstest.Server, *pubsub.Client, error)

SetupTestPubsub creates a new fake Pub/Sub server and the client connection to the server. It also adds the client into the context.

func ValidatePubSubTopicName

func ValidatePubSubTopicName(topic string) (string, string, error)

ValidatePubSubTopicName validates the format of topic, extract the cloud project and topic id, and return them.

func WithBqClient

func WithBqClient(ctx context.Context, client BqClient) context.Context

WithBqClient returns a new context with the given bq client.

Types

type BackendClient

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

BackendClient is the client to communicate with TaskBackend. It wraps a pb.TaskBackendClient.

func NewBackendClient

func NewBackendClient(ctx context.Context, project, target string, globalCfg *pb.SettingsCfg) (*BackendClient, error)

NewBackendClient creates a client to communicate with a full-featured TaskBackend server.

func (*BackendClient) CancelTasks

CancelTasks sends a cancel request to the backend

func (*BackendClient) FetchTasks

FetchTasks returns the requested tasks.

func (*BackendClient) RunTask

RunTask returns for the requested task.

func (*BackendClient) ValidateConfigs

ValidateConfigs returns validation errors (if any).

type BqClient

type BqClient interface {
	// Insert a row into a BigQuery table
	Insert(ctx context.Context, dataset string, table string, row *lucibq.Row) error
}

func GetBqClient

func GetBqClient(ctx context.Context) BqClient

GetBqClient returns the bigquery Client installed in the current context. Panics if there isn't one.

func NewBqClient

func NewBqClient(ctx context.Context, cloudProject string) (BqClient, error)

NewBqClient creates a new BqClient.

type MockSwarmingClient

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

MockSwarmingClient is a mock of SwarmingClient interface.

func NewMockSwarmingClient

func NewMockSwarmingClient(ctrl *gomock.Controller) *MockSwarmingClient

NewMockSwarmingClient creates a new mock instance.

func (*MockSwarmingClient) CancelTask

CancelTask mocks base method.

func (*MockSwarmingClient) CreateTask

CreateTask mocks base method.

func (*MockSwarmingClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSwarmingClient) GetTaskResult

func (m *MockSwarmingClient) GetTaskResult(ctx context.Context, taskID string) (*apipb.TaskResultResponse, error)

GetTaskResult mocks base method.

type MockSwarmingClientMockRecorder

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

MockSwarmingClientMockRecorder is the mock recorder for MockSwarmingClient.

func (*MockSwarmingClientMockRecorder) CancelTask

func (mr *MockSwarmingClientMockRecorder) CancelTask(ctx, req interface{}) *gomock.Call

CancelTask indicates an expected call of CancelTask.

func (*MockSwarmingClientMockRecorder) CreateTask

func (mr *MockSwarmingClientMockRecorder) CreateTask(ctx, createTaskReq interface{}) *gomock.Call

CreateTask indicates an expected call of CreateTask.

func (*MockSwarmingClientMockRecorder) GetTaskResult

func (mr *MockSwarmingClientMockRecorder) GetTaskResult(ctx, taskID interface{}) *gomock.Call

GetTaskResult indicates an expected call of GetTaskResult.

type MockTaskBackendClient

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

MockTaskBackendClient is a mock of TaskBackendClient interface.

func NewMockTaskBackendClient

func NewMockTaskBackendClient(ctrl *gomock.Controller) *MockTaskBackendClient

NewMockTaskBackendClient creates a new mock instance.

func (*MockTaskBackendClient) CancelTasks

CancelTasks mocks base method.

func (*MockTaskBackendClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTaskBackendClient) FetchTasks

FetchTasks mocks base method.

func (*MockTaskBackendClient) RunTask

RunTask mocks base method.

func (*MockTaskBackendClient) ValidateConfigs

ValidateConfigs mocks base method.

type MockTaskBackendClientMockRecorder

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

MockTaskBackendClientMockRecorder is the mock recorder for MockTaskBackendClient.

func (*MockTaskBackendClientMockRecorder) CancelTasks

func (mr *MockTaskBackendClientMockRecorder) CancelTasks(ctx, in interface{}, opts ...interface{}) *gomock.Call

CancelTasks indicates an expected call of CancelTasks.

func (*MockTaskBackendClientMockRecorder) FetchTasks

func (mr *MockTaskBackendClientMockRecorder) FetchTasks(ctx, in interface{}, opts ...interface{}) *gomock.Call

FetchTasks indicates an expected call of FetchTasks.

func (*MockTaskBackendClientMockRecorder) RunTask

func (mr *MockTaskBackendClientMockRecorder) RunTask(ctx, in interface{}, opts ...interface{}) *gomock.Call

RunTask indicates an expected call of RunTask.

func (*MockTaskBackendClientMockRecorder) ValidateConfigs

func (mr *MockTaskBackendClientMockRecorder) ValidateConfigs(ctx, in interface{}, opts ...interface{}) *gomock.Call

ValidateConfigs indicates an expected call of ValidateConfigs.

type MockTaskCreator

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

MockTaskCreator is a mock of TaskCreator interface.

func NewMockTaskCreator

func NewMockTaskCreator(ctrl *gomock.Controller) *MockTaskCreator

NewMockTaskCreator creates a new mock instance.

func (*MockTaskCreator) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTaskCreator) RunTask

RunTask mocks base method.

type MockTaskCreatorMockRecorder

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

MockTaskCreatorMockRecorder is the mock recorder for MockTaskCreator.

func (*MockTaskCreatorMockRecorder) RunTask

func (mr *MockTaskCreatorMockRecorder) RunTask(ctx, in interface{}, opts ...interface{}) *gomock.Call

RunTask indicates an expected call of RunTask.

type SwarmingClient

type SwarmingClient interface {
	CreateTask(ctx context.Context, createTaskReq *apipb.NewTaskRequest) (*apipb.TaskRequestMetadataResponse, error)
	GetTaskResult(ctx context.Context, taskID string) (*apipb.TaskResultResponse, error)
	CancelTask(ctx context.Context, req *apipb.TaskCancelRequest) (*apipb.CancelResponse, error)
}

SwarmingClient is a Swarming API wrapper for buildbucket-specific usage.

In prod, a SwarmingClient for interacting with the Swarming service will be used. Tests should use a fake implementation.

func NewSwarmingClient

func NewSwarmingClient(ctx context.Context, host string, project string) (SwarmingClient, error)

NewSwarmingClient returns a new SwarmingClient to interact with Swarming APIs.

type TaskBackendClient

type TaskBackendClient interface {
	CancelTasks(ctx context.Context, in *pb.CancelTasksRequest, opts ...grpc.CallOption) (*pb.CancelTasksResponse, error)
	RunTask(ctx context.Context, in *pb.RunTaskRequest, opts ...grpc.CallOption) (*pb.RunTaskResponse, error)
	FetchTasks(ctx context.Context, in *pb.FetchTasksRequest, opts ...grpc.CallOption) (*pb.FetchTasksResponse, error)
	ValidateConfigs(ctx context.Context, in *pb.ValidateConfigsRequest, opts ...grpc.CallOption) (*pb.ValidateConfigsResponse, error)
}

TaskBackendClient represents a full-featured TaskBackend.

type TaskCreator

type TaskCreator interface {
	RunTask(ctx context.Context, in *pb.RunTaskRequest, opts ...grpc.CallOption) (*pb.RunTaskResponse, error)
}

TaskCreator is the abstraction for TaskBackend or TaskBackendLite services which expose the RunTask API.

func NewTaskCreator

func NewTaskCreator(ctx context.Context, project, target string, globalCfg *pb.SettingsCfg, isLite bool) (TaskCreator, error)

NewTaskCreator creates a client to communicate with the backend which implements RunTask API.

type TaskCreatorClient

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

TaskCreatorClient is the implementation of TaskCreator and will be used in real Prod env.

func (*TaskCreatorClient) RunTask

RunTask returns for the requested task.

Jump to

Keyboard shortcuts

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