MCPcopy
hub / github.com/kptdev/kpt / TestCommand_Run_branch

Function TestCommand_Run_branch

internal/util/get/get_test.go:229–280  ·  view source on GitHub ↗

TestCommand_Run_branch verifies Command can clone a git branch 1. create a new branch 2. add data to the branch 3. checkout the master branch again 4. clone the new branch 5. verify contents match the new branch

(t *testing.T)

Source from the content-addressed store, hash-verified

227// 4. clone the new branch
228// 5. verify contents match the new branch
229func TestCommand_Run_branch(t *testing.T) {
230 g, w, clean := testutil.SetupDefaultRepoAndWorkspace(t, testutil.Dataset1)
231 defer clean()
232
233 // add commits to the exp branch
234 err := g.CheckoutBranch("exp", true)
235 assert.NoError(t, err)
236 err = g.ReplaceData(testutil.Dataset2)
237 assert.NoError(t, err)
238 err = g.Commit("new dataset")
239 assert.NoError(t, err)
240 commit, err := g.GetCommit()
241 assert.NoError(t, err)
242 err = g.CheckoutBranch("master", false)
243 assert.NoError(t, err)
244 commit2, err := g.GetCommit()
245 assert.NoError(t, err)
246 assert.NotEqual(t, commit, commit2)
247
248 err = Command{
249 Git: kptfile.Git{Repo: g.RepoDirectory, Ref: "refs/heads/exp", Directory: "/"},
250 Destination: filepath.Base(g.RepoDirectory)}.Run()
251 assert.NoError(t, err)
252
253 // verify the cloned contents matches the repository
254 r := filepath.Join(w.WorkspaceDirectory, g.RepoName)
255 g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset2), r)
256
257 // verify the KptFile contains the expected values
258 g.AssertKptfile(t, r, kptfile.KptFile{
259 ResourceMeta: yaml.ResourceMeta{
260 ObjectMeta: yaml.ObjectMeta{
261 NameMeta: yaml.NameMeta{
262 Name: g.RepoName,
263 },
264 },
265 TypeMeta: yaml.TypeMeta{
266 APIVersion: kptfile.TypeMeta.APIVersion,
267 Kind: kptfile.TypeMeta.Kind},
268 },
269 PackageMeta: kptfile.PackageMeta{},
270 Upstream: kptfile.Upstream{
271 Type: "git",
272 Git: kptfile.Git{
273 Directory: "/",
274 Repo: g.RepoDirectory,
275 Ref: "refs/heads/exp",
276 Commit: commit,
277 },
278 },
279 })
280}
281
282// TestCommand_Run_tag verifies Command can clone from a git tag
283//

Callers

nothing calls this directly

Calls 9

cleanFunction · 0.85
GetCommitMethod · 0.80
AssertEqualMethod · 0.80
CheckoutBranchMethod · 0.65
ReplaceDataMethod · 0.65
CommitMethod · 0.65
RunMethod · 0.45
AssertKptfileMethod · 0.45

Tested by

no test coverage detected