testutils

package
v2.16.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunFakeSSHIfRequested added in v2.16.2

func RunFakeSSHIfRequested()

RunFakeSSHIfRequested acts as `ssh -G` and exits when this test binary was started as the fake ssh installed by StubSSH, that is, when it runs under the name ssh with the fake's responses set. Otherwise it returns, so other re-execs of the test binary are unaffected. Call it first in TestMain.

func StubConfig

func StubConfig(t *testing.T, cfgStr string)

StubConfig replaces the config.Read function with a function that returns a config object created from the given config string. It also sets up a cleanup function that restores the original config.Read function.

func StubSSH added in v2.16.2

func StubSSH(t *testing.T, responses map[string]SSHResponse)

StubSSH puts a fake ssh first on PATH. Its `ssh -G HOST` answers with responses[HOST], or reports HOST itself when unmapped, like ssh without a matching config. The fake is the running test binary, so the test package's TestMain must call RunFakeSSHIfRequested.

Types

type SSHResponse added in v2.16.2

type SSHResponse struct {
	// contains filtered or unexported fields
}

SSHResponse is how the fake ssh installed by StubSSH answers `ssh -G` for a host. Build one with SSHReportsHostname, SSHReportsNoHostname, or SSHFails. The zero value is invalid.

func SSHFails added in v2.16.2

func SSHFails() SSHResponse

SSHFails makes the fake ssh exit with an error for a host. It still prints a hostname first, so callers must honour the exit status rather than the output.

func SSHReportsHostname added in v2.16.2

func SSHReportsHostname(hostname string) SSHResponse

SSHReportsHostname makes the fake ssh report hostname for a host.

func SSHReportsNoHostname added in v2.16.2

func SSHReportsNoHostname() SSHResponse

SSHReportsNoHostname makes the fake ssh succeed without reporting a hostname for a host.

Jump to

Keyboard shortcuts

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