Documentation ¶
Index ¶
- Constants
- Variables
- func AddKptfileToWorkspace(t *testing.T, w *TestWorkspace, kf *kptfilev1.KptFile)
- func Chdir(t *testing.T, path string) func()
- func ConfigureTestKptCache(m *testing.M) int
- func Diff(sourceDir, destDir string, addMergeCommentsToSource bool) (sets.String, error)
- func GetTestDataPath() (string, error)
- func KptfileAwarePkgEqual(t *testing.T, pkg1, pkg2 string, addMergeCommentsToSource bool) bool
- func PrintFile(paths ...string) error
- func PrintPackage(paths ...string) error
- func SetupRepoAndWorkspace(t *testing.T, content Content) (*TestGitRepo, *TestWorkspace, func())
- func SetupRepos(t *testing.T, repoContent map[string][]Content) (map[string]*TestGitRepo, func())
- func UpdateGitDir(t *testing.T, name string, gitDir GitDirectory, changes []Content, ...) error
- func UpdateRepos(t *testing.T, repos map[string]*TestGitRepo, repoContent map[string][]Content) error
- type Content
- type GitDirectory
- type ReposInfo
- type TestGitRepo
- func (g *TestGitRepo) AssertEqual(t *testing.T, sourceDir, destDir string, addMergeCommentsToSource bool) bool
- func (g *TestGitRepo) AssertKptfile(t *testing.T, cloned string, kpkg kptfilev1.KptFile) bool
- func (g *TestGitRepo) CheckoutBranch(branch string, create bool) error
- func (g *TestGitRepo) Commit(message string) (string, error)
- func (g *TestGitRepo) CustomUpdate(f func(string) error) 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(name string, data []Content, repos map[string]*TestGitRepo) error
- func (g *TestGitRepo) Tag(tagName string) error
- type TestSetupManager
- type TestWorkspace
- func (w *TestWorkspace) CheckoutBranch(branch string, create bool) error
- func (w *TestWorkspace) Commit(message string) (string, error)
- func (w *TestWorkspace) CustomUpdate(f func(string) error) 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 ( Upstream = "upstream" Local = "local" )
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" )
const TmpDirPrefix = "test-kpt"
Variables ¶
var AssertNoError = assertnow.NilError
var EmptyReposInfo = &ReposInfo{}
var KptfileSet = diffSet(kptfilev1.KptFileName)
Functions ¶
func AddKptfileToWorkspace ¶
func AddKptfileToWorkspace(t *testing.T, w *TestWorkspace, kf *kptfilev1.KptFile)
AddKptfileToWorkspace writes the provided Kptfile to the workspace and makes a commit.
func ConfigureTestKptCache ¶
ConfigureTestKptCache sets up a temporary directory for the kpt git cache, sets the env variable so it will be used for tests, and cleans up the directory afterwards.
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 KptfileAwarePkgEqual ¶
KptfileAwarePkgEqual compares two packages (including any subpackages) and has special handling of Kptfiles to handle fields that contain values which cannot easily be specified in the golden package.
func PrintPackage ¶ added in v0.38.0
func SetupRepoAndWorkspace ¶
func SetupRepoAndWorkspace(t *testing.T, content Content) (*TestGitRepo, *TestWorkspace, func())
SetupRepoAndWorkspace 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 SetupRepos ¶
SetupRepos creates repos and returns a mapping from name to TestGitRepos. This only creates the first version of each repo as given by the first item in the repoContent slice.
func UpdateGitDir ¶
func UpdateGitDir(t *testing.T, name string, gitDir GitDirectory, changes []Content, repos map[string]*TestGitRepo) error
func UpdateRepos ¶
func UpdateRepos(t *testing.T, repos map[string]*TestGitRepo, repoContent map[string][]Content) error
UpdateRepos updates the existing repos with any additional Content items in the repoContent slice.
Types ¶
type Content ¶ added in v0.38.0
type Content struct { CreateBranch bool Branch string Data string Pkg *pkgbuilder.RootPkg Tag string Message string // UpdateFunc is invoked after the repo has been updated with the new // content, but before it is committed. This allows for making changes // that isn't supported by the pkgbuilder (like creating symlinks). UpdateFunc func(path string) error }
type GitDirectory ¶ added in v0.38.0
type ReposInfo ¶
type ReposInfo struct {
// contains filtered or unexported fields
}
func ToReposInfo ¶
func ToReposInfo(repos map[string]*TestGitRepo) *ReposInfo
func (*ReposInfo) ResolveCommitIndex ¶
type TestGitRepo ¶
type TestGitRepo struct { T *testing.T // 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 // Commits keeps track of the commit shas for the changes // to the repo. Commits []string }
TestGitRepo manages a local git repository for testing
func (*TestGitRepo) AssertEqual ¶
func (g *TestGitRepo) AssertEqual(t *testing.T, sourceDir, destDir string, addMergeCommentsToSource bool) 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) (string, error)
Commit performs a git commit and returns the SHA for the newly created commit.
func (*TestGitRepo) CustomUpdate ¶
func (g *TestGitRepo) CustomUpdate(f func(string) error) error
CustomUpdate executes the provided update function and passes in the path to the directory of the repository.
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(name string, data []Content, repos map[string]*TestGitRepo) 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 // ReposChanges are content for any repos. ReposChanges map[string][]Content LocalChanges []Content Repos map[string]*TestGitRepo LocalWorkspace *TestWorkspace // contains filtered or unexported fields }
func (*TestSetupManager) AssertKptfile ¶ added in v0.38.0
func (g *TestSetupManager) AssertKptfile(name, commit, ref string, strategy kptfilev1.UpdateStrategyType) bool
func (*TestSetupManager) AssertLocalDataEquals ¶ added in v0.38.0
func (g *TestSetupManager) AssertLocalDataEquals(path string, addMergeCommentToSource bool) 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() 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
type TestWorkspace ¶ added in v0.37.0
func SetupReposAndWorkspace ¶
func SetupReposAndWorkspace(t *testing.T, reposContent map[string][]Content) (map[string]*TestGitRepo, *TestWorkspace, func())
SetupReposAndWorkspace handles setting up a set of repos as specified by the reposContent and a workspace to clone into. It returns a cleanup function that will remove the repos.
func SetupWorkspace ¶
func SetupWorkspace(t *testing.T) (*TestWorkspace, func())
SetupWorkspace creates a local workspace which kpt packages can be cloned into. It returns a cleanup function that will remove the workspace.
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) (string, error)
Commit performs a git commit
func (*TestWorkspace) CustomUpdate ¶
func (w *TestWorkspace) CustomUpdate(f func(string) error) error
CustomUpdate executes the provided update function and passes in the path to the directory of the repository.
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