testserver

package
v1.3.11 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package testserver provides an in-process mock RPC server for testing applications that use Connect RPC.

The mock server is designed to be reusable across multiple projects and provides a realistic testing environment by implementing actual HTTP/RPC handlers rather than using interface mocks.

Basic Usage

Create a mock server and configure responses:

func TestMyFeature(t *testing.T) {
    server := testserver.NewMockBuilderServer(t)
    defer server.Close()

    // Configure mock response
    server.OnGetClusterTimescaleDB().Return(&serverv1.GetClusterTimescaleDBResponse{
        Id: "test-db-id",
        Name: "test-db",
    })

    // Use server.URL to create a real client
    client := serverv1connect.NewBuilderServiceClient(http.DefaultClient, server.URL)
    resp, err := client.GetClusterTimescaleDB(ctx, connect.NewRequest(&serverv1.GetClusterTimescaleDBRequest{
        Id: "test-db-id",
    }))

    require.NoError(t, err)
    assert.Equal(t, "test-db-id", resp.Msg.Id)
}

Error Testing

Configure methods to return errors:

server.OnUpdateClusterTimescaleDB().ReturnError(errors.New("update failed"))

client := serverv1connect.NewBuilderServiceClient(http.DefaultClient, server.URL)
_, err := client.UpdateClusterTimescaleDB(ctx, connect.NewRequest(...))

require.Error(t, err)
assert.Contains(t, err.Error(), "update failed")

Request Capture

Capture and assert on requests sent to the server:

server.OnGetClusterTimescaleDB().Return(&serverv1.GetClusterTimescaleDBResponse{...})

client := serverv1connect.NewBuilderServiceClient(http.DefaultClient, server.URL)
client.GetClusterTimescaleDB(ctx, connect.NewRequest(&serverv1.GetClusterTimescaleDBRequest{
    Id: "test-id",
}))

requests := server.GetCapturedRequests("GetClusterTimescaleDB")
require.Len(t, requests, 1)
capturedReq := requests[0].(*serverv1.GetClusterTimescaleDBRequest)
assert.Equal(t, "test-id", capturedReq.Id)

Custom Behaviors

For complex scenarios, use custom behavior functions:

server.OnGetClusterTimescaleDB().WithBehavior(func(req proto.Message) (proto.Message, error) {
    getReq := req.(*serverv1.GetClusterTimescaleDBRequest)
    if getReq.Id == "invalid" {
        return nil, errors.New("not found")
    }
    return &serverv1.GetClusterTimescaleDBResponse{
        Id: getReq.Id,
        Name: "dynamic-name",
    }, nil
})

Thread Safety

The mock server is thread-safe and can be used with t.Parallel() tests. Each test should create its own server instance to ensure isolation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BehaviorFunc

type BehaviorFunc func(req proto.Message) (proto.Message, error)

BehaviorFunc is a custom function that can be used to implement complex response logic in tests. It receives the request and returns a response or error.

type MethodConfigBuilder

type MethodConfigBuilder[T proto.Message] struct {
	// contains filtered or unexported fields
}

MethodConfigBuilder provides a fluent API for configuring mock responses for a specific RPC method.

func (*MethodConfigBuilder[T]) Return

func (b *MethodConfigBuilder[T]) Return(response T)

Return configures the method to return the given response.

func (*MethodConfigBuilder[T]) ReturnError

func (b *MethodConfigBuilder[T]) ReturnError(err error)

ReturnError configures the method to return the given error.

func (*MethodConfigBuilder[T]) WithBehavior

func (b *MethodConfigBuilder[T]) WithBehavior(fn BehaviorFunc)

WithBehavior configures the method to use a custom behavior function that can implement complex logic.

type MockServer

type MockServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

MockServer wraps httptest.Server with a configuration API for setting up mock RPC responses.

func NewMockBuilderServer

func NewMockBuilderServer(t testing.TB) *MockServer

NewMockBuilderServer creates a new in-process HTTP server that implements the BuilderService and AuthService RPC interfaces. The server URL can be used to create real RPC clients that will interact with the mock server.

The auth service returns a default mock token automatically, so tests don't need to configure authentication unless testing auth-specific scenarios.

Example:

server := testserver.NewMockBuilderServer(t)
defer server.Close()

