utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: 0BSD Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPostgresPort         = "5432"
	PostgresAdminDatabase       = "postgres"
	PostgresApplicationDatabase = "application"
	PostgresApplicationTemplate = "application_template"
)
View Source
const (
	DirectoryField        = "directory"
	SizeInBytesField      = "size_in_bytes"
	FolderToFindField     = "folder_to_find"
	InitialDirField       = "initial_directory"
	HostField             = "host"
	CurrentAttemptField   = "current_attempt"
	MaximumAttemptsFields = "maximum_attempts"
	PortField             = "port"
)
View Source
const (
	BrandName               = "quollix"
	OfficialMaintainer      = BrandName
	OfficialBrandAppName    = BrandName
	OfficialDatabaseAppName = "postgres"
)
View Source
const EmailServiceNotEnabledErrorMessage = "email service is not enabled"
View Source
const LicenseTokenSigningPublicKeyOpenSSH = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEC2+vXmZ/qX7vwL7Y2CWt65j3765Xe/n84E//XvS5h/" // #nosec G101: public key used by tests, not a credential
View Source
const LocalTestingPublicKeyOpenSSH = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF70YNMkl2Wedmpo2UszvIrXJqr/pgCpevysNjjwtUig"

Variables

View Source
var (
	Logger               = deepstack.NewDeepStackLogger(deepstack.NewRawConsoleHandler(slog.LevelInfo))
	OperationFailedError = "Operation failed"
)
View Source
var LicenseTokenSigningPublicKeyOpenSSHBytes = []byte(LicenseTokenSigningPublicKeyOpenSSH)
View Source
var LocalTestingPublicKeyOpenSSHBytes = []byte(LocalTestingPublicKeyOpenSSH)

Functions

func AssertDeepStackErrorFromRequest

func AssertDeepStackErrorFromRequest(t *testing.T, err error, expectedResponseBodyErrorMessage string)

func AssertInvalidInputError

func AssertInvalidInputError(t *testing.T, err error)

func BuildArtifacts

func BuildArtifacts(tr *taskrunner.TaskRunner, moduleRoot string)

func BuildWholeGoProject

func BuildWholeGoProject(Tr *taskrunner.TaskRunner, directory string)

BuildWholeGoProject this function is meant to detect compile errors in the test code with build tags

func Close

func Close(r Closable)

func CollectBuildTags

func CollectBuildTags(dir string) ([]string, error)

func DecodeAuthorizedEd25519PublicKey

func DecodeAuthorizedEd25519PublicKey(authorizedKey []byte) (ed25519.PublicKey, error)

func DecodeEd25519PrivateKeyOpenSSH

func DecodeEd25519PrivateKeyOpenSSH(privateKeyOpenSSH []byte) (ed25519.PrivateKey, error)

func ExtractError

func ExtractError(err error) string

func FindDir

func FindDir(dirName string) (string, error)

func FormatRelativeDuration

func FormatRelativeDuration(now, target time.Time) string

func GetLocalTestingPrivateKeyBytes

func GetLocalTestingPrivateKeyBytes() []byte

func GetLocalTestingPrivateKeyOpenSSH

func GetLocalTestingPrivateKeyOpenSSH() string

func GetLocalTestingPublicKeyFingerprintSHA256

func GetLocalTestingPublicKeyFingerprintSHA256() string

func GetLocalTestingPublicKeyRaw

func GetLocalTestingPublicKeyRaw() []byte

func IsGeneratedArtifactFile

func IsGeneratedArtifactFile(fileName string) bool

func IsSystemApp

func IsSystemApp(appName string) bool

func MapOf

func MapOf(elements ...string) map[string]any

func NewDockerRuntimeCleanupCommand

func NewDockerRuntimeCleanupCommand(tr *taskrunner.TaskRunner) *cobra.Command

func NewFileHandler

func NewFileHandler(level slog.Level) *slog.JSONHandler

func ReadLicenseKeyFromUserConfig

func ReadLicenseKeyFromUserConfig() (string, error)

func RecoverHttpPanics

func RecoverHttpPanics(next http.Handler) http.Handler

func RemoveDir

func RemoveDir(path string)

