testutils

package
v0.0.0-...-54413df Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 30 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultFakeGitServerContainerName = "fake_git_server"
	GitDockerImage                    = "winlu/docker-git-server"
	DefaultExposedGitPort             = 2222
	DefaultExposedGitBindHost         = "127.0.0.1"
	DefaultGitDockerDaemonHost        = "unix:///var/run/docker.sock"
	DefaultGitDockerDaemonCertPath    = ""
	DefaultGitDockerDaemonTLSVerify   = "1"
)
View Source
const (
	PostgresDockerImage                  = "postgres"
	DefaultPostgresVersion               = "10"
	DefaultPostgresDockerDaemonHost      = "unix:///var/run/docker.sock"
	DefaultPostgresDockerDaemonCertPath  = ""
	DefaultPostgresDockerDaemonTLSVerify = "1"
	DefaultPostgresHost                  = "127.0.0.1"
	DefaultPostgresPort                  = 5432
	DefaultPostgresUser                  = "postgres"
	DefaultPostgresPassword              = "password"
	DefaultPostgresDatabase              = "postgres"
)
View Source
const (
	RabbitMqDockerImage                  = "rabbitmq"
	DefaultRabbitMqVersion               = "3"
	DefaultRabbitMqDockerDaemonHost      = "unix:///var/run/docker.sock"
	DefaultRabbitMqDockerDaemonCertPath  = ""
	DefaultRabbitMqDockerDaemonTLSVerify = "1"
	DefaultRabbitMqHost                  = "127.0.0.1"
	DefaultRabbitMqPort                  = 5672
	DefaultRabbitMqUser                  = "guest"
	DefaultRabbitMqPassword              = "guest"
)
View Source
const (
	RedisDockerImage                  = "redis"
	DefaultRedisVersion               = "5"
	DefaultRedisDockerDaemonHost      = "unix:///var/run/docker.sock"
	DefaultRedisDockerDaemonCertPath  = ""
	DefaultRedisDockerDaemonTLSVerify = "1"
	DefaultRedisHost                  = "127.0.0.1"
	DefaultRedisPort                  = 6379
)

Variables

This section is empty.

Functions

func AssertGolden

func AssertGolden(t *testing.T, path string, actual []byte)

func AssertGoldenTemplate

func AssertGoldenTemplate(t *testing.T, path string, templateVars map[string]string, actual []byte)

func GenerateAndWritePrivateKey

func GenerateAndWritePrivateKey(t *testing.T, tmpDir, keyName string) (string, *stdRsa.PrivateKey)

nolint: thelper

func GenerateAndWritePublicKey

func GenerateAndWritePublicKey(t *testing.T, tmpDir, keyName string, privKey *stdRsa.PrivateKey) string

nolint: thelper

func GitEnvToArray

func GitEnvToArray(gitEnv map[string]string) []string

func GoBuild

func GoBuild(ctx context.Context, binaryPattern, pkgPath string, osExecutor os.OsExecutor) string

func RandString

func RandString(n int) string

RandString is a random string generator for testing. Not meant for production use and very insecure.

func RunCommandInSameProcess

func RunCommandInSameProcess(cmd *cobra.Command, args []string, output io.Writer) (*cobra.Command, error)

RunCommandInSameProcess is a test helper function to test CLI in integration tests by running in the same process and being able to mock/stub behavior.

func RunCommandInSubprocess

func RunCommandInSubprocess(t *testing.T, args ...string) *exec.Cmd

RunCommandInSubprocess is a test helper function to test CLI in end-to-end tests by running them in a separate subprocess, but not being able able to mock/stub behavior. nolint: thelper

func TestChdir

func TestChdir(t *testing.T, dir string)

TestChdir changes current dir to specified `dir`.

func TestCwd

func TestCwd(t *testing.T, dirPrefix string) string

TestCwd creates new temporary dir using `TestDir` and changes to it using `TestChdir`.

func TestDir

func TestDir(t *testing.T, dirPrefix string) string

TestDir creates a new temporary dir using specified `dirPrefix`.

Types

type Build

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

func NewBuild

func NewBuild(binaryPath, workDir string) *Build

func (*Build) Run

func (b *Build) Run(ctx context.Context, args ...string) (string, string, error)

type FakeGitServer

type FakeGitServer struct {
	Host string
	Port int
	// contains filtered or unexported fields
}

func DefaultGitServer

func DefaultGitServer() *FakeGitServer

func NewFakeGitServer

func NewFakeGitServer(
	host string,
	port int,
	dockerContainerName string,
	dockerDaemonHost string,
	dockerCertPath string,
	dockerTLSVerify string,
) *FakeGitServer

func NewFakeGitServerFromEnv

func NewFakeGitServerFromEnv() *FakeGitServer

func (*FakeGitServer) AddDirToGitRepo

