tests

package
v0.1.0 Latest Latest
Warning

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

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

README

Utils package for tests

Use only in tests.

Documentation

Index

Constants

View Source
const HealthzPath = "/healthz"
View Source
const (
	KindBinary = "../../../bin/kind"
)
View Source
const PrivateKeysRoot = "private_keys"

Variables

This section is empty.

Functions

func AssertKubeProxy

func AssertKubeProxy(t *testing.T, test *Test, localServerPort string, wantError bool)

func AssertLogBufferNoErrorBundle

func AssertLogBufferNoErrorBundle(t *testing.T, buf *bytes.Buffer)

func AssertLogBufferWithErrorBundle

func AssertLogBufferWithErrorBundle(t *testing.T, buf *bytes.Buffer)

func AssertLogMessage

func AssertLogMessage(t *testing.T, sett settings.Settings, msgInLog string)

func AssertLogMessagesCount

func AssertLogMessagesCount(t *testing.T, sett settings.Settings, msgInLog string, expected int)

func AssertNoLogMessage

func AssertNoLogMessage(t *testing.T, sett settings.Settings, msgInLog string)

func AssertParseFlagsHelp

func AssertParseFlagsHelp(t *testing.T, params AssertParseFlagsHelpParams)

func CheckSkipSSHTest

func CheckSkipSSHTest(t *testing.T, testName string)

func CreateDefaultTestSettings

func CreateDefaultTestSettings(test *Test) settings.Settings

func CreateDefaultTestSettingsWithAgent

func CreateDefaultTestSettingsWithAgent(test *Test, agentSockPath string) settings.Settings

func CreateTestSettingNoDebug

func CreateTestSettingNoDebug(test *Test) settings.Settings

func DoGetRequest

func DoGetRequest(url string, loop retry.Params, logger *PrefixLogger) (string, error)

func FakeSession

func FakeSession() *session.Session

func GenerateID

func GenerateID(names ...string) string

func GenerateKeys

func GenerateKeys(test *Test, passphrase string) (string, string, error)

helper func to generate SSH keys

func GeneratePrivateKey

func GeneratePrivateKey(t *testing.T, passphrase string) string

func GeneratePrivateKeyWithPublic

func GeneratePrivateKeyWithPublic(t *testing.T, passphrase string) (string, string)

func GetTestLoopParamsForFailed

func GetTestLoopParamsForFailed() retry.Params

func IncorrectHost

func IncorrectHost() string

func LogErrorOrAssert

func LogErrorOrAssert(t *testing.T, description string, err error, logger log.Logger)

func Name

func Name(t *testing.T) string

func PrepareFakeBashibleBundle

func PrepareFakeBashibleBundle(t *testing.T, test *Test, entrypoint, bundleDir string) string

func Ptr

func Ptr[T any](v T) *T

func RandInvalidPortExclude

func RandInvalidPortExclude(_ []int) int

func RandPassword

func RandPassword(n int) string

func RandPort

func RandPort() int

func RandPortExclude

func RandPortExclude(exclude []int) int

func RandRange

func RandRange(min, max int) int

func RandRangeExclude

func RandRangeExclude(min, max int, exclude []int) int

func RandString

func RandString(n int) string

func RunDocker

func RunDocker(command ...string) error

func RunDockerWithOut

func RunDockerWithOut(command ...string) (string, error)

func Session

func Session(wrapper *TestContainerWrapper, overrides ...SessionOverride) *session.Session

func SessionWithBastion

func SessionWithBastion(wrapper *TestContainerWrapper, bastionWrapper *TestContainerWrapper, overrides ...SessionOverride) *session.Session

func SetEnvs

func SetEnvs(t *testing.T, envs map[string]string)

func Sleep

func Sleep(d time.Duration)

func TestLogger

func TestLogger(opts ...TestOpt) *log.InMemoryLogger

func WritePubKeyFileForPrivate

func WritePubKeyFileForPrivate(test *Test, privateKeyPath string, pubKey string) (string, error)

Types

type Agent

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

func StartAgent