server.OnGetClusterTimescaleDB().Return(&serverv1.GetClusterTimescaleDBResponse{
    Id: "test-id",
})

client := serverv1connect.NewBuilderServiceClient(http.DefaultClient, server.URL)
resp, err := client.GetClusterTimescaleDB(ctx, connect.NewRequest(...))

func (*MockServer) GetCapturedRequests

func (s *MockServer) GetCapturedRequests(methodName string) []proto.Message

GetCapturedRequests returns all requests captured for the given method name. This is useful for test assertions.

func (*MockServer) OnCreateBindingClusterBackgroundPersistenceDeployment added in v1.2.195

func (s *MockServer) OnCreateBindingClusterBackgroundPersistenceDeployment() *MethodConfigBuilder[*serverv1.CreateBindingClusterBackgroundPersistenceDeploymentResponse]

OnCreateBindingClusterBackgroundPersistenceDeployment configures the CreateBindingClusterBackgroundPersistenceDeployment RPC method.

func (*MockServer) OnCreateBindingClusterCloudStorage added in v1.2.272

func (s *MockServer) OnCreateBindingClusterCloudStorage() *MethodConfigBuilder[*serverv1.CreateBindingClusterCloudStorageResponse]

OnCreateBindingClusterCloudStorage configures the CreateBindingClusterCloudStorage RPC method.

func (*MockServer) OnCreateBindingClusterContainerRegistry added in v1.2.273

func (s *MockServer) OnCreateBindingClusterContainerRegistry() *MethodConfigBuilder[*serverv1.CreateBindingClusterContainerRegistryResponse]

OnCreateBindingClusterContainerRegistry configures the CreateBindingClusterContainerRegistry RPC method.

func (*MockServer) OnCreateBindingClusterGateway added in v1.2.195

func (s *MockServer) OnCreateBindingClusterGateway() *MethodConfigBuilder[*serverv1.CreateBindingClusterGatewayResponse]

OnCreateBindingClusterGateway configures the CreateBindingClusterGateway RPC method.

func (*MockServer) OnCreateBindingClusterTelemetryDeployment added in v1.2.195

func (s *MockServer) OnCreateBindingClusterTelemetryDeployment() *MethodConfigBuilder[*serverv1.CreateBindingClusterTelemetryDeploymentResponse]

OnCreateBindingClusterTelemetryDeployment configures the CreateBindingClusterTelemetryDeployment RPC method.

func (*MockServer) OnCreateBindingEnvironmentBackgroundPersistenceDeployment added in v1.2.195

func (s *MockServer) OnCreateBindingEnvironmentBackgroundPersistenceDeployment() *MethodConfigBuilder[*serverv1.CreateBindingEnvironmentBackgroundPersistenceDeploymentResponse]

OnCreateBindingEnvironmentBackgroundPersistenceDeployment configures the CreateBindingEnvironmentBackgroundPersistenceDeployment RPC method.

func (*MockServer) OnCreateBindingEnvironmentCloudStorage added in v1.2.272

func (s *MockServer) OnCreateBindingEnvironmentCloudStorage() *MethodConfigBuilder[*serverv1.CreateBindingEnvironmentCloudStorageResponse]

OnCreateBindingEnvironmentCloudStorage configures the CreateBindingEnvironmentCloudStorage RPC method.

func (*MockServer) OnCreateBindingEnvironmentGateway added in v1.2.195

func (s *MockServer) OnCreateBindingEnvironmentGateway() *MethodConfigBuilder[*serverv1.CreateBindingEnvironmentGatewayResponse]

OnCreateBindingEnvironmentGateway configures the CreateBindingEnvironmentGateway RPC method.

func (*MockServer) OnCreateBindingEnvironmentOfflineStoreConnection added in v1.2.198

func (s *MockServer) OnCreateBindingEnvironmentOfflineStoreConnection() *MethodConfigBuilder[*serverv1.CreateBindingEnvironmentOfflineStoreConnectionResponse]

OnCreateBindingEnvironmentOfflineStoreConnection configures the CreateBindingEnvironmentOfflineStoreConnection RPC method.

func (*MockServer) OnCreateBindingPrivateGateway added in v1.2.195

func (s *MockServer) OnCreateBindingPrivateGateway() *MethodConfigBuilder[*serverv1.CreateBindingPrivateGatewayResponse]

OnCreateBindingPrivateGateway configures the CreateBindingPrivateGateway RPC method.

