testutil

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Dataset1              = "dataset1"
	Dataset2              = "dataset2"
	Dataset3              = "dataset3"
	Dataset4              = "dataset4" // Dataset4 is replica of Dataset2 with different setter values
	Dataset5              = "dataset5" // Dataset5 is replica of Dataset2 with additional non KRM files
	DatasetMerged         = "datasetmerged"
	DiffOutput            = "diff_output"
	UpdateMergeConflict   = "updateMergeConflict"
	HelloWorldSet         = "helloworld-set"
	HelloWorldFn          = "helloworld-fn"
	HelloWorldFnNoKptfile = "helloworld-fn-no-kptfile"
)
View Source
const TmpDirPrefix = "test-kpt"

Variables

View Source
var AssertNoError = assertnow.NilError
View Source
var KptfileSet = func() sets.String {
	s := sets.String{}
	s.Insert(kptfile.KptFileName)
	return s
}()

Functions

func AssertEqual added in v0.18.0

func AssertEqual(t *testing.T, g *TestGitRepo, sourceDir, destDir string)

func Commit added in v0.18.0

func Commit(t *testing.T, g *TestGitRepo, message string)

func CommitTag added in v0.18.0

func CommitTag(t *testing.T, g *TestGitRepo, tag string)

func Compare added in v0.18.0

func Compare(t *testing.T, a, b string)

func CopyData added in v0.18.0

func CopyData(t *testing.T, g *TestGitRepo, data, dest string)

func CopyKptfile added in v0.18.0

func CopyKptfile(t *testing.T, src, dest string)

func Diff added in v0.26.0

func Diff(sourceDir, destDir string) (sets.String, error)

Diff returns a list of files that differ between the source and destination.

Diff is guaranteed to return a non-empty set if any files differ, but this set is not guaranteed to contain all differing files.

func GetTestDataPath added in v0.18.0

func GetTestDataPath() (string, error)

func RemoveData added in v0.18.0

func RemoveData(t *testing.T, g *TestGitRepo)

func Replace added in v0.18.0

func Replace(t *testing.T, path, old, new string)

func Tag added in v0.18.0

func Tag(t *testing.T, g *TestGitRepo, tag string)

Types

type TestGitRepo

type TestGitRepo struct {
	// RepoDirectory is the temp directory of the git repo
	RepoDirectory string

	// DatasetDirectory is the directory of the testdata files
	DatasetDirectory string

	// RepoName is the name of the repository
	RepoName string

	Updater string
}

TestGitRepo manages a local git repository for testing

func SetupDefaultRepoAndWorkspace

func SetupDefaultRepoAndWorkspace(t *testing.T) (*TestGitRepo, string, func())

SetupDefaultRepoAndWorkspace handles setting up a default repo to clone, and a workspace to clone into. returns a cleanup function to remove the git repo and workspace.

func (*TestGitRepo) AssertEqual

func (g *TestGitRepo) AssertEqual(t *testing.T, sourceDir, destDir string) bool

AssertEqual verifies the contents of a source package matches the contents of the destination package it was fetched to. Excludes comparing the .git directory in the source package.

While the sourceDir can be the TestGitRepo, because tests change the TestGitRepo may have been changed after the destDir was copied, it is often better to explicitly use a set of golden files as the sourceDir rather than the original TestGitRepo that was copied.

func (*TestGitRepo) AssertKptfile

func (g *TestGitRepo) AssertKptfile(t *testing.T, cloned string, kpkg kptfile.KptFile) bool

AssertKptfile verifies the contents of the KptFile matches the provided value.

func (*TestGitRepo) CheckoutBranch

func (g *TestGitRepo) CheckoutBranch(branch string, create bool) error

CheckoutBranch checks out the git branch in the repo

func (*TestGitRepo) Commit

func (g *TestGitRepo) Commit(message string) error

Commit performs a git commit

func (*TestGitRepo) CopyAddData

func (g *TestGitRepo) CopyAddData(data string) error

CopyAddData copies data from a source and adds it

func (*TestGitRepo) GetCommit

func (g *TestGitRepo) GetCommit() (string, error)

func (*TestGitRepo) RemoveAll

func (g *TestGitRepo) RemoveAll() error

RemoveAll deletes the test git repo

func (*TestGitRepo) ReplaceData

func (g *TestGitRepo) ReplaceData(data string) error

ReplaceData replaces the data with a new source

func (*TestGitRepo) SetupTestGitRepo

func (g *TestGitRepo) SetupTestGitRepo(data string) error

SetupTestGitRepo initializes a new git repository and populates it with data from a source

func (*TestGitRepo) Tag

func (g *TestGitRepo) Tag(tag string) error

Tag initializes tags the git repository

Jump to

Keyboard shortcuts

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