Documentation
¶
Index ¶
- Variables
- func CleanupGCSPrefix(t *testing.T, bucket, prefix string)
- func CleanupTestSpinnerDirs() error
- func ComputeConfigHash(project, zone, bucket string) string
- func DockerContainerExists(t *testing.T, name string) bool
- func DockerContainerRunning(t *testing.T, name string) bool
- func DockerImageExists(t *testing.T, image string) bool
- func EnsureDockerRunning(t *testing.T)
- func ExecInContainer(t *testing.T, containerName string, command ...string) string
- func GCPImageExists(t *testing.T, project, name string) bool
- func GCPInstanceExists(t *testing.T, project, zone, name string) bool
- func GCPInstanceMetadata(t *testing.T, project, zone, name, key string) (string, bool)
- func GCPInstanceStatus(t *testing.T, project, zone, name string) string
- func GCSObjectExists(t *testing.T, bucket, object string) bool
- func GenerateSharedImageName(version int, project, zone, bucket string) string
- func GenerateTestContainerName(t *testing.T) string
- func GenerateTestImageName(t *testing.T) string
- func GenerateTestImageTag(t *testing.T) string
- func GetBinaryPath() string
- func GetImageLabels(t *testing.T, project, imageName string) map[string]string
- func GetSharedGCPImage(t *testing.T) string
- func IsDockerAvailable() bool
- func OverrideSecretStoreWithRealToken(githubToken string) (cleanup func(), err error)
- func ReadGCSObject(t *testing.T, bucket, object string) []byte
- func RemoveDockerContainer(t *testing.T, name string)
- func RemoveDockerImage(t *testing.T, image string)
- func RemoveGCPImage(t *testing.T, project, name string)
- func RemoveGCPInstance(t *testing.T, project, zone, name string)
- func RunCommand(t *testing.T, args ...string) (stdout string, stderr string, exitCode int)
- func RunCommandExpectError(t *testing.T, args ...string) (stdout string, stderr string, exitCode int)
- func RunCommandExpectSuccess(t *testing.T, args ...string) (stdout string, stderr string)
- func RunCommandWithEnv(t *testing.T, env map[string]string, args ...string) (stdout string, stderr string, exitCode int)
- func RunContainerWithImage(t *testing.T, imageName string) string
- func RunGCPSpinCommand(t *testing.T, args ...string) (instanceName string, stdout string, stderr string)
- func RunSpinCommand(t *testing.T, args ...string) (containerName string, stdout string, stderr string)
- func SetSharedBinaryAccessor(accessor func() string)
- func SetSharedImageAccessor(accessor func() string)
- func SetupTestImage(t *testing.T, setupArgs ...string) (imageTag string, imageName string)
- func SetupTestSecretStore() (cleanup func(), err error)
- func SkipIfDockerNotAvailable(t *testing.T)
- func Sleep(t *testing.T, seconds int)
- func StopGCPInstance(t *testing.T, project, zone, name string)
- func ValidateSharedImage(t *testing.T, project, imageName, expectedHash string) bool
- func WaitForGCPInstanceStatus(t *testing.T, project, zone, instanceName, expectedStatus string, ...)
- func WaitForGCSStateStatus(t *testing.T, bucket, instanceName, expectedStatus string, timeoutSec int)
- func WriteFile(t *testing.T, path string, content string) error
- func WriteGCSObject(t *testing.T, bucket, object string, data []byte)
- type GCPTestConfig
Constants ¶
This section is empty.
Variables ¶
var BinaryPath = "../../dist/spinner"
BinaryPath is the path to the compiled test binary
Functions ¶
func CleanupGCSPrefix ¶
CleanupGCSPrefix removes all objects under a given prefix in a GCS bucket. Used to clean up state/log objects created during tests.
func CleanupTestSpinnerDirs ¶
func CleanupTestSpinnerDirs() error
CleanupTestSpinnerDirs removes all test-related spinner data directories. Matches directories containing "-test-" in the name (e.g., spinner-dockerfile-test-hello-world). This is intended to be called from TestMain for global cleanup after all tests.
func ComputeConfigHash ¶
ComputeConfigHash generates an 8-character hash from bake configuration. This hash ensures that images created with different configs get different names.
func DockerContainerExists ¶
DockerContainerExists checks if a container exists (running or stopped)
func DockerContainerRunning ¶
DockerContainerRunning checks if a container is currently running
func DockerImageExists ¶
DockerImageExists checks if a Docker image exists
func EnsureDockerRunning ¶
EnsureDockerRunning checks that Docker daemon is accessible
func ExecInContainer ¶
ExecInContainer runs a command in a container and returns the output
func GCPImageExists ¶
GCPImageExists checks if a GCP Compute Engine image exists.
func GCPInstanceExists ¶
GCPInstanceExists checks if a GCP VM instance exists using gcloud CLI. Returns true if the instance exists (any state), false if not found.
func GCPInstanceMetadata ¶
GCPInstanceMetadata returns the value of a specific metadata key for a GCP VM instance. Returns the value and true if found, empty string and false if not found.
func GCPInstanceStatus ¶
GCPInstanceStatus returns the status of a GCP VM instance (e.g., "RUNNING", "TERMINATED"). Returns empty string if the instance doesn't exist.
func GCSObjectExists ¶
GCSObjectExists checks whether a GCS object exists.
func GenerateSharedImageName ¶
GenerateSharedImageName creates a deterministic image name based on version and config. Format: test-shared-v{version}-{hash} Version allows manual invalidation on major changes, hash ensures config match.
func GenerateTestContainerName ¶
GenerateTestContainerName creates a unique Docker container name for testing
func GenerateTestImageName ¶
GenerateTestImageName creates a unique GCP image name for testing. Format: spinner-test-<timestamp> (valid GCP image name).
func GenerateTestImageTag ¶
GenerateTestImageTag creates a unique Docker image tag for testing Returns just the tag part (without the "spinner:" prefix) Use this with the setup command's --name flag
func GetBinaryPath ¶
func GetBinaryPath() string
GetBinaryPath returns the path to the compiled spinner binary. If TestMain has built a shared binary, it returns that path. Otherwise, it falls back to the default BinaryPath.
func GetImageLabels ¶
GetImageLabels retrieves labels from a GCP Compute Engine image using gcloud CLI. Returns empty map if image doesn't exist or has no labels.
func GetSharedGCPImage ¶
GetSharedGCPImage returns the shared test image name created in TestMain. This is the preferred method for GCP integration tests to avoid recreating images (which takes 35+ minutes each).
The shared image is created once before all tests run and deleted after all tests complete. Individual tests create separate VM instances from this shared image, ensuring test isolation.
func IsDockerAvailable ¶
func IsDockerAvailable() bool
IsDockerAvailable returns true if the Docker daemon is accessible.
func OverrideSecretStoreWithRealToken ¶
OverrideSecretStoreWithRealToken creates a temporary secret store using the provided real GITHUB_TOKEN and a placeholder CLAUDE_CODE_OAUTH_TOKEN, then overrides SPINNER_SECRET_STORE and SPINNER_SECRET_PASSPHRASE for the caller's process. This is intended for tests that need to authenticate against GitHub with a real token. The returned cleanup function restores the previous env values.
func ReadGCSObject ¶
ReadGCSObject reads the full contents of a GCS object.
func RemoveDockerContainer ¶
RemoveDockerContainer removes a Docker container if it exists
func RemoveDockerImage ¶
RemoveDockerImage removes a Docker image if it exists
func RemoveGCPImage ¶
RemoveGCPImage deletes a GCP Compute Engine image if it exists.
func RemoveGCPInstance ¶
RemoveGCPInstance deletes a GCP VM instance if it exists.
func RunCommand ¶
RunCommand executes the spinner CLI with given arguments and returns output
func RunCommandExpectError ¶
func RunCommandExpectError(t *testing.T, args ...string) (stdout string, stderr string, exitCode int)
RunCommandExpectError runs a command and requires it to fail
func RunCommandExpectSuccess ¶
RunCommandExpectSuccess runs a command and requires it to succeed
func RunCommandWithEnv ¶
func RunCommandWithEnv(t *testing.T, env map[string]string, args ...string) (stdout string, stderr string, exitCode int)
RunCommandWithEnv executes the spinner CLI with custom environment variables
func RunContainerWithImage ¶
RunContainerWithImage starts a container with the given image and returns the container name
func RunGCPSpinCommand ¶
func RunGCPSpinCommand(t *testing.T, args ...string) (instanceName string, stdout string, stderr string)
RunGCPSpinCommand executes the spin command with GCP backend and returns the instance name from output.
func RunSpinCommand ¶
func RunSpinCommand(t *testing.T, args ...string) (containerName string, stdout string, stderr string)
RunSpinCommand executes the spin command and returns the container name from output
func SetSharedBinaryAccessor ¶
func SetSharedBinaryAccessor(accessor func() string)
SetSharedBinaryAccessor allows the integration package to register its binary accessor.
func SetSharedImageAccessor ¶
func SetSharedImageAccessor(accessor func() string)
SetSharedImageAccessor allows the integration package to register its image accessor. This is called from init() in the integration package.
func SetupTestImage ¶
SetupTestImage creates a test image with the given setup args and sets up cleanup. The CLI binary is built once in TestMain and reused across all tests.
func SetupTestSecretStore ¶
func SetupTestSecretStore() (cleanup func(), err error)
SetupTestSecretStore creates a temporary encrypted secret store populated with test tokens required by `spinner spin` (GITHUB_TOKEN, CLAUDE_CODE_OAUTH_TOKEN). It also writes an empty .spinner.json config file and sets SPINNER_CONFIG_FILE so that test subprocesses do not inherit the developer's ~/.spinner.json defaults (e.g. model=...) that would cause test assertions to fail.
Sets the following in the test process environment (inherited by subprocesses):
- SPINNER_SECRET_STORE — path to the temp store file
- SPINNER_SECRET_PASSPHRASE — passphrase for the temp store
- SPINNER_CONFIG_FILE — path to an empty .spinner.json (overrides config search)
Returns a cleanup function that removes temp files and restores env vars.
func SkipIfDockerNotAvailable ¶
SkipIfDockerNotAvailable skips the test if Docker is not available
func StopGCPInstance ¶
StopGCPInstance stops a running GCP VM instance.
func ValidateSharedImage ¶
ValidateSharedImage checks if an existing image matches the expected configuration. Returns true if the image exists AND has a matching spinner-config-hash label.
func WaitForGCPInstanceStatus ¶
func WaitForGCPInstanceStatus(t *testing.T, project, zone, instanceName, expectedStatus string, timeoutSec int)
WaitForGCPInstanceStatus polls VM status until it reaches the expected status or timeout.
func WaitForGCSStateStatus ¶
func WaitForGCSStateStatus(t *testing.T, bucket, instanceName, expectedStatus string, timeoutSec int)
WaitForGCSStateStatus polls GCS state.json until it reaches the expected status or timeout.
Types ¶
type GCPTestConfig ¶
GCPTestConfig holds the resolved configuration for GCP integration tests.
func GCPTestConfigFromEnv ¶
func GCPTestConfigFromEnv() *GCPTestConfig
GCPTestConfigFromEnv reads GCP test configuration from environment variables. Returns nil if any required variable is missing.
func SkipIfGCPNotAvailable ¶
func SkipIfGCPNotAvailable(t *testing.T) *GCPTestConfig
SkipIfGCPNotAvailable skips the test if GCP credentials or configuration are not available. It checks:
- Not in short mode
- Required env vars are set (SPINNER_TEST_GCP_PROJECT, SPINNER_TEST_GCP_BUCKET)
- Application Default Credentials (ADC) are available