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

Function TestCommand_Run_failClean

internal/util/get/get_test.go:441–521  ·  view source on GitHub ↗

TestCommand_Run_failClean verifies that the Command will not clean the existing directory if it fails to clone. 1. clone the master branch 2. clone a non-existing branch 3. verify the master branch data is still present

(t *testing.T)

Source from the content-addressed store, hash-verified

439// 2. clone a non-existing branch
440// 3. verify the master branch data is still present
441func TestCommand_Run_failClean(t *testing.T) {
442 g, w, clean := testutil.SetupDefaultRepoAndWorkspace(t, testutil.Dataset1)
443 defer clean()
444
445 err := Command{Git: kptfile.Git{
446 Repo: g.RepoDirectory, Ref: "master", Directory: "/"},
447 Destination: filepath.Base(g.RepoDirectory),
448 }.Run()
449 assert.NoError(t, err)
450
451 // verify the KptFile contains the expected values
452 commit, err := g.GetCommit()
453 assert.NoError(t, err)
454
455 // verify the cloned contents matches the repository
456 r := filepath.Join(w.WorkspaceDirectory, g.RepoName)
457 g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset1), r)
458 g.AssertKptfile(t, r, kptfile.KptFile{
459 ResourceMeta: yaml.ResourceMeta{
460 ObjectMeta: yaml.ObjectMeta{
461 NameMeta: yaml.NameMeta{
462 Name: g.RepoName,
463 },
464 },
465 TypeMeta: yaml.TypeMeta{
466 APIVersion: kptfile.TypeMeta.APIVersion,
467 Kind: kptfile.TypeMeta.Kind},
468 },
469 PackageMeta: kptfile.PackageMeta{},
470 Upstream: kptfile.Upstream{
471 Type: "git",
472 Git: kptfile.Git{
473 Directory: "/",
474 Repo: g.RepoDirectory,
475 Ref: "master",
476 Commit: commit, // verify the commit matches the repo
477 },
478 },
479 })
480
481 // configure clone to clean the existing dir, but fail
482 err = Command{
483 Git: kptfile.Git{Repo: g.RepoDirectory, Ref: "refs/heads/not-real", Directory: "/"},
484 Destination: filepath.Base(g.RepoDirectory),
485 Clean: true,
486 }.Run()
487 if !assert.Error(t, err) {
488 t.FailNow()
489 }
490 if !assert.Contains(t, err.Error(), "refs/heads/not-real") {
491 t.FailNow()
492 }
493 if !assert.Contains(t, err.Error(), "exit status 128") {
494 t.FailNow()
495 }
496
497 // verify files weren't deleted
498 g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset1), r)

Callers

nothing calls this directly

Calls 7

cleanFunction · 0.85
GetCommitMethod · 0.80
AssertEqualMethod · 0.80
RunMethod · 0.45
AssertKptfileMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected