testutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(t *testing.T, env *TestEnv, args ...string) (stdout, stderr string, err error)

Exec builds and executes the root command with the given args, returning captured stdout, stderr, and any error from cmd.Execute().

func FindContextEntry

func FindContextEntry(t *testing.T, path, name string) *config.ContextEntry

FindContextEntry reads the YAML config file at path and returns a pointer to the ContextEntry whose Name matches name, or nil if not found.

func WriteConfigFile

func WriteConfigFile(t *testing.T, dir string, content map[string]any) string

WriteConfigFile marshals content as JSON and writes it to dir/config.json. Returns the full path for use with --config or QDRANT_CLOUD_CONFIG.

func WriteContextConfigFile

func WriteContextConfigFile(t *testing.T, dir, currentContext string, contexts map[string]map[string]string) string

WriteContextConfigFile writes a context-format YAML config file to dir/config.yaml. Contexts are written as a YAML slice (- name: ...) sorted by name for deterministic output. Returns the full path for use with --config or QDRANT_CLOUD_CONFIG.

func WriteYAMLConfigFile

func WriteYAMLConfigFile(t *testing.T, dir string, content map[string]any) string

WriteYAMLConfigFile marshals content as YAML and writes it to dir/config.yaml. Returns the full path for use with --config or QDRANT_CLOUD_CONFIG.

Types

type FakeBackupService added in v0.2.0

type FakeBackupService struct {
	backupv1.UnimplementedBackupServiceServer

	ListBackupsFunc          func(context.Context, *backupv1.ListBackupsRequest) (*backupv1.ListBackupsResponse, error)
	GetBackupFunc            func(context.Context, *backupv1.GetBackupRequest) (*backupv1.GetBackupResponse, error)
	CreateBackupFunc         func(context.Context, *backupv1.CreateBackupRequest) (*backupv1.CreateBackupResponse, error)
	DeleteBackupFunc         func(context.Context, *backupv1.DeleteBackupRequest) (*backupv1.DeleteBackupResponse, error)
	ListBackupRestoresFunc   func(context.Context, *backupv1.ListBackupRestoresRequest) (*backupv1.ListBackupRestoresResponse, error)
	RestoreBackupFunc        func(context.Context, *backupv1.RestoreBackupRequest) (*backupv1.RestoreBackupResponse, error)
	ListBackupSchedulesFunc  func(context.Context, *backupv1.ListBackupSchedulesRequest) (*backupv1.ListBackupSchedulesResponse, error)
	GetBackupScheduleFunc    func(context.Context, *backupv1.GetBackupScheduleRequest) (*backupv1.GetBackupScheduleResponse, error)
	CreateBackupScheduleFunc func(context.Context, *backupv1.CreateBackupScheduleRequest) (*backupv1.CreateBackupScheduleResponse, error)
	UpdateBackupScheduleFunc func(context.Context, *backupv1.UpdateBackupScheduleRequest) (*backupv1.UpdateBackupScheduleResponse, error)
	DeleteBackupScheduleFunc func(context.Context, *backupv1.DeleteBackupScheduleRequest) (*backupv1.DeleteBackupScheduleResponse, error)

	ListBackupsCalls          MethodSpy[*backupv1.ListBackupsRequest, *backupv1.ListBackupsResponse]
	GetBackupCalls            MethodSpy[*backupv1.GetBackupRequest, *backupv1.GetBackupResponse]
	CreateBackupCalls         MethodSpy[*backupv1.CreateBackupRequest, *backupv1.CreateBackupResponse]
	DeleteBackupCalls         MethodSpy[*backupv1.DeleteBackupRequest, *backupv1.DeleteBackupResponse]
	ListBackupRestoresCalls   MethodSpy[*backupv1.ListBackupRestoresRequest, *backupv1.ListBackupRestoresResponse]
	RestoreBackupCalls        MethodSpy[*backupv1.RestoreBackupRequest, *backupv1.RestoreBackupResponse]
	ListBackupSchedulesCalls  MethodSpy[*backupv1.ListBackupSchedulesRequest, *backupv1.ListBackupSchedulesResponse]
	GetBackupScheduleCalls    MethodSpy[*backupv1.GetBackupScheduleRequest, *backupv1.GetBackupScheduleResponse]
	CreateBackupScheduleCalls MethodSpy[*backupv1.CreateBackupScheduleRequest, *backupv1.CreateBackupScheduleResponse]
	UpdateBackupScheduleCalls MethodSpy[*backupv1.UpdateBackupScheduleRequest, *backupv1.UpdateBackupScheduleResponse]
	DeleteBackupScheduleCalls MethodSpy[*backupv1.DeleteBackupScheduleRequest, *backupv1.DeleteBackupScheduleResponse]
}