func StartAgent(sockDir string, logger log.Logger, keysPath ...PrivateKey) (*Agent, error)

func StartTestAgent

func StartTestAgent(t *testing.T, wrapper *TestContainerWrapper) *Agent

func (*Agent) AddKey

func (a *Agent) AddKey(key PrivateKey) error

func (*Agent) IsStopped

func (a *Agent) IsStopped() bool

func (*Agent) Pid

func (a *Agent) Pid() int

func (*Agent) RegisterCleanup

func (a *Agent) RegisterCleanup(t *testing.T)

func (*Agent) RemoveKey

func (a *Agent) RemoveKey(key PrivateKey) error

func (*Agent) SockPath

func (a *Agent) SockPath() string

func (*Agent) Stop

func (a *Agent) Stop()

func (*Agent) String

func (a *Agent) String() string

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 *log.InMemoryLogger, 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 KINDCluster

type KINDCluster struct {
	Name             string
	ControlPlaneIP   string
	ControlPlanePort string
	// contains filtered or unexported fields
}

func CreateKINDCluster

func CreateKINDCluster(t *testing.T, params *KINDClusterCreateParams) *KINDCluster

func (*KINDCluster) Delete

func (c *KINDCluster) Delete() error

func (*KINDCluster) Kubeconfig

func (c *KINDCluster) Kubeconfig() string

func (*KINDCluster) KubeconfigWithIP

func (c *KINDCluster) KubeconfigWithIP(ip string, port string) string

KubeconfigWithIP ip and port can empty if empty returns raw

func (*KINDCluster) RESTConfig

func (c *KINDCluster) RESTConfig() (*rest.Config, error)

func (*KINDCluster) RegisterCleanup

func (c *KINDCluster) RegisterCleanup(t *testing.T)

type KINDClusterCreateParams

type KINDClusterCreateParams struct {
	Test        *Test
	ClusterName string
	Containers  []*SSHContainersForKind

	NoPrepareLocalKubectlInSSHContainer bool
}

type PrefixLogger

type PrefixLogger struct {
	log.Logger
	// contains filtered or unexported fields
}

func NewPrefixLogger

func NewPrefixLogger(logger log.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) Log

func (l *PrefixLogger) Log(write func(string, ...any), f string, args ...any)

func (*PrefixLogger) WithPrefix

func (l *PrefixLogger) WithPrefix(p string) *PrefixLogger

type PrivateKey

type PrivateKey struct {
	Path     string
	Password string
}

type PublicKey

type PublicKey struct {
	Key  string
	Path string
}

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) 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 SSHContainersForKind

type SSHContainersForKind struct {
	Client    connection.SSHClient
	Container *TestContainerWrapper
}

type SessionOverride

type SessionOverride func(input *session.Input)

func OverrideSessionWithIncorrectBastionPort

func OverrideSessionWithIncorrectBastionPort(wrappers ...*TestContainerWrapper) SessionOverride

func OverrideSessionWithIncorrectPort

func OverrideSessionWithIncorrectPort(wrappers ...*TestContainerWrapper) SessionOverride

type Test

type Test struct {
	Logger *log.InMemoryLogger
	// contains filtered or unexported fields
}

func NewTest

func NewTest(testName string, opts ...TestOpt) (*Test, error)

func ShouldNewIntegrationTest

func ShouldNewIntegrationTest(t *testing.T, name string, opts ...TestOpt) *Test

func ShouldNewTest

func ShouldNewTest(t *testing.T, testName string, opts ...TestOpt) *Test

func (*Test) Cleanup

func (s *Test) Cleanup(t *testing.T)

func (*Test) CreateFile

func (s *Test) CreateFile(content string, executable bool, pathInTestDir ...string) (string, error)

func (*Test) CreateFileWithSameSuffix

func (s *Test) CreateFileWithSameSuffix(sourceFile string, content string, executable bool, pathInTestDir ...string) (string, error)

func (*Test) CreateTmpFile

func (s *Test) CreateTmpFile(content string, executable bool, pathInTestDir ...string) (string, error)