func (*MockServer) OnCreateCloudComponentCluster added in v1.2.267

func (s *MockServer) OnCreateCloudComponentCluster() *MethodConfigBuilder[*serverv1.CreateCloudComponentClusterResponse]

OnCreateCloudComponentCluster configures the CreateCloudComponentCluster RPC method.

func (*MockServer) OnCreateCloudComponentContainerRegistry added in v1.2.273

func (s *MockServer) OnCreateCloudComponentContainerRegistry() *MethodConfigBuilder[*serverv1.CreateCloudComponentContainerRegistryResponse]

OnCreateCloudComponentContainerRegistry configures the CreateCloudComponentContainerRegistry RPC method.

func (*MockServer) OnCreateCloudComponentStorage added in v1.2.272

func (s *MockServer) OnCreateCloudComponentStorage() *MethodConfigBuilder[*serverv1.CreateCloudComponentStorageResponse]

OnCreateCloudComponentStorage configures the CreateCloudComponentStorage RPC method.

func (*MockServer) OnCreateCloudComponentVpc added in v1.2.267

func (s *MockServer) OnCreateCloudComponentVpc() *MethodConfigBuilder[*serverv1.CreateCloudComponentVpcResponse]

OnCreateCloudComponentVpc configures the CreateCloudComponentVpc RPC method.

func (*MockServer) OnCreateClusterBackgroundPersistence added in v1.2.215

func (s *MockServer) OnCreateClusterBackgroundPersistence() *MethodConfigBuilder[*serverv1.CreateClusterBackgroundPersistenceResponse]

OnCreateClusterBackgroundPersistence configures the CreateClusterBackgroundPersistence RPC method.

func (*MockServer) OnCreateClusterGateway added in v1.2.268

OnCreateClusterGateway configures the CreateClusterGateway RPC method.

func (*MockServer) OnCreateClusterHostPool added in v1.2.291

func (s *MockServer) OnCreateClusterHostPool() *MethodConfigBuilder[*serverv1.CreateClusterHostPoolResponse]

OnCreateClusterHostPool configures the CreateClusterHostPool RPC method.

func (*MockServer) OnCreateClusterTimescaleDB

func (s *MockServer) OnCreateClusterTimescaleDB() *MethodConfigBuilder[*serverv1.CreateClusterTimescaleDBResponse]

OnCreateClusterTimescaleDB configures the CreateClusterTimescaleDB RPC method.

func (*MockServer) OnCreateEnvironmentHostPool added in v1.2.291

func (s *MockServer) OnCreateEnvironmentHostPool() *MethodConfigBuilder[*serverv1.CreateEnvironmentHostPoolResponse]

OnCreateEnvironmentHostPool configures the CreateEnvironmentHostPool RPC method.

func (*MockServer) OnCreateEnvironmentV2 added in v1.2.211

OnCreateEnvironmentV2 configures the CreateEnvironmentV2 RPC method.

func (*MockServer) OnCreateOfflineStoreConnection added in v1.2.198

func (s *MockServer) OnCreateOfflineStoreConnection() *MethodConfigBuilder[*serverv1.CreateOfflineStoreConnectionResponse]

OnCreateOfflineStoreConnection configures the CreateOfflineStoreConnection RPC method.

func (*MockServer) OnCreateSandbox added in v1.2.303

OnCreateSandbox configures the CreateSandbox RPC method.

func (*MockServer) OnCreateScalingGroup added in v1.2.241

OnCreateScalingGroup configures the CreateScalingGroup RPC method.

func (*MockServer) OnCreateTelemetryDeployment added in v1.2.186

func (s *MockServer) OnCreateTelemetryDeployment() *MethodConfigBuilder[*serverv1.CreateTelemetryDeploymentResponse]

OnCreateTelemetryDeployment configures the CreateTelemetryDeployment RPC method.

func (*MockServer) OnDeleteBindingClusterBackgroundPersistenceDeployment added in v1.2.195

func (s *MockServer) OnDeleteBindingClusterBackgroundPersistenceDeployment() *MethodConfigBuilder[*serverv1.DeleteBindingClusterBackgroundPersistenceDeploymentResponse]

OnDeleteBindingClusterBackgroundPersistenceDeployment configures the DeleteBindingClusterBackgroundPersistenceDeployment RPC method.