FakeBackupService is a test fake that implements BackupServiceServer. Set the function fields to control responses per test.

func (*FakeBackupService) CreateBackup added in v0.2.0

CreateBackup delegates to CreateBackupFunc if set, otherwise dispatches via CreateBackupCalls.

func (*FakeBackupService) CreateBackupSchedule added in v0.2.0

CreateBackupSchedule delegates to CreateBackupScheduleFunc if set, otherwise dispatches via CreateBackupScheduleCalls.

func (*FakeBackupService) DeleteBackup added in v0.2.0

DeleteBackup delegates to DeleteBackupFunc if set, otherwise dispatches via DeleteBackupCalls.

func (*FakeBackupService) DeleteBackupSchedule added in v0.2.0

DeleteBackupSchedule delegates to DeleteBackupScheduleFunc if set, otherwise dispatches via DeleteBackupScheduleCalls.

func (*FakeBackupService) GetBackup added in v0.2.0

GetBackup delegates to GetBackupFunc if set, otherwise dispatches via GetBackupCalls.

func (*FakeBackupService) GetBackupSchedule added in v0.2.0

GetBackupSchedule delegates to GetBackupScheduleFunc if set, otherwise dispatches via GetBackupScheduleCalls.

func (*FakeBackupService) ListBackupRestores added in v0.2.0

ListBackupRestores delegates to ListBackupRestoresFunc if set, otherwise dispatches via ListBackupRestoresCalls.

func (*FakeBackupService) ListBackupSchedules added in v0.2.0

ListBackupSchedules delegates to ListBackupSchedulesFunc if set, otherwise dispatches via ListBackupSchedulesCalls.

func (*FakeBackupService) ListBackups added in v0.2.0

ListBackups delegates to ListBackupsFunc if set, otherwise dispatches via ListBackupsCalls.

func (*FakeBackupService) RestoreBackup added in v0.2.0

RestoreBackup delegates to RestoreBackupFunc if set, otherwise dispatches via RestoreBackupCalls.

func (*FakeBackupService) UpdateBackupSchedule added in v0.2.0

UpdateBackupSchedule delegates to UpdateBackupScheduleFunc if set, otherwise dispatches via UpdateBackupScheduleCalls.

type FakeBookingService

FakeBookingService is a test fake that implements BookingServiceServer. Set the function fields to control responses per test.

func (*FakeBookingService) ListPackages

ListPackages delegates to ListPackagesFunc if set, otherwise dispatches via ListPackagesCalls.

type FakeClusterService

