testutils

package
v0.0.0-...-14dca07 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestUser = user.User{
	Uid:      "1",
	Gid:      "2",
	Username: "evg4b",
	Name:     "Evgeny Abramovich",
	HomeDir:  filepath.Join("usr", "home"),
}

TestUser is os/user.User stub.

Functions

func AssertError

func AssertError(t *testing.T, expected string, actual error)

AssertError error by string, where expected string is empty then error should be null. Otherwise error message should be matched to string.

func AssertSlice

func AssertSlice(t *testing.T, expected, actual []string)

func ConfigureFakeExec

func ConfigureFakeExec(helperTest string) (CmdBuilder, EnvBuilder)

ConfigureFakeExec configures exec.Cmd builder mock to call passed helper test (helper test should be located in the package with test).

func CreateRepo

func CreateRepo(t *testing.T) (*vcs.GitRepository, *git.Repository, billy.Filesystem, *git.Worktree)

CreateRepo creates vcs.GitRepository and all dependencies.

func DecodeYaml

func DecodeYaml(source string, object any) error

DecodeYaml decodes object from yaml string (KnownFields = true).

func ExecTestHandler

func ExecTestHandler(t *testing.T, cases map[string]func())

ExecTestHandler configure helper test to check executed command. Key is concatenation program with arguments e.g. 'go test ./..'.

func FsFromMap

func FsFromMap(t *testing.T, files map[string]string) billy.Filesystem

FsFromMap creates billy.Filesystem in memory from map. Where key is a filename and value is file context.

func FsFromSlice

func FsFromSlice(t *testing.T, files []string) billy.Filesystem

FsFromMap creates billy.Filesystem in memory from slice. Each element of slice is filename, content always "test".

func MakeCommits

func MakeCommits(t *testing.T, wt *git.Worktree, fs billy.Basic, data map[string]map[string]string)

MakeCommits creates commits history from two-dimensional map. First level key is a commit message, second key is a file name and value is a file content.

func MakeFiles

func MakeFiles(t *testing.T, fs billy.Basic, files map[string]string)

MakeFiles creates in billy.Filesystem files from map. Where key is a filename and value is file context.

func NopCloser

func NopCloser(wr io.Writer) io.WriteCloser

NopCloser transforms io.Writer to io.WriteCloser.

Types

type CmdBuilder

type CmdBuilder = func(context.Context, string, ...string) *exec.Cmd

type EnvBuilder

type EnvBuilder = func([]string) []string

Jump to

Keyboard shortcuts

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