func (*MockServer) OnDeleteBindingClusterCloudStorage added in v1.2.272

func (s *MockServer) OnDeleteBindingClusterCloudStorage() *MethodConfigBuilder[*serverv1.DeleteBindingClusterCloudStorageResponse]

OnDeleteBindingClusterCloudStorage configures the DeleteBindingClusterCloudStorage RPC method.

func (*MockServer) OnDeleteBindingClusterContainerRegistry added in v1.2.273

func (s *MockServer) OnDeleteBindingClusterContainerRegistry() *MethodConfigBuilder[*serverv1.DeleteBindingClusterContainerRegistryResponse]

OnDeleteBindingClusterContainerRegistry configures the DeleteBindingClusterContainerRegistry RPC method.

func (*MockServer) OnDeleteBindingClusterGateway added in v1.2.195

func (s *MockServer) OnDeleteBindingClusterGateway() *MethodConfigBuilder[*serverv1.DeleteBindingClusterGatewayResponse]

OnDeleteBindingClusterGateway configures the DeleteBindingClusterGateway RPC method.

func (*MockServer) OnDeleteBindingClusterTelemetryDeployment added in v1.2.195

func (s *MockServer) OnDeleteBindingClusterTelemetryDeployment() *MethodConfigBuilder[*serverv1.DeleteBindingClusterTelemetryDeploymentResponse]

OnDeleteBindingClusterTelemetryDeployment configures the DeleteBindingClusterTelemetryDeployment RPC method.

func (*MockServer) OnDeleteBindingEnvironmentBackgroundPersistenceDeployment added in v1.2.195

func (s *MockServer) OnDeleteBindingEnvironmentBackgroundPersistenceDeployment() *MethodConfigBuilder[*serverv1.DeleteBindingEnvironmentBackgroundPersistenceDeploymentResponse]

OnDeleteBindingEnvironmentBackgroundPersistenceDeployment configures the DeleteBindingEnvironmentBackgroundPersistenceDeployment RPC method.

func (*MockServer) OnDeleteBindingEnvironmentCloudStorage added in v1.2.272

func (s *MockServer) OnDeleteBindingEnvironmentCloudStorage() *MethodConfigBuilder[*serverv1.DeleteBindingEnvironmentCloudStorageResponse]

OnDeleteBindingEnvironmentCloudStorage configures the DeleteBindingEnvironmentCloudStorage RPC method.

func (*MockServer) OnDeleteBindingEnvironmentGateway added in v1.2.195

func (s *MockServer) OnDeleteBindingEnvironmentGateway() *MethodConfigBuilder[*serverv1.DeleteBindingEnvironmentGatewayResponse]

OnDeleteBindingEnvironmentGateway configures the DeleteBindingEnvironmentGateway RPC method.

func (*MockServer) OnDeleteBindingEnvironmentOfflineStoreConnection added in v1.2.198

func (s *MockServer) OnDeleteBindingEnvironmentOfflineStoreConnection() *MethodConfigBuilder[*serverv1.DeleteBindingEnvironmentOfflineStoreConnectionResponse]

OnDeleteBindingEnvironmentOfflineStoreConnection configures the DeleteBindingEnvironmentOfflineStoreConnection RPC method.

func (*MockServer) OnDeleteBindingPrivateGateway added in v1.2.195

func (s *MockServer) OnDeleteBindingPrivateGateway() *MethodConfigBuilder[*serverv1.DeleteBindingPrivateGatewayResponse]

OnDeleteBindingPrivateGateway configures the DeleteBindingPrivateGateway RPC method.

func (*MockServer) OnDeleteCloudComponentCluster added in v1.2.267

func (s *MockServer) OnDeleteCloudComponentCluster() *MethodConfigBuilder[*serverv1.DeleteCloudComponentClusterResponse]

OnDeleteCloudComponentCluster configures the DeleteCloudComponentCluster RPC method.

func (*MockServer) OnDeleteCloudComponentContainerRegistry added in v1.2.273

func (s *MockServer) OnDeleteCloudComponentContainerRegistry() *MethodConfigBuilder[*serverv1.DeleteCloudComponentContainerRegistryResponse]

OnDeleteCloudComponentContainerRegistry configures the DeleteCloudComponentContainerRegistry RPC method.

func (*MockServer) OnDeleteCloudComponentStorage added in v1.2.272