type FakeClusterService struct {
	clusterv1.UnimplementedClusterServiceServer

	ListClustersFunc       func(context.Context, *clusterv1.ListClustersRequest) (*clusterv1.ListClustersResponse, error)
	GetClusterFunc         func(context.Context, *clusterv1.GetClusterRequest) (*clusterv1.GetClusterResponse, error)
	CreateClusterFunc      func(context.Context, *clusterv1.CreateClusterRequest) (*clusterv1.CreateClusterResponse, error)
	UpdateClusterFunc      func(context.Context, *clusterv1.UpdateClusterRequest) (*clusterv1.UpdateClusterResponse, error)
	DeleteClusterFunc      func(context.Context, *clusterv1.DeleteClusterRequest) (*clusterv1.DeleteClusterResponse, error)
	RestartClusterFunc     func(context.Context, *clusterv1.RestartClusterRequest) (*clusterv1.RestartClusterResponse, error)
	SuspendClusterFunc     func(context.Context, *clusterv1.SuspendClusterRequest) (*clusterv1.SuspendClusterResponse, error)
	UnsuspendClusterFunc   func(context.Context, *clusterv1.UnsuspendClusterRequest) (*clusterv1.UnsuspendClusterResponse, error)
	SuggestClusterNameFunc func(context.Context, *clusterv1.SuggestClusterNameRequest) (*clusterv1.SuggestClusterNameResponse, error)
	ListQdrantReleasesFunc func(context.Context, *clusterv1.ListQdrantReleasesRequest) (*clusterv1.ListQdrantReleasesResponse, error)

	ListClustersCalls       MethodSpy[*clusterv1.ListClustersRequest, *clusterv1.ListClustersResponse]
	GetClusterCalls         MethodSpy[*clusterv1.GetClusterRequest, *clusterv1.GetClusterResponse]
	CreateClusterCalls      MethodSpy[*clusterv1.CreateClusterRequest, *clusterv1.CreateClusterResponse]
	UpdateClusterCalls      MethodSpy[*clusterv1.UpdateClusterRequest, *clusterv1.UpdateClusterResponse]
	DeleteClusterCalls      MethodSpy[*clusterv1.DeleteClusterRequest, *clusterv1.DeleteClusterResponse]
	RestartClusterCalls     MethodSpy[*clusterv1.RestartClusterRequest, *clusterv1.RestartClusterResponse]
	SuspendClusterCalls     MethodSpy[*clusterv1.SuspendClusterRequest, *clusterv1.SuspendClusterResponse]
	UnsuspendClusterCalls   MethodSpy[*clusterv1.UnsuspendClusterRequest, *clusterv1.UnsuspendClusterResponse]
	SuggestClusterNameCalls MethodSpy[*clusterv1.SuggestClusterNameRequest, *clusterv1.SuggestClusterNameResponse]
	ListQdrantReleasesCalls MethodSpy[*clusterv1.ListQdrantReleasesRequest, *clusterv1.ListQdrantReleasesResponse]
}

FakeClusterService is a test fake that implements ClusterServiceServer. Set the function fields to control responses per test.

func (*FakeClusterService) CreateCluster

CreateCluster delegates to CreateClusterFunc if set, otherwise dispatches via CreateClusterCalls.

func (*FakeClusterService) DeleteCluster

DeleteCluster delegates to DeleteClusterFunc if set, otherwise dispatches via DeleteClusterCalls.

func (*FakeClusterService) GetCluster

GetCluster delegates to GetClusterFunc if set, otherwise dispatches via GetClusterCalls.

func (*FakeClusterService) ListClusters

ListClusters delegates to ListClustersFunc if set, otherwise dispatches via ListClustersCalls.

func (*FakeClusterService) ListQdrantReleases

ListQdrantReleases delegates to ListQdrantReleasesFunc if set, otherwise dispatches via ListQdrantReleasesCalls.

func (*FakeClusterService) RestartCluster

RestartCluster delegates to RestartClusterFunc if set, otherwise dispatches via RestartClusterCalls.

func (*FakeClusterService) SuggestClusterName

SuggestClusterName delegates to SuggestClusterNameFunc if set, otherwise dispatches via SuggestClusterNameCalls.

func (*FakeClusterService) SuspendCluster

SuspendCluster delegates to SuspendClusterFunc if set, otherwise dispatches via SuspendClusterCalls.

func (*FakeClusterService) UnsuspendCluster

UnsuspendCluster delegates to UnsuspendClusterFunc if set, otherwise dispatches via UnsuspendClusterCalls.

func (*FakeClusterService) UpdateCluster

UpdateCluster delegates to UpdateClusterFunc if set, otherwise dispatches via UpdateClusterCalls.

type FakeDatabaseApiKeyService

FakeDatabaseApiKeyService is a test fake that implements DatabaseApiKeyServiceServer. Set the function fields to control responses per test.

func (*FakeDatabaseApiKeyService) CreateDatabaseApiKey

CreateDatabaseApiKey delegates to CreateDatabaseApiKeyFunc if set, otherwise dispatches via CreateDatabaseApiKeyCalls.

func (*FakeDatabaseApiKeyService) DeleteDatabaseApiKey

DeleteDatabaseApiKey delegates to DeleteDatabaseApiKeyFunc if set, otherwise dispatches via DeleteDatabaseApiKeyCalls.

func (*FakeDatabaseApiKeyService) ListDatabaseApiKeys

ListDatabaseApiKeys delegates to ListDatabaseApiKeysFunc if set, otherwise dispatches via ListDatabaseApiKeysCalls.

type FakePlatformService