func (*Test) FullName

func (s *Test) FullName() string

func (*Test) GenerateID

func (s *Test) GenerateID(names ...string) string

func (*Test) GetID

func (s *Test) GetID() string

func (*Test) GetLogger

func (s *Test) GetLogger() *log.InMemoryLogger

func (*Test) IsZero

func (s *Test) IsZero() bool

func (*Test) MkSubDirs

func (s *Test) MkSubDirs(dirs ...string) (string, error)

func (*Test) MustCreateFile

func (s *Test) MustCreateFile(t *testing.T, content string, executable bool, pathInTestDir ...string) string

func (*Test) MustCreateTmpFile

func (s *Test) MustCreateTmpFile(t *testing.T, content string, executable bool, pathInTestDir ...string) string

func (*Test) MustCreateUnaccessibleDir

func (s *Test) MustCreateUnaccessibleDir(t *testing.T, name string)

func (*Test) MustMkSubDirs

func (s *Test) MustMkSubDirs(t *testing.T, dirs ...string) string

func (*Test) Name

func (s *Test) Name() string

func (*Test) RegisterCleanup

func (s *Test) RegisterCleanup(t *testing.T)

func (*Test) RunSubTestParallel

func (s *Test) RunSubTestParallel(t *testing.T)

func (*Test) SetSubTest

func (s *Test) SetSubTest(names ...string) *Test

func (*Test) SetTmpDir

func (s *Test) SetTmpDir(dir string) error

func (*Test) Settings

func (s *Test) Settings() settings.Settings

func (*Test) TmpDir

func (s *Test) TmpDir() string

func (*Test) TryToSkipIntegrationTest

func (s *Test) TryToSkipIntegrationTest(t *testing.T)

func (*Test) WithAuthSock

func (s *Test) WithAuthSock(p string) *Test

func (*Test) WithEnvsPrefix

func (s *Test) WithEnvsPrefix(p string) *Test

func (*Test) WrapError

func (s *Test) WrapError(format string, args ...any) error

func (*Test) WrapErrorWithAfterName

func (s *Test) WrapErrorWithAfterName(aftername, format string, args ...any) error

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 TestContainerWrapperSettings

type TestContainerWrapperSettings struct {
	*ContainerSettings

	PrivateKeyPassword string
	ExternalNetwork    string

	NoStartContainerDuringCreate          bool
	NoWaitStartingSSHDAfterStartContainer bool
	NoGeneratePrivateKey                  bool
	NoWriteSSHDConfig                     bool
	NoGeneratePrivateKeys                 bool
}

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 WithNoStartContainer

func WithNoStartContainer() TestContainerWrapperSettingsOpts

func WithNoWaitStartingSSHDAfterStartContainer

func WithNoWaitStartingSSHDAfterStartContainer() TestContainerWrapperSettingsOpts

func WithNoWriteSSHDConfig

func WithNoWriteSSHDConfig() TestContainerWrapperSettingsOpts

func WithPassword

func WithPassword(password string) TestContainerWrapperSettingsOpts

type TestFlagsParser

type TestFlagsParser interface {
	InitFlags(*flag.FlagSet) (*flag.FlagSet, error)
}

type TestFlagsParserHelpProvider

type TestFlagsParserHelpProvider func(s settings.Settings, envsPrefix string) TestFlagsParser

type TestOpt

type TestOpt func(opts *testOpts)

func TestIsIntegration

func TestIsIntegration(yes bool) TestOpt

func TestWithAuthSock

func TestWithAuthSock(p string) TestOpt

func TestWithDebug

func TestWithDebug(isDebug bool) TestOpt

func TestWithLoggerBuffer

func TestWithLoggerBuffer(b *bytes.Buffer) TestOpt

func TestWithParallelRun

func TestWithParallelRun(p bool) TestOpt

func TestWithPrettyLogger

func TestWithPrettyLogger(f bool) TestOpt

type Volume

type Volume struct {
	Local  string
	Remote string
}

Jump to

Keyboard shortcuts

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