func (s *MockServer) OnDeleteCloudComponentStorage() *MethodConfigBuilder[*serverv1.DeleteCloudComponentStorageResponse]

OnDeleteCloudComponentStorage configures the DeleteCloudComponentStorage RPC method.

func (*MockServer) OnDeleteCloudComponentVpc added in v1.2.267

func (s *MockServer) OnDeleteCloudComponentVpc() *MethodConfigBuilder[*serverv1.DeleteCloudComponentVpcResponse]

OnDeleteCloudComponentVpc configures the DeleteCloudComponentVpc RPC method.

func (*MockServer) OnDeleteClusterBackgroundPersistence added in v1.2.268

func (s *MockServer) OnDeleteClusterBackgroundPersistence() *MethodConfigBuilder[*serverv1.DeleteClusterBackgroundPersistenceResponse]

OnDeleteClusterBackgroundPersistence configures the DeleteClusterBackgroundPersistence RPC method.

func (*MockServer) OnDeleteClusterGateway added in v1.2.268

OnDeleteClusterGateway configures the DeleteClusterGateway RPC method.

func (*MockServer) OnDeleteClusterHostPool added in v1.2.291

func (s *MockServer) OnDeleteClusterHostPool() *MethodConfigBuilder[*serverv1.DeleteClusterHostPoolResponse]

OnDeleteClusterHostPool configures the DeleteClusterHostPool RPC method.

func (*MockServer) OnDeleteClusterTimescaleDB added in v1.2.185

func (s *MockServer) OnDeleteClusterTimescaleDB() *MethodConfigBuilder[*serverv1.DeleteClusterTimescaleDBResponse]

OnDeleteClusterTimescaleDB configures the DeleteClusterTimescaleDB RPC method.

func (*MockServer) OnDeleteEnvironment added in v1.2.211

OnDeleteEnvironment configures the DeleteEnvironment RPC method.

func (*MockServer) OnDeleteEnvironmentHostPool added in v1.2.291

func (s *MockServer) OnDeleteEnvironmentHostPool() *MethodConfigBuilder[*serverv1.DeleteEnvironmentHostPoolResponse]

OnDeleteEnvironmentHostPool configures the DeleteEnvironmentHostPool RPC method.

func (*MockServer) OnDeleteIntegration added in v1.2.191

OnDeleteIntegration configures the DeleteIntegration RPC method.

func (*MockServer) OnDeleteOfflineStoreConnection added in v1.2.198

func (s *MockServer) OnDeleteOfflineStoreConnection() *MethodConfigBuilder[*serverv1.DeleteOfflineStoreConnectionResponse]

OnDeleteOfflineStoreConnection configures the DeleteOfflineStoreConnection RPC method.

func (*MockServer) OnDeleteScalingGroup added in v1.2.241

OnDeleteScalingGroup configures the DeleteScalingGroup RPC method.

func (*MockServer) OnDeleteTelemetryDeployment added in v1.2.192

func (s *MockServer) OnDeleteTelemetryDeployment() *MethodConfigBuilder[*serverv1.DeleteTelemetryDeploymentResponse]

OnDeleteTelemetryDeployment configures the DeleteTelemetryDeployment RPC method.

func (*MockServer) OnGetBindingClusterBackgroundPersistenceDeployment added in v1.2.195

func (s *MockServer) OnGetBindingClusterBackgroundPersistenceDeployment() *MethodConfigBuilder[*serverv1.GetBindingClusterBackgroundPersistenceDeploymentResponse]

OnGetBindingClusterBackgroundPersistenceDeployment configures the GetBindingClusterBackgroundPersistenceDeployment RPC method.

func (*MockServer) OnGetBindingClusterCloudStorage added in v1.2.272

func (s *MockServer) OnGetBindingClusterCloudStorage() *MethodConfigBuilder[*serverv1.GetBindingClusterCloudStorageResponse]

OnGetBindingClusterCloudStorage configures the GetBindingClusterCloudStorage RPC method.

func (*MockServer) OnGetBindingClusterContainerRegistry added in v1.2.273

func (s *MockServer) OnGetBindingClusterContainerRegistry() *MethodConfigBuilder[*serverv1.GetBindingClusterContainerRegistryResponse]

OnGetBindingClusterContainerRegistry configures the GetBindingClusterContainerRegistry RPC method.