FakePlatformService is a test fake that implements PlatformServiceServer. Set the function fields to control responses per test.

func (*FakePlatformService) ListCloudProviderRegions

ListCloudProviderRegions delegates to ListCloudProviderRegionsFunc if set, otherwise dispatches via ListCloudProviderRegionsCalls.

func (*FakePlatformService) ListCloudProviders

ListCloudProviders delegates to ListCloudProvidersFunc if set, otherwise dispatches via ListCloudProvidersCalls.

type MethodSpy added in v0.3.0

type MethodSpy[Req, Resp any] struct {
	// contains filtered or unexported fields
}

MethodSpy records calls to a single RPC method and optionally dispatches to per-call or fallback handlers. Use the *Calls fields on fake services instead of managing call counters and captured requests manually.

Priority when handling a call: *Func field > OnCall handler > Always handler > Unimplemented default.

func (*MethodSpy[Req, Resp]) All added in v0.3.0

func (m *MethodSpy[Req, Resp]) All() []Req

All returns a copy of all captured requests in call order.

func (*MethodSpy[Req, Resp]) Always added in v0.3.0

func (m *MethodSpy[Req, Resp]) Always(fn func(context.Context, Req) (Resp, error)) *MethodSpy[Req, Resp]

Always sets a fallback handler invoked for every call that has no matching OnCall entry. If neither OnCall nor Always is set the method falls back to the gRPC Unimplemented default.

func (*MethodSpy[Req, Resp]) Count added in v0.3.0

func (m *MethodSpy[Req, Resp]) Count() int

Count returns how many times the method has been called.

func (*MethodSpy[Req, Resp]) Last added in v0.3.0

func (m *MethodSpy[Req, Resp]) Last() (Req, bool)

Last returns the most recent request and true, or the zero value and false if never called.

func (*MethodSpy[Req, Resp]) OnCall added in v0.3.0

func (m *MethodSpy[Req, Resp]) OnCall(i int, fn func(context.Context, Req) (Resp, error)) *MethodSpy[Req, Resp]

OnCall registers a handler for the i-th call (0-indexed). Chainable.

func (*MethodSpy[Req, Resp]) Reset added in v0.3.0

func (m *MethodSpy[Req, Resp]) Reset()

Reset clears captured requests and all registered handlers.

func (*MethodSpy[Req, Resp]) Returns added in v0.3.0

func (m *MethodSpy[Req, Resp]) Returns(resp Resp, err error) *MethodSpy[Req, Resp]

Returns sets a fixed response returned for every call (shorthand for Always with a constant return).

type Option

type Option func(*envConfig)

Option configures a TestEnv.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the API key used by the test client's auth interceptor.

func WithAccountID

func WithAccountID(id string) Option

WithAccountID sets the default account ID pre-configured on the test state.

func WithVersion

func WithVersion(v string) Option

WithVersion sets the CLI version used in the user-agent header.

type RequestCapture

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

RequestCapture is a server-side unary interceptor that records incoming metadata.

func (*RequestCapture) Last

func (rc *RequestCapture) Last() metadata.MD

Last returns the metadata from the most recent request.

type TestEnv

type TestEnv struct {
	State                *state.State
	Server               *FakeClusterService
	BookingServer        *FakeBookingService
	PlatformServer       *FakePlatformService
	DatabaseApiKeyServer *FakeDatabaseApiKeyService
	BackupServer         *FakeBackupService
	Capture              *RequestCapture
	Cleanup              func()
}

TestEnv bundles everything a test needs.

func NewBareTestEnv

func NewBareTestEnv(t *testing.T) *TestEnv

NewBareTestEnv creates a test environment with a bufconn-backed gRPC server but with no config values pre-populated in viper. Use this when the test itself controls how config is loaded — for example, to verify that account_id is read from a config file, an environment variable, or a CLI flag.

func NewTestEnv

func NewTestEnv(t *testing.T, opts ...Option) *TestEnv

NewTestEnv creates a test environment with a bufconn-backed gRPC server and a pre-populated config. account_id and api_key are set via the highest viper priority (Set), so they reliably override any machine environment variables. Use this for testing command behaviour where a valid account ID is needed but its specific source doesn't matter. Defaults: account_id="test-account-id". Override with WithAccountID / WithAPIKey.

Jump to

Keyboard shortcuts

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