func RemoveGeneratedArtifacts

func RemoveGeneratedArtifacts(rootDir string)

func RenderDefaultPage

func RenderDefaultPage(htmlContent string) string

func RunAndLogIfError

func RunAndLogIfError(fn func() error)

func SendJsonResponse

func SendJsonResponse(w http.ResponseWriter, data any)

func SetCookieHeaders

func SetCookieHeaders(req *http.Request, c *ComponentClient)

func ShowHelpCommand

func ShowHelpCommand(cmd *cobra.Command)

func UnpackResponse

func UnpackResponse[T any](object any) (*T, error)

func WriteResponseError

func WriteResponseError(w http.ResponseWriter, expectedErrors map[string]any, err error, context ...any)

WriteResponseError Here we can define a set of expected error messages that can safely be exposed to clients. If the error matches one of these strings, it is returned unchanged. Otherwise, a default message is used to ensure that no sensitive error messages are returned.

func WriteResponseErrorAlways

func WriteResponseErrorAlways(w http.ResponseWriter, err error, context ...any)

Types

type ArtifactDiscovery

type ArtifactDiscovery struct {
	MockeryDirs []string
	WireDirs    []string
}

func DiscoverArtifacts

func DiscoverArtifacts(moduleRoot string) (ArtifactDiscovery, error)

type AuthHelper

type AuthHelper interface {
	GenerateCookie() (*http.Cookie, error)
	GenerateSecret() (string, error)
	GetTimeInSevenDays() time.Time
	SaltAndHash(clearText string) (string, error)
	DoesMatchSaltedHash(clearText, saltedHash string) bool
	GetSHA256Hash(plainText string) string
}

type AuthHelperImpl

type AuthHelperImpl struct{}

func (*AuthHelperImpl) DoesMatchSaltedHash

func (a *AuthHelperImpl) DoesMatchSaltedHash(clearText, saltedHash string) bool

func (*AuthHelperImpl) GenerateCookie

func (a *AuthHelperImpl) GenerateCookie() (*http.Cookie, error)

func (*AuthHelperImpl) GenerateSecret

func (a *AuthHelperImpl) GenerateSecret() (string, error)

func (*AuthHelperImpl) GetSHA256Hash

func (a *AuthHelperImpl) GetSHA256Hash(plainText string) string

func (*AuthHelperImpl) GetTimeInSevenDays

func (a *AuthHelperImpl) GetTimeInSevenDays() time.Time

func (*AuthHelperImpl) SaltAndHash

func (a *AuthHelperImpl) SaltAndHash(clearText string) (string, error)

type BytesSigner

type BytesSigner interface {
	SignBytes(privateKey ed25519.PrivateKey, payloadBytes []byte) []byte
	VerifyBytes(publicKey ed25519.PublicKey, payloadBytes []byte, signature []byte) bool
}

type BytesSignerImpl

type BytesSignerImpl struct{}

func (*BytesSignerImpl) SignBytes

func (c *BytesSignerImpl) SignBytes(privateKey ed25519.PrivateKey, payloadBytes []byte) []byte

func (*BytesSignerImpl) VerifyBytes

func (c *BytesSignerImpl) VerifyBytes(publicKey ed25519.PublicKey, payloadBytes []byte, signature []byte) bool

type Closable

type Closable interface {
	Close() error
}

type ComponentClient

type ComponentClient struct {
	Cookie            *http.Cookie
	SetCookieHeader   bool
	RootUrl           string
	Origin            string
	VerifyCertificate bool
}

func (*ComponentClient) DoRequest

func (c *ComponentClient) DoRequest(path string, payload any) ([]byte, error)

func (*ComponentClient) DoRequestWithFullResponse

func (c *ComponentClient) DoRequestWithFullResponse(path string, payload any) (*http.Response, error)

type ComposeSyntaxChecker

type ComposeSyntaxChecker interface {
	CheckDockerComposeSyntax(composeFileBytes []byte) error
}

type DatabaseConnector

type DatabaseConnector interface {
	GetDB() *sql.DB
	Connect() error
}

type DatabaseSnapshotRepository

