Documentation
¶
Index ¶
- Constants
- func AcquireGlobalTestLock(t *testing.T, name string)
- func AssertKubeProxy(t *testing.T, test *Test, localServerPort string, wantError bool)
- func AssertLogBufferBundleWithInfo(t *testing.T, buf *bytes.Buffer)
- func AssertLogBufferNoErrorBundle(t *testing.T, buf *bytes.Buffer)
- func AssertLogBufferWithErrorBundle(t *testing.T, buf *bytes.Buffer)
- func AssertParseFlagsHelp(t *testing.T, params AssertParseFlagsHelpParams)
- func CheckSkipSSHTest(t *testing.T, testName string)
- func CreateDefaultTestSettings(test *Test) settings.Settings
- func CreateDefaultTestSettingsWithAgent(test *Test, agentSockPath string) settings.Settings
- func CreateTestSettingNoDebug(test *Test) settings.Settings
- func DoGetRequest(url string, loop retry.Params, logger *PrefixLogger) (string, error)
- func FakeSession() *session.Session
- func GenerateID(names ...string) string
- func GenerateKeys(test *Test, passphrase string) (string, string, error)
- func GeneratePrivateKey(t *testing.T, passphrase string) string
- func GeneratePrivateKeyWithPublic(t *testing.T, passphrase string) (string, string)
- func GetTestLoopParamsForFailed() retry.Params
- func IncorrectHost() string
- func LogErrorOrAssert(t *testing.T, description string, err error, logger *slog.Logger)
- func Name(t *testing.T) string
- func PrepareFakeBashibleBundle(t *testing.T, test *Test, entrypoint, bundleDir string) string
- func Ptr[T any](v T) *T
- func RandInvalidPortExclude(_ []int) int
- func RandPassword(n int) string
- func RandPort() int
- func RandPortExclude(exclude []int) int
- func RandRange(min, max int) int
- func RandRangeExclude(min, max int, exclude []int) int
- func RandString(n int) string
- func RunDocker(command ...string) error
- func RunDockerWithOut(command ...string) (string, error)
- func Session(wrapper *TestContainerWrapper, overrides ...SessionOverride) *session.Session
- func SessionWithBastion(wrapper *TestContainerWrapper, bastionWrapper *TestContainerWrapper, ...) *session.Session
- func SetEnvs(t *testing.T, envs map[string]string)
- func Sleep(d time.Duration)
- func WaitPortFree(t *testing.T, port int)
- func WritePubKeyFileForPrivate(test *Test, privateKeyPath string, pubKey string) (string, error)
- type Agent
- type AssertParseFlagsHelpParams
- type ContainerSettings
- type HTTPHandler
- type HTTPServer
- type PrefixLogger
- type PrivateKey
- type PublicKey
- type SSHContainer
- func (c *SSHContainer) Connect() error
- func (c *SSHContainer) ContainerSettings() *ContainerSettings
- func (c *SSHContainer) CreateDeckhouseDirs() error
- func (c *SSHContainer) CreateDirectory(path string) error
- func (c *SSHContainer) Disconnect() error
- func (c *SSHContainer) DockerNetworkConnect(isDisconnect bool, name string) error
- func (c *SSHContainer) DownloadKubectl(version string) error
- func (c *SSHContainer) ExecToContainer(description string, command ...string) error
- func (c *SSHContainer) ExecToContainerWithOut(description string, command ...string) (string, error)
- func (c *SSHContainer) FailAndUpConnection(sleepBeforeConnect time.Duration) error
- func (c *SSHContainer) GetContainerIP() string
- func (c *SSHContainer) GetContainerId() string
- func (c *SSHContainer) GetNetwork() string
- func (c *SSHContainer) GetSSHDConfigPath() string
- func (c *SSHContainer) LocalPortString() string
- func (c *SSHContainer) RemotePort() int
- func (c *SSHContainer) RemotePortString() string
- func (c *SSHContainer) Restart(waitSSHDStarted bool, sleepBeforeStart time.Duration) error
- func (c *SSHContainer) ShortContainerId() string
- func (c *SSHContainer) SoftRestart(waitSSHDStarted bool, sleepBeforeStart time.Duration) error
- func (c *SSHContainer) Start(waitSSHDStarted bool) error
- func (c *SSHContainer) Stop() error
- func (c *SSHContainer) WithExternalNetwork(network string) *SSHContainer
- func (c *SSHContainer) WithVolumes(volumes ...Volume) *SSHContainer
- func (c *SSHContainer) WriteConfig() error
- type SessionOverride
- type Test
- func (s *Test) Cleanup(t *testing.T)
- func (s *Test) CreateFile(content string, executable bool, pathInTestDir ...string) (string, error)
- func (s *Test) CreateFileWithSameSuffix(sourceFile string, content string, executable bool, pathInTestDir ...string) (string, error)
- func (s *Test) CreateTmpFile(content string, executable bool, pathInTestDir ...string) (string, error)
- func (s *Test) FullName() string
- func (s *Test) FullNameForContainer() string
- func (s *Test) GenerateID(names ...string) string
- func (s *Test) GetID() string
- func (s *Test) GetLogger() *slog.Logger
- func (s *Test) IsZero() bool
- func (s *Test) MkSubDirs(dirs ...string) (string, error)
- func (s *Test) MustCreateFile(t *testing.T, content string, executable bool, pathInTestDir ...string) string
- func (s *Test) MustCreateTmpFile(t *testing.T, content string, executable bool, pathInTestDir ...string) string
- func (s *Test) MustCreateUnaccessibleDir(t *testing.T, name string)
- func (s *Test) MustMkSubDirs(t *testing.T, dirs ...string) string
- func (s *Test) Name() string
- func (s *Test) RegisterCleanup(t *testing.T)
- func (s *Test) RunSubTestParallel(t *testing.T)
- func (s *Test) SetSubTest(names ...string) *Test
- func (s *Test) SetTmpDir(dir string) error
- func (s *Test) Settings() settings.Settings
- func (s *Test) TmpDir() string
- func (s *Test) TryToSkipIntegrationTest(t *testing.T)
- func (s *Test) WithAuthSock(p string) *Test
- func (s *Test) WithEnvsPrefix(p string) *Test
- func (s *Test) WithNodeTmpDir(p string) *Test
- func (s *Test) WrapError(format string, args ...any) error
- func (s *Test) WrapErrorWithAfterName(aftername, format string, args ...any) error
- type TestContainerWrapper
- type TestContainerWrapperSettings
- type TestContainerWrapperSettingsOpts
- func WithAuthSettings(testContainer *TestContainerWrapper) TestContainerWrapperSettingsOpts
- func WithConnectToContainerNetwork(testContainer *TestContainerWrapper) TestContainerWrapperSettingsOpts
- func WithContainerName(name string) TestContainerWrapperSettingsOpts
- func WithLocalPort(port int) TestContainerWrapperSettingsOpts
- func WithNoGeneratePrivateKeys() TestContainerWrapperSettingsOpts
- func WithNoPassword() TestContainerWrapperSettingsOpts
- func WithNoStartContainer() TestContainerWrapperSettingsOpts
- func WithNoSudo() TestContainerWrapperSettingsOpts
- func WithNoWaitStartingSSHDAfterStartContainer() TestContainerWrapperSettingsOpts
- func WithNoWriteSSHDConfig() TestContainerWrapperSettingsOpts
- func WithPassword(password string) TestContainerWrapperSettingsOpts
- func WithUserName(name string) TestContainerWrapperSettingsOpts
- func WithVolumes(v []Volume) TestContainerWrapperSettingsOpts
- type TestFlagsParser
- type TestFlagsParserHelpProvider
- type TestOpt
- func TestIsIntegration(yes bool) TestOpt
- func TestNoLogDebug(noLogDebug bool) TestOpt
- func TestWithAuthSock(p string) TestOpt
- func TestWithDebug(isDebug bool) TestOpt
- func TestWithLoggerBuffer(b *bytes.Buffer) TestOpt
- func TestWithParallelRun(p bool) TestOpt
- func TestWithPrettyLogger(f bool) TestOpt
- type Volume
Constants ¶
const HealthzPath = "/healthz"
const PrivateKeysRoot = "private_keys"
Variables ¶
This section is empty.
Functions ¶
func AcquireGlobalTestLock ¶ added in v0.11.0
AcquireGlobalTestLock takes an exclusive inter-process lock with the given name and holds it until the test finishes. Use it for tests that occupy globally shared resources (e.g. the fixed kube-proxy local API port), which would collide when test binaries of different packages run in parallel.
func AssertKubeProxy ¶
func AssertLogBufferBundleWithInfo ¶ added in v0.7.0
func AssertParseFlagsHelp ¶
func AssertParseFlagsHelp(t *testing.T, params AssertParseFlagsHelpParams)
func CheckSkipSSHTest ¶
func DoGetRequest ¶
func FakeSession ¶
func GenerateID ¶
func GenerateKeys ¶
helper func to generate SSH keys
func IncorrectHost ¶
func IncorrectHost() string
func LogErrorOrAssert ¶
func RandInvalidPortExclude ¶
func RandPassword ¶
func RandPortExclude ¶
func RandRangeExclude ¶
func RandString ¶
func RunDockerWithOut ¶
func Session ¶
func Session(wrapper *TestContainerWrapper, overrides ...SessionOverride) *session.Session
func SessionWithBastion ¶
func SessionWithBastion(wrapper *TestContainerWrapper, bastionWrapper *TestContainerWrapper, overrides ...SessionOverride) *session.Session
func WaitPortFree ¶ added in v0.12.0
WaitPortFree blocks until the given TCP port on localhost can be bound again, or fails the test after the timeout. Use it right after AcquireGlobalTestLock for tests that reuse a fixed port (e.g. the kube-proxy local API port): the previous lock holder tears the listener down asynchronously, so the port may still be in use for a short while after that holder releases the lock.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
func StartAgent ¶
func StartTestAgent ¶
func StartTestAgent(t *testing.T, wrapper *TestContainerWrapper) *Agent
func (*Agent) AddKey ¶
func (a *Agent) AddKey(key PrivateKey) error
func (*Agent) RegisterCleanup ¶
func (*Agent) RemoveKey ¶
func (a *Agent) RemoveKey(key PrivateKey) error
type AssertParseFlagsHelpParams ¶
type AssertParseFlagsHelpParams struct {
Name string
Provider TestFlagsParserHelpProvider
ExpectedFlags int
}
type ContainerSettings ¶
type ContainerSettings struct {
*Test
PublicKey *PublicKey
Password string
Username string
NodeTmpPath string
LocalPort int
SudoAccess bool
ContainerName string
AdditionalVolumes []Volume
}
func (*ContainerSettings) HasPassword ¶
func (s *ContainerSettings) HasPassword() bool
func (*ContainerSettings) HasPublicKey ¶
func (s *ContainerSettings) HasPublicKey() bool
func (*ContainerSettings) HasPublicKeyContent ¶
func (s *ContainerSettings) HasPublicKeyContent() bool
func (*ContainerSettings) HasPublicKeyPath ¶
func (s *ContainerSettings) HasPublicKeyPath() bool
func (*ContainerSettings) LocalPortString ¶
func (s *ContainerSettings) LocalPortString() string
func (*ContainerSettings) String ¶
func (s *ContainerSettings) String() string
type HTTPHandler ¶
type HTTPHandler struct {
Path string
Handle func(w http.ResponseWriter, r *http.Request, logger *PrefixLogger)
}
func NewSimpleHTTPHandler ¶
func NewSimpleHTTPHandler(path string, response string) *HTTPHandler
func (*HTTPHandler) IsValid ¶
func (h *HTTPHandler) IsValid() error
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
func MustStartHTTPServer ¶
func MustStartHTTPServer(t *testing.T, test *Test, port int, handlers ...*HTTPHandler) *HTTPServer
func NewHTTPServer ¶
func NewHTTPServer(port int, logger *slog.Logger, handlers ...*HTTPHandler) *HTTPServer
func (*HTTPServer) AddHandler ¶
func (s *HTTPServer) AddHandler(handler *HTTPHandler)
func (*HTTPServer) RegisterCleanup ¶
func (s *HTTPServer) RegisterCleanup(t *testing.T)
func (*HTTPServer) Start ¶
func (s *HTTPServer) Start(waitStart bool) error
func (*HTTPServer) Stop ¶
func (s *HTTPServer) Stop() error
func (*HTTPServer) WithLogPrefix ¶
func (s *HTTPServer) WithLogPrefix(p string) *HTTPServer
type PrefixLogger ¶
func NewPrefixLogger ¶
func NewPrefixLogger(logger *slog.Logger) *PrefixLogger
func (*PrefixLogger) Error ¶
func (l *PrefixLogger) Error(f string, args ...any)
func (*PrefixLogger) Info ¶
func (l *PrefixLogger) Info(f string, args ...any)
func (*PrefixLogger) WithPrefix ¶
func (l *PrefixLogger) WithPrefix(p string) *PrefixLogger
type PrivateKey ¶
type SSHContainer ¶
type SSHContainer struct {
// contains filtered or unexported fields
}
func NewSSHContainer ¶
func NewSSHContainer(settings *ContainerSettings) (*SSHContainer, error)
func (*SSHContainer) Connect ¶
func (c *SSHContainer) Connect() error
func (*SSHContainer) ContainerSettings ¶
func (c *SSHContainer) ContainerSettings() *ContainerSettings
func (*SSHContainer) CreateDeckhouseDirs ¶
func (c *SSHContainer) CreateDeckhouseDirs() error
func (*SSHContainer) CreateDirectory ¶
func (c *SSHContainer) CreateDirectory(path string) error
func (*SSHContainer) Disconnect ¶
func (c *SSHContainer) Disconnect() error
func (*SSHContainer) DockerNetworkConnect ¶
func (c *SSHContainer) DockerNetworkConnect(isDisconnect bool, name string) error
func (*SSHContainer) DownloadKubectl ¶
func (c *SSHContainer) DownloadKubectl(version string) error
func (*SSHContainer) ExecToContainer ¶
func (c *SSHContainer) ExecToContainer(description string, command ...string) error
func (*SSHContainer) ExecToContainerWithOut ¶ added in v0.5.0
func (c *SSHContainer) ExecToContainerWithOut(description string, command ...string) (string, error)
func (*SSHContainer) FailAndUpConnection ¶
func (c *SSHContainer) FailAndUpConnection(sleepBeforeConnect time.Duration) error
func (*SSHContainer) GetContainerIP ¶
func (c *SSHContainer) GetContainerIP() string
func (*SSHContainer) GetContainerId ¶
func (c *SSHContainer) GetContainerId() string
func (*SSHContainer) GetNetwork ¶
func (c *SSHContainer) GetNetwork() string
func (*SSHContainer) GetSSHDConfigPath ¶
func (c *SSHContainer) GetSSHDConfigPath() string
func (*SSHContainer) LocalPortString ¶
func (c *SSHContainer) LocalPortString() string
func (*SSHContainer) RemotePort ¶
func (c *SSHContainer) RemotePort() int
func (*SSHContainer) RemotePortString ¶
func (c *SSHContainer) RemotePortString() string
func (*SSHContainer) Restart ¶
func (c *SSHContainer) Restart(waitSSHDStarted bool, sleepBeforeStart time.Duration) error
func (*SSHContainer) ShortContainerId ¶
func (c *SSHContainer) ShortContainerId() string
func (*SSHContainer) SoftRestart ¶
func (c *SSHContainer) SoftRestart(waitSSHDStarted bool, sleepBeforeStart time.Duration) error
func (*SSHContainer) Start ¶
func (c *SSHContainer) Start(waitSSHDStarted bool) error
func (*SSHContainer) Stop ¶
func (c *SSHContainer) Stop() error
func (*SSHContainer) WithExternalNetwork ¶
func (c *SSHContainer) WithExternalNetwork(network string) *SSHContainer
func (*SSHContainer) WithVolumes ¶
func (c *SSHContainer) WithVolumes(volumes ...Volume) *SSHContainer
func (*SSHContainer) WriteConfig ¶
func (c *SSHContainer) WriteConfig() error
force AllowTcpForwarding yes to allow connection throufh bastion
type SessionOverride ¶
func OverrideSessionWithIncorrectBastionPort ¶
func OverrideSessionWithIncorrectBastionPort(wrappers ...*TestContainerWrapper) SessionOverride
func OverrideSessionWithIncorrectPort ¶
func OverrideSessionWithIncorrectPort(wrappers ...*TestContainerWrapper) SessionOverride
type Test ¶
func (*Test) CreateFile ¶
func (*Test) CreateFileWithSameSuffix ¶
func (*Test) CreateTmpFile ¶
func (*Test) FullNameForContainer ¶ added in v0.5.0
func (*Test) GenerateID ¶
func (*Test) MustCreateFile ¶
func (*Test) MustCreateTmpFile ¶
func (*Test) MustCreateUnaccessibleDir ¶
func (*Test) RegisterCleanup ¶
func (*Test) RunSubTestParallel ¶
func (*Test) SetSubTest ¶
func (*Test) TryToSkipIntegrationTest ¶
func (*Test) WithAuthSock ¶
func (*Test) WithEnvsPrefix ¶
func (*Test) WithNodeTmpDir ¶ added in v0.7.0
type TestContainerWrapper ¶
type TestContainerWrapper struct {
Container *SSHContainer
Settings *TestContainerWrapperSettings
PrivateKeyPath string
}
func NewTestContainerWrapper ¶
func NewTestContainerWrapper(t *testing.T, test *Test, opts ...TestContainerWrapperSettingsOpts) *TestContainerWrapper
func (*TestContainerWrapper) AgentPrivateKeys ¶
func (c *TestContainerWrapper) AgentPrivateKeys() []session.AgentPrivateKey
func (*TestContainerWrapper) Cleanup ¶
func (c *TestContainerWrapper) Cleanup(t *testing.T)
func (*TestContainerWrapper) ContainerIP ¶
func (c *TestContainerWrapper) ContainerIP() string
func (*TestContainerWrapper) LocalPort ¶
func (c *TestContainerWrapper) LocalPort() int
func (*TestContainerWrapper) PublicKeyPath ¶
func (c *TestContainerWrapper) PublicKeyPath() string
type TestContainerWrapperSettingsOpts ¶
type TestContainerWrapperSettingsOpts func(container *TestContainerWrapperSettings)
func WithAuthSettings ¶
func WithAuthSettings(testContainer *TestContainerWrapper) TestContainerWrapperSettingsOpts
func WithConnectToContainerNetwork ¶
func WithConnectToContainerNetwork(testContainer *TestContainerWrapper) TestContainerWrapperSettingsOpts
func WithContainerName ¶
func WithContainerName(name string) TestContainerWrapperSettingsOpts
func WithLocalPort ¶
func WithLocalPort(port int) TestContainerWrapperSettingsOpts
func WithNoGeneratePrivateKeys ¶
func WithNoGeneratePrivateKeys() TestContainerWrapperSettingsOpts
func WithNoPassword ¶
func WithNoPassword() TestContainerWrapperSettingsOpts
func WithNoStartContainer ¶
func WithNoStartContainer() TestContainerWrapperSettingsOpts
func WithNoSudo ¶
func WithNoSudo() TestContainerWrapperSettingsOpts
func WithNoWaitStartingSSHDAfterStartContainer ¶
func WithNoWaitStartingSSHDAfterStartContainer() TestContainerWrapperSettingsOpts
func WithNoWriteSSHDConfig ¶
func WithNoWriteSSHDConfig() TestContainerWrapperSettingsOpts
func WithPassword ¶
func WithPassword(password string) TestContainerWrapperSettingsOpts
func WithUserName ¶
func WithUserName(name string) TestContainerWrapperSettingsOpts
func WithVolumes ¶
func WithVolumes(v []Volume) TestContainerWrapperSettingsOpts
type TestFlagsParser ¶
type TestFlagsParserHelpProvider ¶
type TestFlagsParserHelpProvider func(s settings.Settings, envsPrefix string) TestFlagsParser
type TestOpt ¶
type TestOpt func(opts *testOpts)