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

Function TestCommand_RunRemoteDiff

internal/util/diff/diff_test.go:45–107  ·  view source on GitHub ↗

TestCommand_RunRemoteDiff verifies Command can show changes for remote 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. Run remote diff betwee

(t *testing.T)

Source from the content-addressed store, hash-verified

43// 5. add more data to the master branch, commit it
44// 5. Run remote diff between master and cloned
45func TestCommand_RunRemoteDiff(t *testing.T) {
46 t.SkipNow()
47 g, w, clean := testutil.SetupDefaultRepoAndWorkspace(t, testutil.Dataset1)
48 defer clean()
49
50 // create a commit with dataset2 and tag it v2, then add another commit on top with dataset3
51 commit0, err := g.GetCommit()
52 assert.NoError(t, err)
53 err = g.ReplaceData(testutil.Dataset2)
54 assert.NoError(t, err)
55 err = g.Commit("new-data for v2")
56 assert.NoError(t, err)
57 commit, err := g.GetCommit()
58 assert.NoError(t, err)
59 err = g.Tag("v2")
60 assert.NoError(t, err)
61 err = g.ReplaceData(testutil.Dataset3)
62 assert.NoError(t, err)
63 err = g.Commit("new-data post-v2")
64 assert.NoError(t, err)
65 commit2, err := g.GetCommit()
66 assert.NoError(t, err)
67 assert.NotEqual(t, commit, commit0)
68 assert.NotEqual(t, commit, commit2)
69
70 err = get.Command{Git: kptfile.Git{
71 Repo: g.RepoDirectory, Ref: "refs/tags/v2", Directory: "/"},
72 Destination: filepath.Base(g.RepoDirectory)}.Run()
73 assert.NoError(t, err)
74
75 localPkg := filepath.Join(w.WorkspaceDirectory, g.RepoName)
76
77 diffOutput := &bytes.Buffer{}
78
79 err = (&Command{
80 Path: localPkg,
81 Ref: "master",
82 DiffType: "remote",
83 DiffTool: "diff",
84 DiffToolOpts: "-r -i -w",
85 Output: diffOutput,
86 }).Run()
87 assert.NoError(t, err)
88
89 filteredOutput := filterDiffMetadata(diffOutput)
90
91 diffTestOutputDir := filepath.Join(g.DatasetDirectory, testutil.DiffOutput)
92 diffOutputGoldenFile := filepath.Join(diffTestOutputDir, "remote_v2_master.txt")
93
94 // If KPT_GENERATE_DIFF_TEST_GOLDEN_FILE env is set, update the golden
95 // files.
96 if os.Getenv("KPT_GENERATE_DIFF_TEST_GOLDEN_FILE") != "" {
97 err = ioutil.WriteFile(diffOutputGoldenFile, []byte(filteredOutput), 0666)
98 if err != nil {
99 t.Errorf("error writing golden output file: %v", err)
100 return
101 }
102 return

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