type DatabaseSnapshotRepository interface {
	CreateDatabaseSnapshot() error
	ResetDatabaseToSnapshot() error
	DeleteDatabaseSnapshotIfExists() error
	SnapshotExists() (bool, error)
}

type DatabaseSnapshotRepositoryImpl

type DatabaseSnapshotRepositoryImpl struct {
	DatabaseHost            string
	DatabasePort            string
	ApplicationDatabaseName string
	TemplateDatabaseName    string
	AdminDatabaseName       string
	DatabaseConnector       DatabaseConnector
	DatabaseUtils           DatabaseUtils
}

func NewDatabaseSnapshotRepository

func NewDatabaseSnapshotRepository(
	databaseHost string,
	databaseConnector DatabaseConnector,
	databaseUtils DatabaseUtils,
) *DatabaseSnapshotRepositoryImpl

func (*DatabaseSnapshotRepositoryImpl) CreateDatabaseSnapshot

func (d *DatabaseSnapshotRepositoryImpl) CreateDatabaseSnapshot() error

func (*DatabaseSnapshotRepositoryImpl) DeleteDatabaseSnapshotIfExists

func (d *DatabaseSnapshotRepositoryImpl) DeleteDatabaseSnapshotIfExists() error

func (*DatabaseSnapshotRepositoryImpl) ResetDatabaseToSnapshot

func (d *DatabaseSnapshotRepositoryImpl) ResetDatabaseToSnapshot() error

func (*DatabaseSnapshotRepositoryImpl) SnapshotExists

func (d *DatabaseSnapshotRepositoryImpl) SnapshotExists() (bool, error)

type DatabaseUtils

type DatabaseUtils interface {
	WaitForPostgresDb(host, port, databaseName string) (*sql.DB, error)
	RunMigrations(migrationsDir, host, port, databaseName string) error
	EnsureDatabaseExists(host, port, databaseName string) error
}

type DatabaseUtilsImpl

type DatabaseUtilsImpl struct{}

func (*DatabaseUtilsImpl) EnsureDatabaseExists

func (d *DatabaseUtilsImpl) EnsureDatabaseExists(host, port, databaseName string) error

func (*DatabaseUtilsImpl) RunMigrations

func (d *DatabaseUtilsImpl) RunMigrations(migrationsDir, host, port, databaseName string) error

func (*DatabaseUtilsImpl) WaitForPostgresDb

func (d *DatabaseUtilsImpl) WaitForPostgresDb(host, port, databaseName string) (*sql.DB, error)

type DockerCliWrapper

type DockerCliWrapper interface {
	IsContainerRunning(containerName string) (bool, error)
	ImageExists(image string) (bool, error)
	DeleteImage(image string) error
}

type DockerCliWrapperImpl

type DockerCliWrapperImpl struct{}

func (*DockerCliWrapperImpl) DeleteImage

func (d *DockerCliWrapperImpl) DeleteImage(image string) error

func (*DockerCliWrapperImpl) ImageExists

func (d *DockerCliWrapperImpl) ImageExists(image string) (bool, error)

func (*DockerCliWrapperImpl) IsContainerRunning

func (d *DockerCliWrapperImpl) IsContainerRunning(containerName string) (bool, error)

type EmailClient

type EmailClient interface {
	SendEmail(emailConfig *EmailConfig, to, subject, body string) error
	CheckEmailServerConnection(emailConfig *EmailConfig) error
}

type EmailClientImpl

type EmailClientImpl struct{}

func (*EmailClientImpl) CheckEmailServerConnection

func (e *EmailClientImpl) CheckEmailServerConnection(emailConfig *EmailConfig) error

func (*EmailClientImpl) SendEmail

func (e *EmailClientImpl) SendEmail(emailConfig *EmailConfig, to, subject, body string) error

type EmailClientMock

type EmailClientMock struct{}

func (EmailClientMock) CheckEmailServerConnection

func (e EmailClientMock) CheckEmailServerConnection(emailConfig *EmailConfig) error

func (EmailClientMock) SendEmail

func (e EmailClientMock) SendEmail(emailConfig *EmailConfig, to, subject, body string) error

type EmailConfig