func (*MockServer) OnGetBindingClusterGateway added in v1.2.195

func (s *MockServer) OnGetBindingClusterGateway() *MethodConfigBuilder[*serverv1.GetBindingClusterGatewayResponse]

OnGetBindingClusterGateway configures the GetBindingClusterGateway RPC method.

func (*MockServer) OnGetBindingClusterTelemetryDeployment added in v1.2.195

func (s *MockServer) OnGetBindingClusterTelemetryDeployment() *MethodConfigBuilder[*serverv1.GetBindingClusterTelemetryDeploymentResponse]

OnGetBindingClusterTelemetryDeployment configures the GetBindingClusterTelemetryDeployment RPC method.

func (*MockServer) OnGetBindingEnvironmentBackgroundPersistenceDeployment added in v1.2.195

func (s *MockServer) OnGetBindingEnvironmentBackgroundPersistenceDeployment() *MethodConfigBuilder[*serverv1.GetBindingEnvironmentBackgroundPersistenceDeploymentResponse]

OnGetBindingEnvironmentBackgroundPersistenceDeployment configures the GetBindingEnvironmentBackgroundPersistenceDeployment RPC method.

func (*MockServer) OnGetBindingEnvironmentCloudStorage added in v1.2.272

func (s *MockServer) OnGetBindingEnvironmentCloudStorage() *MethodConfigBuilder[*serverv1.GetBindingEnvironmentCloudStorageResponse]

OnGetBindingEnvironmentCloudStorage configures the GetBindingEnvironmentCloudStorage RPC method.

func (*MockServer) OnGetBindingEnvironmentGateway added in v1.2.195

func (s *MockServer) OnGetBindingEnvironmentGateway() *MethodConfigBuilder[*serverv1.GetBindingEnvironmentGatewayResponse]

OnGetBindingEnvironmentGateway configures the GetBindingEnvironmentGateway RPC method.

func (*MockServer) OnGetBindingEnvironmentOfflineStoreConnection added in v1.2.198

func (s *MockServer) OnGetBindingEnvironmentOfflineStoreConnection() *MethodConfigBuilder[*serverv1.GetBindingEnvironmentOfflineStoreConnectionResponse]

OnGetBindingEnvironmentOfflineStoreConnection configures the GetBindingEnvironmentOfflineStoreConnection RPC method.

func (*MockServer) OnGetBindingPrivateGateway added in v1.2.195

func (s *MockServer) OnGetBindingPrivateGateway() *MethodConfigBuilder[*serverv1.GetBindingPrivateGatewayResponse]

OnGetBindingPrivateGateway configures the GetBindingPrivateGateway RPC method.

func (*MockServer) OnGetCloudComponentCluster added in v1.2.267

func (s *MockServer) OnGetCloudComponentCluster() *MethodConfigBuilder[*serverv1.GetCloudComponentClusterResponse]

OnGetCloudComponentCluster configures the GetCloudComponentCluster RPC method.

func (*MockServer) OnGetCloudComponentContainerRegistry added in v1.2.273

func (s *MockServer) OnGetCloudComponentContainerRegistry() *MethodConfigBuilder[*serverv1.GetCloudComponentContainerRegistryResponse]

OnGetCloudComponentContainerRegistry configures the GetCloudComponentContainerRegistry RPC method.

func (*MockServer) OnGetCloudComponentStorage added in v1.2.272

func (s *MockServer) OnGetCloudComponentStorage() *MethodConfigBuilder[*serverv1.GetCloudComponentStorageResponse]

OnGetCloudComponentStorage configures the GetCloudComponentStorage RPC method.

func (*MockServer) OnGetCloudComponentVpc added in v1.2.267

OnGetCloudComponentVpc configures the GetCloudComponentVpc RPC method.

func (*MockServer) OnGetClusterBackgroundPersistence added in v1.2.215

func (s *MockServer) OnGetClusterBackgroundPersistence() *MethodConfigBuilder[*serverv1.GetClusterBackgroundPersistenceResponse]

OnGetClusterBackgroundPersistence configures the GetClusterBackgroundPersistence RPC method.

func (*MockServer) OnGetClusterGateway added in v1.2.268

OnGetClusterGateway configures the GetClusterGateway RPC method.

func (*MockServer) OnGetClusterTimescaleDB

