testutil

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 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

FakeBackupService is a test fake that implements BackupServiceServer. Use the *Calls fields to configure responses and inspect captured requests.

func (*FakeBackupService) CreateBackup added in v0.2.0

CreateBackup records the call and dispatches via CreateBackupCalls.

func (*FakeBackupService) CreateBackupSchedule added in v0.2.0

CreateBackupSchedule records the call and dispatches via CreateBackupScheduleCalls.

func (*FakeBackupService) DeleteBackup added in v0.2.0

DeleteBackup records the call and dispatches via DeleteBackupCalls.

func (*FakeBackupService) DeleteBackupSchedule added in v0.2.0

DeleteBackupSchedule records the call and dispatches via DeleteBackupScheduleCalls.

func (*FakeBackupService) GetBackup added in v0.2.0

GetBackup records the call and dispatches via GetBackupCalls.

func (*FakeBackupService) GetBackupSchedule added in v0.2.0

GetBackupSchedule records the call and dispatches via GetBackupScheduleCalls.

func (*FakeBackupService) ListBackupRestores added in v0.2.0

ListBackupRestores records the call and dispatches via ListBackupRestoresCalls.

func (*FakeBackupService) ListBackupSchedules added in v0.2.0

ListBackupSchedules records the call and dispatches via ListBackupSchedulesCalls.

func (*FakeBackupService) ListBackups added in v0.2.0

ListBackups records the call and dispatches via ListBackupsCalls.

func (*FakeBackupService) RestoreBackup added in v0.2.0

RestoreBackup records the call and dispatches via RestoreBackupCalls.

func (*FakeBackupService) UpdateBackupSchedule added in v0.2.0

UpdateBackupSchedule records the call and dispatches via UpdateBackupScheduleCalls.

type FakeBookingService

FakeBookingService is a test fake that implements BookingServiceServer. Use the *Calls fields to configure responses and inspect captured requests.

func (*FakeBookingService) GetPackage added in v0.4.1

GetPackage records the call and dispatches via GetPackageCalls.

func (*FakeBookingService) ListPackages

ListPackages records the call and dispatches via ListPackagesCalls.

type FakeClusterService

FakeClusterService is a test fake that implements ClusterServiceServer. Use the *Calls fields to configure responses and inspect captured requests.

func (*FakeClusterService) CreateCluster

CreateCluster records the call and dispatches via CreateClusterCalls.

func (*FakeClusterService) DeleteCluster

DeleteCluster records the call and dispatches via DeleteClusterCalls.

func (*FakeClusterService) GetCluster

GetCluster records the call and dispatches via GetClusterCalls.

func (*FakeClusterService) ListClusters

ListClusters records the call and dispatches via ListClustersCalls.

func (*FakeClusterService) ListQdrantReleases

ListQdrantReleases records the call and dispatches via ListQdrantReleasesCalls.

func (*FakeClusterService) RestartCluster

RestartCluster records the call and dispatches via RestartClusterCalls.

func (*FakeClusterService) SuggestClusterName

SuggestClusterName records the call and dispatches via SuggestClusterNameCalls.

func (*FakeClusterService) SuspendCluster

SuspendCluster records the call and dispatches via SuspendClusterCalls.

func (*FakeClusterService) UnsuspendCluster

UnsuspendCluster records the call and dispatches via UnsuspendClusterCalls.

func (*FakeClusterService) UpdateCluster

UpdateCluster records the call and dispatches via UpdateClusterCalls.

type FakeDatabaseApiKeyService

FakeDatabaseApiKeyService is a test fake that implements DatabaseApiKeyServiceServer. Use the *Calls fields to configure responses and inspect captured requests.

func (*FakeDatabaseApiKeyService) CreateDatabaseApiKey

CreateDatabaseApiKey records the call and dispatches via CreateDatabaseApiKeyCalls.

func (*FakeDatabaseApiKeyService) DeleteDatabaseApiKey

DeleteDatabaseApiKey records the call and dispatches via DeleteDatabaseApiKeyCalls.

func (*FakeDatabaseApiKeyService) ListDatabaseApiKeys

ListDatabaseApiKeys records the call and dispatches via ListDatabaseApiKeysCalls.

type FakePlatformService

FakePlatformService is a test fake that implements PlatformServiceServer. Use the *Calls fields to configure responses and inspect captured requests.

func (*FakePlatformService) ListCloudProviderRegions

ListCloudProviderRegions records the call and dispatches via ListCloudProviderRegionsCalls.

func (*FakePlatformService) ListCloudProviders

ListCloudProviders records the call and 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