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

Function TestCmdMainBranch_execute

internal/cmdget/cmdget_test.go:74–120  ·  view source on GitHub ↗

TestCmdMainBranch_execute tests that get is correctly invoked if default branch is main and master branch doesn't exist

(t *testing.T)

Source from the content-addressed store, hash-verified

72// TestCmdMainBranch_execute tests that get is correctly invoked if default branch
73// is main and master branch doesn't exist
74func TestCmdMainBranch_execute(t *testing.T) {
75 // set up git repository with master and main branches
76 g, w, clean := testutil.SetupDefaultRepoAndWorkspace(t, testutil.Dataset1)
77 defer clean()
78 dest := filepath.Join(w.WorkspaceDirectory, g.RepoName)
79 err := g.CheckoutBranch("main", false)
80 if !assert.NoError(t, err) {
81 t.FailNow()
82 }
83 err = g.DeleteBranch("master")
84 if !assert.NoError(t, err) {
85 t.FailNow()
86 }
87
88 r := cmdget.NewRunner("kpt")
89 r.Command.SetArgs([]string{"file://" + g.RepoDirectory + ".git/", "./"})
90 err = r.Command.Execute()
91
92 assert.NoError(t, err)
93 g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset1), dest)
94
95 commit, err := g.GetCommit()
96 assert.NoError(t, err)
97 g.AssertKptfile(t, dest, kptfile.KptFile{
98 ResourceMeta: yaml.ResourceMeta{
99 ObjectMeta: yaml.ObjectMeta{
100 NameMeta: yaml.NameMeta{
101 Name: g.RepoName,
102 },
103 },
104 TypeMeta: yaml.TypeMeta{
105 APIVersion: kptfile.TypeMeta.APIVersion,
106 Kind: kptfile.TypeMeta.Kind},
107 },
108 PackageMeta: kptfile.PackageMeta{},
109 Upstream: kptfile.Upstream{
110 Type: "git",
111 Git: kptfile.Git{
112 Directory: "/",
113 Repo: "file://" + g.RepoDirectory,
114 Ref: "main",
115 Commit: commit, // verify the commit matches the repo
116 },
117 },
118 })
119
120}
121
122func TestCmd_stdin(t *testing.T) {
123 d, err := ioutil.TempDir("", "kpt")

Callers

nothing calls this directly

Calls 8

NewRunnerFunction · 0.92
cleanFunction · 0.85
DeleteBranchMethod · 0.80
AssertEqualMethod · 0.80
GetCommitMethod · 0.80
CheckoutBranchMethod · 0.65
AssertKptfileMethod · 0.45

Tested by

no test coverage detected