func (s *MockServer) OnGetClusterTimescaleDB() *MethodConfigBuilder[*serverv1.GetClusterTimescaleDBResponse]

OnGetClusterTimescaleDB configures the GetClusterTimescaleDB RPC method.

func (*MockServer) OnGetEnv added in v1.2.186

OnGetEnv configures the GetEnv RPC method. By default, the mock server returns a valid environment with test-cluster-id.

func (*MockServer) OnGetHostPool added in v1.2.291

OnGetHostPool configures the GetHostPool RPC method.

func (*MockServer) OnGetIntegration added in v1.2.191

OnGetIntegration configures the GetIntegration RPC method.

func (*MockServer) OnGetIntegrationValue added in v1.2.193

OnGetIntegrationValue configures the GetIntegrationValue RPC method.

func (*MockServer) OnGetOfflineStoreConnection added in v1.2.198

func (s *MockServer) OnGetOfflineStoreConnection() *MethodConfigBuilder[*serverv1.GetOfflineStoreConnectionResponse]

OnGetOfflineStoreConnection configures the GetOfflineStoreConnection RPC method.

func (*MockServer) OnGetSandbox added in v1.2.303

OnGetSandbox configures the GetSandbox RPC method.

func (*MockServer) OnGetScalingGroup added in v1.2.241

OnGetScalingGroup configures the GetScalingGroup RPC method.

func (*MockServer) OnGetTelemetryDeployment added in v1.2.186

func (s *MockServer) OnGetTelemetryDeployment() *MethodConfigBuilder[*serverv1.GetTelemetryDeploymentResponse]

OnGetTelemetryDeployment configures the GetTelemetryDeployment RPC method.

func (*MockServer) OnGetToken added in v1.2.185

OnGetToken configures the GetToken RPC method. By default, the mock server returns a valid token automatically. Use this method only if you need to test auth failures or custom token responses.

func (*MockServer) OnInsertIntegration added in v1.2.191

OnInsertIntegration configures the InsertIntegration RPC method.

func (*MockServer) OnListBindingClusterContainerRegistry added in v1.2.273

func (s *MockServer) OnListBindingClusterContainerRegistry() *MethodConfigBuilder[*serverv1.ListBindingClusterContainerRegistryResponse]

OnListBindingClusterContainerRegistry configures the ListBindingClusterContainerRegistry RPC method.

func (*MockServer) OnListCloudComponentContainerRegistry added in v1.2.273

func (s *MockServer) OnListCloudComponentContainerRegistry() *MethodConfigBuilder[*serverv1.ListCloudComponentContainerRegistryResponse]

OnListCloudComponentContainerRegistry configures the ListCloudComponentContainerRegistry RPC method.

func (*MockServer) OnListCloudComponentStorage added in v1.2.273

func (s *MockServer) OnListCloudComponentStorage() *MethodConfigBuilder[*serverv1.ListCloudComponentStorageResponse]

OnListCloudComponentStorage configures the ListCloudComponentStorage RPC method.

func (*MockServer) OnListHostPools added in v1.2.291

OnListHostPools configures the ListHostPools RPC method.

func (*MockServer) OnListIntegrations added in v1.2.191

OnListIntegrations configures the ListIntegrations RPC method.

func (*MockServer) OnListOfflineStoreConnections added in v1.2.198

func (s *MockServer) OnListOfflineStoreConnections() *MethodConfigBuilder[*serverv1.ListOfflineStoreConnectionsResponse]

OnListOfflineStoreConnections configures the ListOfflineStoreConnections RPC method.

func (*MockServer) OnListSandboxes added in v1.2.303

OnListSandboxes configures the ListSandboxes RPC method.

func (*MockServer) OnMigrateOfflineStoreConnection added in v1.2.198

func (s *MockServer) OnMigrateOfflineStoreConnection() *MethodConfigBuilder[*serverv1.MigrateOfflineStoreConnectionResponse]

OnMigrateOfflineStoreConnection configures the MigrateOfflineStoreConnection RPC method.

func (*MockServer) OnTerminateSandbox added in v1.2.303

OnTerminateSandbox configures the TerminateSandbox RPC method.

func (*MockServer) OnTestOfflineStoreConnection added in v1.2.198

func (s *MockServer) OnTestOfflineStoreConnection() *MethodConfigBuilder[*serverv1.TestOfflineStoreConnectionResponse]

