Documentation ¶
Index ¶
- Constants
- Variables
- func AssertPkgEqual(t *testing.T, g *TestGitRepo, sourceDir, destDir string)
- func Commit(t *testing.T, g *TestGitRepo, message string)
- func CommitTag(t *testing.T, g *TestGitRepo, tag string)
- func Compare(t *testing.T, a, b string)
- func CopyData(t *testing.T, g *TestGitRepo, data, dest string)
- func CopyKptfile(t *testing.T, src, dest string)
- func Diff(sourceDir, destDir string) (sets.String, error)
- func GetTestDataPath() (string, error)
- func PrintFile(paths ...string) error
- func PrintPackage(paths ...string) error
- func RemoveData(t *testing.T, g *TestGitRepo)
- func Replace(t *testing.T, path, old, new string)
- func SetupDefaultRepoAndWorkspace(t *testing.T, dataset string) (*TestGitRepo, *TestWorkspace, func())
- func Tag(t *testing.T, g *TestGitRepo, tag string)
- type Content
- type GitDirectory
- type TestGitRepo
- func (g *TestGitRepo) AssertEqual(t *testing.T, sourceDir, destDir string) bool
- func (g *TestGitRepo) AssertKptfile(t *testing.T, cloned string, kpkg kptfile.KptFile) bool
- func (g *TestGitRepo) CheckoutBranch(branch string, create bool) error
- func (g *TestGitRepo) Commit(message string) error
- func (g *TestGitRepo) DeleteBranch(branch string) error
- func (g *TestGitRepo) GetCommit() (string, error)
- func (g *TestGitRepo) RemoveAll() error
- func (g *TestGitRepo) ReplaceData(data string) error
- func (g *TestGitRepo) SetupTestGitRepo(data string) error
- func (g *TestGitRepo) Tag(tagName string) error
- type TestSetupManager
- func (g *TestSetupManager) AssertKptfile(name, commit, ref string) bool
- func (g *TestSetupManager) AssertKptfileEquals(path, commit, ref string) bool
- func (g *TestSetupManager) AssertLocalDataEquals(path string) bool
- func (g *TestSetupManager) Clean()
- func (g *TestSetupManager) Init(dataset string) bool
- func (g *TestSetupManager) SetLocalData(path string) bool
- type TestWorkspace
- func (w *TestWorkspace) CheckoutBranch(branch string, create bool) error
- func (w *TestWorkspace) Commit(message string) error
- func (w *TestWorkspace) FullPackagePath() string
- func (w *TestWorkspace) RemoveAll() error
- func (w *TestWorkspace) ReplaceData(data string) error
- func (w *TestWorkspace) SetupTestWorkspace() error
- func (w *TestWorkspace) Tag(tagName string) error
Constants ¶
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" )
const TmpDirPrefix = "test-kpt"
Variables ¶
var AssertNoError = assertnow.NilError
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 CopyKptfile ¶ added in v0.18.0
func Diff ¶ added in v0.26.0
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 PrintPackage ¶ added in v0.38.0
func RemoveData ¶ added in v0.18.0
func RemoveData(t *testing.T, g *TestGitRepo)
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.
Types ¶
type GitDirectory ¶ added in v0.38.0
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 ¶
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
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