runtime

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package runtime exposes process and timing dependencies for command tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrLocalNotRunning = errors.New("local development is not running; run 'volcano start' to launch it, or use 'volcano cloud <command>' to target your cloud project")

ErrLocalNotRunning signals that a command needs the local Volcano stack but it isn't up (the server container is absent or stopped). It is already user-actionable, so callers surface it verbatim instead of burying it under a generic wrapper like "failed to load config".

Functions

func CommandPath added in v0.0.3

func CommandPath(deps Deps, command string) string

CommandPath returns a user-facing command path for the current command tree.

func OpenBrowser

func OpenBrowser(deps Deps, rawURL string) error

OpenBrowser opens rawURL through the configured browser hook or OpenURL.

func OpenURL

func OpenURL(rawURL string) error

OpenURL opens rawURL in the platform default browser. It refuses any non-http(s) URL so a malicious or misconfigured backend can't make the CLI hand file://, custom-scheme, or flag-like values to open/xdg-open/rundll32.

Types

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, name string, args ...string) ([]byte, error)
}

CommandRunner runs an external command.

type CommandRunnerFunc added in v0.0.2

type CommandRunnerFunc func(ctx context.Context, name string, args ...string) ([]byte, error)

CommandRunnerFunc adapts a function to CommandRunner.

func (CommandRunnerFunc) Run added in v0.0.2

func (f CommandRunnerFunc) Run(ctx context.Context, name string, args ...string) ([]byte, error)

Run calls f(ctx, name, args...).

type Deps

type Deps struct {
	HTTPClient apiclient.HttpRequestDoer
	// APIBaseURL overrides the compiled cloud API URL for tests. Synthetic
	// local configs supply their API URL through ConfigLoader instead.
	APIBaseURL   string
	OpenBrowser  func(string) error
	NewTimer     func(time.Duration) Timer
	NewTicker    func(time.Duration) Ticker
	ConfigLoader func() (*config.Config, error)
	// LocalMode makes session-built API clients send no credential. Local mode
	// is a single-tenant sandbox; the local server defaults an absent credential
	// to the pre-provisioned local user. Set by the local command wiring.
	LocalMode           bool
	LocalCommandRunner  CommandRunner
	UpdateCommandRunner CommandRunner
	GitCommandRunner    CommandRunner
	ExecutablePath      string
	UpdateGitHubAPIURL  string
	CommandPathPrefix   string
	// DocsCacheDir overrides the base cache directory used by `volcano docs`.
	// Empty uses os.UserCacheDir()/volcano. Tests inject a t.TempDir().
	DocsCacheDir string
	// DocsGitHubAPIURL overrides the GitHub API base (default
	// https://api.github.com) for docs sync. Tests point this at an httptest
	// server.
	DocsGitHubAPIURL string
	// DocsRawBaseURL selects raw-host downloads (e.g.
	// https://raw.githubusercontent.com) for public sources. It is empty by
	// default: downloads then go through the authenticated GitHub contents API
	// (which also works for private repos). Tests may point it at an httptest
	// server to exercise the raw-host path.
	DocsRawBaseURL string
	// Now overrides the wall clock for deterministic freshness/staleness tests.
	Now func() time.Time
}

Deps captures runtime dependencies that command and service tests replace.

type Ticker

type Ticker interface {
	C() <-chan time.Time
	Reset(time.Duration)
	Stop()
}

Ticker is the subset of time.Ticker used by command services.

func NewTicker

func NewTicker(deps Deps, duration time.Duration) Ticker

NewTicker returns the configured test ticker or a real time.Ticker wrapper.

type Timer

type Timer interface {
	C() <-chan time.Time
	Stop()
}

Timer is the subset of time.Timer used by command services.

func NewTimer

func NewTimer(deps Deps, duration time.Duration) Timer

NewTimer returns the configured test timer or a real time.Timer wrapper.

Jump to

Keyboard shortcuts

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