testutil

package
v0.39.3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: Apache-2.0 Imports: 20 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 AssertPkgEqual added in v0.38.0

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

func Commit added in v0.18.0

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

Commit performs a git commit

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 PrintFile added in v0.38.0

func PrintFile(paths ...string) error

func PrintPackage added in v0.38.0

func PrintPackage(paths ...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 SetupDefaultRepoAndWorkspace

func SetupDefaultRepoAndWorkspace(t *testing.T, dataset string) (*TestGitRepo, *TestWorkspace, 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 Tag added in v0.18.0

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

Types

type Content added in v0.38.0

type Content struct {
	CreateBranch bool
	Branch       string
	Data         string
	Pkg          *pkgbuilder.Pkg
	Tag          string
	Message      string
}

type GitDirectory added in v0.38.0

type GitDirectory interface {
	CheckoutBranch(branch string, create bool) error
	ReplaceData(data string) error
	Commit(message string) error
	Tag(tagName string) error
}

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
}

TestGitRepo manages a local git repository for testing

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) DeleteBranch added in v0.35.0

func (g *TestGitRepo) DeleteBranch(branch string) error

DeleteBranch deletes the git branch in the repo

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(tagName string) error

Tag initializes tags the git repository

type TestSetupManager added in v0.38.0

type TestSetupManager struct {
	T *testing.T

	// GetRef is the git ref to fetch
	GetRef string

	// GetSubDirectory is the repo subdirectory containing the package
	GetSubDirectory string

	// UpstreamInit are made before fetching the repo
	UpstreamInit []Content

	// UpstreamChanges are upstream content changes made after cloning the repo
	UpstreamChanges []Content

	LocalChanges []Content

	UpstreamRepo *TestGitRepo

	LocalWorkspace *TestWorkspace
	// contains filtered or unexported fields
}

func (*TestSetupManager) AssertKptfile added in v0.38.0

func (g *TestSetupManager) AssertKptfile(name, commit, ref string) bool

func (*TestSetupManager) AssertKptfileEquals added in v0.38.0

func (g *TestSetupManager) AssertKptfileEquals(path, commit, ref string) bool

func (*TestSetupManager) AssertLocalDataEquals added in v0.38.0

func (g *TestSetupManager) AssertLocalDataEquals(path string) bool

func (*TestSetupManager) Clean added in v0.38.0

func (g *TestSetupManager) Clean()

func (*TestSetupManager) Init added in v0.38.0

func (g *TestSetupManager) Init(dataset string) bool

Init initializes test data - Setup a new upstream repo in a tmp directory - Set the initial upstream content to Dataset1 - Setup a new cache location for git repos and update the environment variable - Setup fetch the upstream package to a local package - Verify the local package contains the upstream content

func (*TestSetupManager) SetLocalData added in v0.38.0

func (g *TestSetupManager) SetLocalData(path string) bool

type TestWorkspace added in v0.37.0

type TestWorkspace struct {
	WorkspaceDirectory string
	PackageDir         string
}

func (*TestWorkspace) CheckoutBranch added in v0.37.0

func (w *TestWorkspace) CheckoutBranch(branch string, create bool) error

CheckoutBranch checks out the git branch in the repo

func (*TestWorkspace) Commit added in v0.37.0

func (w *TestWorkspace) Commit(message string) error

Commit performs a git commit

func (*TestWorkspace) FullPackagePath added in v0.38.0

func (w *TestWorkspace) FullPackagePath() string

FullPackagePath returns the full path to the roor package in the local workspace.

func (*TestWorkspace) RemoveAll added in v0.37.0

func (w *TestWorkspace) RemoveAll() error

func (*TestWorkspace) ReplaceData added in v0.37.0

func (w *TestWorkspace) ReplaceData(data string) error

ReplaceData replaces the data with a new source

func (*TestWorkspace) SetupTestWorkspace added in v0.37.0

func (w *TestWorkspace) SetupTestWorkspace() error

func (*TestWorkspace) Tag added in v0.37.0

func (w *TestWorkspace) Tag(tagName string) error

Tag initializes tags the git repository

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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