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

Function TestCommand_Run_LocalDiff

internal/util/diff/diff_test.go:191–249  ·  view source on GitHub ↗

TestCommand_RunLocalDiff verifies Command can show changes for local diff operation. 1. add data to the master branch 2. commit and tag the master branch 3. add more data to the master branch, commit it 4. clone at the tag 5. add more data to the master branch, commit it 5. Update cloned package wi

(t *testing.T)

Source from the content-addressed store, hash-verified

189// 5. Update cloned package with dataset3
190// 6. Run remote diff and verify the output
191func TestCommand_Run_LocalDiff(t *testing.T) {
192 g, w, clean := testutil.SetupDefaultRepoAndWorkspace(t, testutil.Dataset1)
193 defer clean()
194
195 // create a commit with dataset2 and tag it v2, then add another commit on top with dataset3
196 commit0, err := g.GetCommit()
197 assert.NoError(t, err)
198 err = g.ReplaceData(testutil.Dataset2)
199 assert.NoError(t, err)
200 err = g.Commit("new-data for v2")
201 assert.NoError(t, err)
202 commit, err := g.GetCommit()
203 assert.NoError(t, err)
204 err = g.Tag("v2")
205 assert.NoError(t, err)
206 assert.NotEqual(t, commit, commit0)
207
208 err = get.Command{Git: kptfile.Git{
209 Repo: g.RepoDirectory, Ref: "refs/tags/v2", Directory: "/"},
210 Destination: filepath.Base(g.RepoDirectory)}.Run()
211 assert.NoError(t, err)
212
213 localPkg := filepath.Join(w.WorkspaceDirectory, g.RepoName)
214
215 // make changes in local package
216 err = copyutil.CopyDir(filepath.Join(g.DatasetDirectory, testutil.Dataset3), localPkg)
217 assert.NoError(t, err)
218
219 diffOutput := &bytes.Buffer{}
220
221 err = (&Command{
222 Path: localPkg,
223 Ref: "master",
224 DiffType: "combined",
225 DiffTool: "diff",
226 DiffToolOpts: "-r -i -w",
227 Output: diffOutput,
228 }).Run()
229 assert.NoError(t, err)
230
231 filteredOutput := filterDiffMetadata(diffOutput)
232
233 diffTestOutputDir := filepath.Join(g.DatasetDirectory, testutil.DiffOutput)
234 diffOutputGoldenFile := filepath.Join(diffTestOutputDir, "local_dataset3_v2.txt")
235
236 // If KPT_GENERATE_DIFF_TEST_GOLDEN_FILE env is set, update the golden
237 // files.
238 if os.Getenv("KPT_GENERATE_DIFF_TEST_GOLDEN_FILE") != "" {
239 err = ioutil.WriteFile(diffOutputGoldenFile, []byte(filteredOutput), 0666)
240 if err != nil {
241 t.Errorf("error writing golden output file: %v", err)
242 return
243 }
244 return
245 }
246 expOut, err := ioutil.ReadFile(diffOutputGoldenFile)
247 assert.NoError(t, err)
248 assert.Equal(t, string(expOut), filteredOutput)

Callers

nothing calls this directly

Calls 8

cleanFunction · 0.85
filterDiffMetadataFunction · 0.85
GetCommitMethod · 0.80
ReplaceDataMethod · 0.65
CommitMethod · 0.65
TagMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected