Documentation
¶
Overview ¶
Package doctor is nova-doctor's frame: a registry of checks, each one a name, the dependency it covers, a Run over an Env, and a result of ok, warn or fail with evidence and, when not ok, the one fix line. The contract is docs/SPEC-DOCTOR.md.
A check lives in its own file, check_<dependency>.go, and registers itself from an init, so a new dependency adds one file and edits nothing here. Every outside fact a check reads (a process, a file, a network address, the clock, the environment) comes through Env, so a test fakes all of them and no test starts a service or opens a socket.
Index ¶
- Variables
- func ExitCode(results []Result, strict bool) int
- func Main(reg *Registry, env Env, stamp string, args []string, stdin io.Reader, ...) int
- func Tool(reg *Registry, env Env, stamp string) *tool.Tool
- type Check
- type Env
- type OSEnv
- func (OSEnv) Dial(ctx context.Context, network, addr string) error
- func (OSEnv) Exec(ctx context.Context, name string, args ...string) (string, error)
- func (OSEnv) Getenv(k string) string
- func (OSEnv) Now() time.Time
- func (OSEnv) ReadDir(p string) ([]fs.DirEntry, error)
- func (OSEnv) ReadFile(p string) ([]byte, error)
- type Options
- type ProviderProbe
- type Registry
- type Result
- type Status
Constants ¶
This section is empty.
Variables ¶
var Default = NewRegistry()
Default is the registry the check_<dependency>.go files register into from an init.
Functions ¶
func ExitCode ¶
ExitCode is the exit by the worst result: 2 for a fail, 1 for a warn under strict, else 0 (docs/SPEC-DOCTOR.md, "The exit").
func Main ¶
func Main(reg *Registry, env Env, stamp string, args []string, stdin io.Reader, stdout, stderr io.Writer) int
Main runs nova-doctor over args. No arguments is refused at exit 2 with the verbs and `run: nova-doctor help` (pkg/tool's Run), never a run: a bare command is no invocation (docs/ONBOARDING.md point 1).
Types ¶
type Check ¶
type Check struct {
Name string
Dependency string
Fleet bool
Run func(ctx context.Context, env Env) Result
}
Check is one dependency's check. Fleet marks a check only a fleet needs: --local skips it and says so.
type Env ¶
type Env interface {
Getenv(key string) string
Now() time.Time
ReadFile(path string) ([]byte, error)
ReadDir(path string) ([]fs.DirEntry, error)
Exec(ctx context.Context, name string, args ...string) (string, error)
Dial(ctx context.Context, network, addr string) error
}
Env is everything a check may reach outside itself. Paths are the real ones in the real Env and a tree under t.TempDir() in a fake.
type OSEnv ¶
type OSEnv struct{}
OSEnv is the real Env: the process's environment, files, clock, children and network.
type Options ¶
type Options struct {
Only []string // check names; empty is every check
Local bool // skip the checks only a fleet needs
}
Options select which checks run.
type ProviderProbe ¶
type ProviderProbe interface {
// Models asks the provider for its models list with key, a call that costs nothing.
// errNoModels says the provider has no endpoint the probe knows.
Models(ctx context.Context, provider, key string) error
// Funds is the dollars the provider reports left, and whether it reports any; a
// provider that reports none is not judged on its funds.
Funds(ctx context.Context, provider, key string) (dollars float64, known bool, err error)
}
ProviderProbe is the outside call the providers check makes: the provider's no-cost models list and the funds it reports. Env may carry one (a test's fake); otherwise the check builds the real HTTP probe, so no test opens a socket.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the set of checks. Default is the one the checks register into.
type Result ¶
type Result struct {
Check string `json:"check"`
Dependency string `json:"dependency"`
Status Status `json:"status"`
Evidence string `json:"evidence"`
Fix string `json:"fix,omitempty"`
}
Result is what one check found. Fix is required when Status is not OK: a nova verb when one exists, never a hand script.