func (s *FakeGitServer) AddDirToGitRepo(
	gitEnv map[string]string,
	dir string,
	templateData interface{},
) error

func (*FakeGitServer) AddFilesToGitRepo

func (s *FakeGitServer) AddFilesToGitRepo(gitEnv map[string]string, files map[string]string) error

func (*FakeGitServer) AddRemoteGitUser

func (s *FakeGitServer) AddRemoteGitUser(username string, privKey *rsa.PrivateKey) error

func (*FakeGitServer) CloneRemoteGitRepo

func (s *FakeGitServer) CloneRemoteGitRepo(gitEnv map[string]string) (string, error)

func (*FakeGitServer) CreateRemoteGitRepo

func (s *FakeGitServer) CreateRemoteGitRepo(privKeyPath, username, repositoryName string) error

func (*FakeGitServer) IsGitHealthy

func (s *FakeGitServer) IsGitHealthy() bool

func (*FakeGitServer) PrepareGitEnv

func (s *FakeGitServer) PrepareGitEnv(privKeyPath, username, repositoryName, gitWorkDir string) map[string]string

func (*FakeGitServer) PrepareGitServerWithArgs

func (s *FakeGitServer) PrepareGitServerWithArgs() error

func (*FakeGitServer) SetupForGitRepo

func (s *FakeGitServer) SetupForGitRepo(
	t *testing.T,
	tempDir string,
	gitRepoFiles map[string]string,
) (map[string]string, string)

nolint: thelper

func (*FakeGitServer) StopGitServer

func (s *FakeGitServer) StopGitServer() error

type FakePostgresServer

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

func NewFakePostgres10Server

func NewFakePostgres10Server(
	dockerContainerName,
	dockerDaemonHost,
	dockerDaemonCertPath,
	dockerDeamonTLSVerify,
	host string,
	port int,
	user,
	password,
	database string,
) *FakePostgresServer

func NewFakePostgres10ServerFromEnv

func NewFakePostgres10ServerFromEnv() *FakePostgresServer

func NewFakePostgresServer

func NewFakePostgresServer(
	postgresVersion,
	dockerContainerName,
	dockerDaemonHost,
	dockerCertPath,
	dockerTLSVerify,
	host string,
	port int,
	user,
	password,
	database string,
) *FakePostgresServer

func NewFakePostgresServerFromEnv

func NewFakePostgresServerFromEnv() *FakePostgresServer

func (*FakePostgresServer) GetDSN

func (s *FakePostgresServer) GetDSN(connectTimeout int) string

func (*FakePostgresServer) IsHealthy

func (s *FakePostgresServer) IsHealthy() bool

func (*FakePostgresServer) RunWithArgs

func (s *FakePostgresServer) RunWithArgs() error

func (*FakePostgresServer) Stop

func (s *FakePostgresServer) Stop() error

type FakeRabbitMq

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

func NewFakeRabbitMq

func NewFakeRabbitMq(
	rabbitmqVersion,
	dockerContainerName,
	dockerDaemonHost,
	dockerCertPath,
	dockerTLSVerify,
	host string,
	port int,
	user,
	password string,
) *FakeRabbitMq

func NewFakeRabbitMqFromEnv

func NewFakeRabbitMqFromEnv() *FakeRabbitMq

func (*FakeRabbitMq) GetConnectionString

func (s *FakeRabbitMq) GetConnectionString() string

func (*FakeRabbitMq) IsHealthy

func (s *FakeRabbitMq) IsHealthy() bool

func (*FakeRabbitMq) RunWithArgs

func (s *FakeRabbitMq) RunWithArgs() error

func (*FakeRabbitMq) Stop

func (s *FakeRabbitMq) Stop() error

type FakeRedisServer

type FakeRedisServer struct {
	Host string
	Port int
	// contains filtered or unexported fields
}

func NewFakeRedis5Server

func NewFakeRedis5Server(
	dockerContainerName,
	dockerDaemonHost,
	dockerDaemonCertPath,
	dockerDaemonTLSVerify,
	host string,
	port int,
) *FakeRedisServer

func NewFakeRedis5ServerFromEnv

func NewFakeRedis5ServerFromEnv() *FakeRedisServer

func NewFakeRedisServer

func NewFakeRedisServer(
	version,
	dockerContainerName,
	dockerDaemonHost,
	dockerCertPath,
	dockerTLSVerify,
	host string,
	port int,
) *FakeRedisServer

func NewFakeRedisServerFromEnv

func NewFakeRedisServerFromEnv() *FakeRedisServer

func (*FakeRedisServer) IsHealthy

func (s *FakeRedisServer) IsHealthy() bool

func (*FakeRedisServer) RunWithArgs

func (s *FakeRedisServer) RunWithArgs() error

func (*FakeRedisServer) Stop

func (s *FakeRedisServer) Stop() error

Jump to

Keyboard shortcuts

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