testutil

package
v0.2.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

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.

func (*FakeBackupService) CreateBackupSchedule added in v0.2.0

CreateBackupSchedule delegates to CreateBackupScheduleFunc if set.

func (*FakeBackupService) DeleteBackup added in v0.2.0

DeleteBackup delegates to DeleteBackupFunc if set.

func (*FakeBackupService) DeleteBackupSchedule added in v0.2.0

DeleteBackupSchedule delegates to DeleteBackupScheduleFunc if set.

func (*FakeBackupService) GetBackup added in v0.2.0

GetBackup delegates to GetBackupFunc if set.

func (*FakeBackupService) GetBackupSchedule added in v0.2.0

GetBackupSchedule delegates to GetBackupScheduleFunc if set.

func (*FakeBackupService) ListBackupRestores added in v0.2.0

ListBackupRestores delegates to ListBackupRestoresFunc if set.

func (*FakeBackupService) ListBackupSchedules added in v0.2.0

ListBackupSchedules delegates to ListBackupSchedulesFunc if set.

func (*FakeBackupService) ListBackups added in v0.2.0

ListBackups delegates to ListBackupsFunc if set.

func (*FakeBackupService) RestoreBackup added in v0.2.0

RestoreBackup delegates to RestoreBackupFunc if set.

func (*FakeBackupService) UpdateBackupSchedule added in v0.2.0

UpdateBackupSchedule delegates to UpdateBackupScheduleFunc if set.

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.

type FakeClusterService

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.

func (*FakeClusterService) DeleteCluster

DeleteCluster delegates to DeleteClusterFunc if set.

func (*FakeClusterService) GetCluster

GetCluster delegates to GetClusterFunc if set.

func (*FakeClusterService) ListClusters

ListClusters delegates to ListClustersFunc if set.

func (*FakeClusterService) ListQdrantReleases

ListQdrantReleases delegates to ListQdrantReleasesFunc if set.

func (*FakeClusterService) RestartCluster

RestartCluster delegates to RestartClusterFunc if set.

func (*FakeClusterService) SuggestClusterName

SuggestClusterName delegates to SuggestClusterNameFunc if set.

func (*FakeClusterService) SuspendCluster

SuspendCluster delegates to SuspendClusterFunc if set.

func (*FakeClusterService) UnsuspendCluster

UnsuspendCluster delegates to UnsuspendClusterFunc if set.

func (*FakeClusterService) UpdateCluster

UpdateCluster delegates to UpdateClusterFunc if set.

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.

func (*FakeDatabaseApiKeyService) DeleteDatabaseApiKey

DeleteDatabaseApiKey delegates to DeleteDatabaseApiKeyFunc if set.

func (*FakeDatabaseApiKeyService) ListDatabaseApiKeys

ListDatabaseApiKeys delegates to ListDatabaseApiKeysFunc if set.

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.

func (*FakePlatformService) ListCloudProviders

ListCloudProviders delegates to ListCloudProvidersFunc if set.

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