type EmailConfig struct {
	SMTPHost             string `validate:"host" json:"smtp_host"`
	SMTPPort             string `validate:"number" json:"smtp_port"`
	FromEmailAddress     string `validate:"email" json:"from_email_address"`
	EmailAccountUsername string `validate:"loose" json:"email_account_username"`
	EmailAccountPassword string `validate:"loose" json:"email_account_password"`
	IsEnabled            bool   `json:"is_enabled"`
}

type FileSystemOperator

type FileSystemOperator interface {
	ListFiles(dir string) ([]SimpleFile, error)
	ReadYamlFile(dir string) (map[string]any, error)
	CheckDockerComposeSyntax(composeFileBytes []byte) error
}

func NewFileSystemOperator

func NewFileSystemOperator(osWrapper OsWrapper) FileSystemOperator

type FileSystemOperatorImpl

type FileSystemOperatorImpl struct {
	OsWrapper OsWrapper
}

func (*FileSystemOperatorImpl) CheckDockerComposeSyntax

func (f *FileSystemOperatorImpl) CheckDockerComposeSyntax(composeFileBytes []byte) error

func (*FileSystemOperatorImpl) ListFiles

func (f *FileSystemOperatorImpl) ListFiles(dir string) ([]SimpleFile, error)

func (*FileSystemOperatorImpl) ReadYamlFile

func (f *FileSystemOperatorImpl) ReadYamlFile(path string) (map[string]any, error)

type GoTestCommand

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

func GoTest

func GoTest(directory string) *GoTestCommand

func (*GoTestCommand) Env

func (c *GoTestCommand) Env(key, value string) *GoTestCommand

func (*GoTestCommand) Filter

func (c *GoTestCommand) Filter(runFilter string) *GoTestCommand

func (*GoTestCommand) Run

func (c *GoTestCommand) Run(tr *taskrunner.TaskRunner)

func (*GoTestCommand) Tag

func (c *GoTestCommand) Tag(buildTag string) *GoTestCommand

type OsWrapper

type OsWrapper interface {
	ReadFile(path string) ([]byte, error)
	WriteFile(path string, data []byte, perm os.FileMode) error
	Remove(path string) error
	RemoveAll(path string) error
	MkdirAll(path string, perm os.FileMode) error
	ReadDir(path string) ([]os.DirEntry, error)
	GetTempDir() (string, error)
	DoesFileExist(path string) (bool, error)
	AllocateLocalhostPort() (string, error)
	Now() time.Time
	PromptUser(prompt string) (string, error)
	Sleep(duration time.Duration)
}

type OsWrapperImpl

type OsWrapperImpl struct{}

func (*OsWrapperImpl) AllocateLocalhostPort

func (o *OsWrapperImpl) AllocateLocalhostPort() (string, error)

func (*OsWrapperImpl) DoesFileExist

func (o *OsWrapperImpl) DoesFileExist(path string) (bool, error)

func (*OsWrapperImpl) GetTempDir

func (o *OsWrapperImpl) GetTempDir() (string, error)

func (*OsWrapperImpl) MkdirAll

func (o *OsWrapperImpl) MkdirAll(path string, perm os.FileMode) error

func (*OsWrapperImpl) Now

func (o *OsWrapperImpl) Now() time.Time

func (*OsWrapperImpl) PromptUser

func (o *OsWrapperImpl) PromptUser(prompt string) (string, error)

func (*OsWrapperImpl) ReadDir

func (o *OsWrapperImpl) ReadDir(path string) ([]os.DirEntry, error)

func (*OsWrapperImpl) ReadFile

func (o *OsWrapperImpl) ReadFile(path string) ([]byte, error)

func (*OsWrapperImpl) Remove

func (o *OsWrapperImpl) Remove(path string) error

func (*OsWrapperImpl) RemoveAll

func (o *OsWrapperImpl) RemoveAll(path string) error

func (*OsWrapperImpl) Sleep

func (o *OsWrapperImpl) Sleep(duration time.Duration)

func (*OsWrapperImpl) WriteFile

func (o *OsWrapperImpl) WriteFile(path string, data []byte, perm os.FileMode) error

type SimpleFile

type SimpleFile struct {
	Name  string
	IsDir bool
}

Jump to

Keyboard shortcuts

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