OnTestOfflineStoreConnection configures the TestOfflineStoreConnection RPC method.

func (*MockServer) OnUpdateCloudComponentCluster added in v1.2.276

func (s *MockServer) OnUpdateCloudComponentCluster() *MethodConfigBuilder[*serverv1.UpdateCloudComponentClusterResponse]

OnUpdateCloudComponentCluster configures the UpdateCloudComponentCluster RPC method.

func (*MockServer) OnUpdateClusterHostPool added in v1.2.291

func (s *MockServer) OnUpdateClusterHostPool() *MethodConfigBuilder[*serverv1.UpdateClusterHostPoolResponse]

OnUpdateClusterHostPool configures the UpdateClusterHostPool RPC method.

func (*MockServer) OnUpdateClusterTimescaleDB

func (s *MockServer) OnUpdateClusterTimescaleDB() *MethodConfigBuilder[*serverv1.UpdateClusterTimescaleDBResponse]

OnUpdateClusterTimescaleDB configures the UpdateClusterTimescaleDB RPC method.

func (*MockServer) OnUpdateEnvironmentHostPool added in v1.2.291

func (s *MockServer) OnUpdateEnvironmentHostPool() *MethodConfigBuilder[*serverv1.UpdateEnvironmentHostPoolResponse]

OnUpdateEnvironmentHostPool configures the UpdateEnvironmentHostPool RPC method.

func (*MockServer) OnUpdateEnvironmentV2 added in v1.2.211

OnUpdateEnvironmentV2 configures the UpdateEnvironmentV2 RPC method.

func (*MockServer) OnUpdateIntegration added in v1.2.191

OnUpdateIntegration configures the UpdateIntegration RPC method.

func (*MockServer) OnUpdateOfflineStoreConnection added in v1.2.198

func (s *MockServer) OnUpdateOfflineStoreConnection() *MethodConfigBuilder[*serverv1.UpdateOfflineStoreConnectionResponse]

OnUpdateOfflineStoreConnection configures the UpdateOfflineStoreConnection RPC method.

func (*MockServer) OnUpdateTelemetryDeployment added in v1.2.186

func (s *MockServer) OnUpdateTelemetryDeployment() *MethodConfigBuilder[*serverv1.UpdateTelemetryDeploymentResponse]

OnUpdateTelemetryDeployment configures the UpdateTelemetryDeployment RPC method.

func (*MockServer) Reset

func (s *MockServer) Reset()

Reset clears all configured responses, errors, behaviors, and captured requests.

type ResponseRegistry

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

ResponseRegistry manages mock responses, errors, and captured requests for RPC methods. It is thread-safe and can be safely used from multiple goroutines.

func NewResponseRegistry

func NewResponseRegistry() *ResponseRegistry

NewResponseRegistry creates a new ResponseRegistry.

func (*ResponseRegistry) CaptureRequest

func (r *ResponseRegistry) CaptureRequest(method string, req proto.Message)

CaptureRequest records an incoming request for the given method.

func (*ResponseRegistry) GetBehavior

func (r *ResponseRegistry) GetBehavior(method string) BehaviorFunc

GetBehavior retrieves the custom behavior function for the given method.

func (*ResponseRegistry) GetCapturedRequests

func (r *ResponseRegistry) GetCapturedRequests(method string) []proto.Message

GetCapturedRequests returns all captured requests for the given method.

func (*ResponseRegistry) GetError

func (r *ResponseRegistry) GetError(method string) error

GetError retrieves the configured error for the given method.

func (*ResponseRegistry) GetResponse

func (r *ResponseRegistry) GetResponse(method string) proto.Message

GetResponse retrieves the configured response for the given method.

func (*ResponseRegistry) Reset

func (r *ResponseRegistry) Reset()

Reset clears all state from the registry.

func (*ResponseRegistry) SetBehavior

func (r *ResponseRegistry) SetBehavior(method string, fn BehaviorFunc)

SetBehavior sets a custom behavior function for the given method.

func (*ResponseRegistry) SetError

func (r *ResponseRegistry) SetError(method string, err error)

SetError configures an error to return for the given method.

func (*ResponseRegistry) SetResponse

func (r *ResponseRegistry) SetResponse(method string, response proto.Message)

SetResponse stores a canned response for the given method.

Jump to

Keyboard shortcuts

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