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

Function TestCmd_failUnCommitted

internal/cmdupdate/cmdupdate_test.go:110–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

108}
109
110func TestCmd_failUnCommitted(t *testing.T) {
111 g, w, clean := testutil.SetupDefaultRepoAndWorkspace(t, testutil.Dataset1)
112 defer clean()
113 dest := filepath.Join(w.WorkspaceDirectory, g.RepoName)
114
115 // clone the repo
116 getCmd := cmdget.NewRunner("kpt")
117 getCmd.Command.SetArgs([]string{"file://" + g.RepoDirectory + ".git", w.WorkspaceDirectory})
118 err := getCmd.Command.Execute()
119 if !assert.NoError(t, err) {
120 return
121 }
122 if !g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset1), dest) {
123 return
124 }
125
126 // update the master branch
127 if !assert.NoError(t, g.ReplaceData(testutil.Dataset2)) {
128 return
129 }
130
131 if !assert.NoError(t, g.Commit("new dataset")) {
132 return
133 }
134
135 // update the cloned package
136 updateCmd := cmdupdate.NewRunner("kpt")
137 if !assert.NoError(t, os.Chdir(w.WorkspaceDirectory)) {
138 return
139 }
140 updateCmd.Command.SetArgs([]string{g.RepoName})
141 err = updateCmd.Command.Execute()
142 if !assert.Error(t, err) {
143 return
144 }
145 assert.Contains(t, err.Error(), "must commit package")
146
147 if !g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset1), dest) {
148 return
149 }
150}
151
152// NoOpRunE is a noop function to replace the run function of a command. Useful for testing argument parsing.
153var NoOpRunE = func(cmd *cobra.Command, args []string) error { return nil }

Callers

nothing calls this directly

Calls 8

NewRunnerFunction · 0.92
NewRunnerFunction · 0.92
cleanFunction · 0.85
AssertEqualMethod · 0.80
ReplaceDataMethod · 0.65
CommitMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected