testutil

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 29 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 FakeAccountService added in v0.20.0

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

func (*FakeAccountService) CreateAccountInvite added in v0.20.0

CreateAccountInvite records the call and dispatches via CreateAccountInviteCalls.

func (*FakeAccountService) DeleteAccountInvite added in v0.20.0

DeleteAccountInvite records the call and dispatches via DeleteAccountInviteCalls.

func (*FakeAccountService) GetAccount added in v0.20.0

GetAccount records the call and dispatches via GetAccountCalls.

func (*FakeAccountService) GetAccountInvite added in v0.20.0

GetAccountInvite records the call and dispatches via GetAccountInviteCalls.

func (*FakeAccountService) GetAccountMember added in v0.20.0

GetAccountMember records the call and dispatches via GetAccountMemberCalls.

func (*FakeAccountService) ListAccountInvites added in v0.20.0

ListAccountInvites records the call and dispatches via ListAccountInvitesCalls.

func (*FakeAccountService) ListAccountMembers added in v0.20.0

ListAccountMembers records the call and dispatches via ListAccountMembersCalls.

func (*FakeAccountService) ListAccounts added in v0.20.0

ListAccounts records the call and dispatches via ListAccountsCalls.

func (*FakeAccountService) UpdateAccount added in v0.20.0

UpdateAccount records the call and dispatches via UpdateAccountCalls.

type FakeAuthService added in v0.19.0

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

func (*FakeAuthService) CreateManagementKey added in v0.19.0

CreateManagementKey records the call and dispatches via CreateManagementKeyCalls.

func (*FakeAuthService) DeleteManagementKey added in v0.19.0

DeleteManagementKey records the call and dispatches via DeleteManagementKeyCalls.

func (*FakeAuthService) ListManagementKeys added in v0.19.0

ListManagementKeys records the call and dispatches via ListManagementKeysCalls.

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) CreateClusterFromBackup added in v0.18.0

CreateClusterFromBackup records the call and dispatches via CreateClusterFromBackupCalls.

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 FakeHybridService added in v0.15.0

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

func (*FakeHybridService) CreateHybridCloudEnvironment added in v0.15.0

CreateHybridCloudEnvironment records the call and dispatches via CreateHybridCloudEnvironmentCalls.

func (*FakeHybridService) DeleteHybridCloudEnvironment added in v0.15.0

DeleteHybridCloudEnvironment records the call and dispatches via DeleteHybridCloudEnvironmentCalls.

func (*FakeHybridService) GenerateBootstrapCommands added in v0.15.0

GenerateBootstrapCommands records the call and dispatches via GenerateBootstrapCommandsCalls.

func (*FakeHybridService) GetHybridCloudEnvironment added in v0.15.0

GetHybridCloudEnvironment records the call and dispatches via GetHybridCloudEnvironmentCalls.

func (*FakeHybridService) ListHybridCloudEnvironments added in v0.15.0

ListHybridCloudEnvironments records the call and dispatches via ListHybridCloudEnvironmentsCalls.

func (*FakeHybridService) UpdateHybridCloudEnvironment added in v0.15.0

UpdateHybridCloudEnvironment records the call and dispatches via UpdateHybridCloudEnvironmentCalls.

type FakeIAMService added in v0.20.0

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

func (*FakeIAMService) AssignUserRoles added in v0.20.0

AssignUserRoles records the call and dispatches via AssignUserRolesCalls.

func (*FakeIAMService) CreateRole added in v0.20.0

CreateRole records the call and dispatches via CreateRoleCalls.

func (*FakeIAMService) DeleteRole added in v0.20.0

DeleteRole records the call and dispatches via DeleteRoleCalls.

func (*FakeIAMService) GetAuthenticatedUser added in v0.20.0

GetAuthenticatedUser records the call and dispatches via GetAuthenticatedUserCalls.

func (*FakeIAMService) GetRole added in v0.20.0

GetRole records the call and dispatches via GetRoleCalls.

func (*FakeIAMService) ListPermissions added in v0.20.0

ListPermissions records the call and dispatches via ListPermissionsCalls.

func (*FakeIAMService) ListRoles added in v0.20.0

ListRoles records the call and dispatches via ListRolesCalls.

func (*FakeIAMService) ListUserRoles added in v0.20.0

ListUserRoles records the call and dispatches via ListUserRolesCalls.

func (*FakeIAMService) ListUsers added in v0.20.0

ListUsers records the call and dispatches via ListUsersCalls.

func (*FakeIAMService) UpdateRole added in v0.20.0

UpdateRole records the call and dispatches via UpdateRoleCalls.

type FakeMonitoringService added in v0.17.0

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

func (*FakeMonitoringService) GetClusterLogs added in v0.17.0

GetClusterLogs records the call and dispatches via GetClusterLogsCalls.

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
	HybridServer         *FakeHybridService
	MonitoringServer     *FakeMonitoringService
	AuthServer           *FakeAuthService
	IAMServer            *FakeIAMService
	AccountServer        *FakeAccountService
	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