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

Function TestCommand_RunCombinedDiff

internal/util/diff/diff_test.go:118–179  ·  view source on GitHub ↗

TestCommand_RunCombinedDiff verifies Command can show changes for combined 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 combined diff

(t *testing.T)

Source from the content-addressed store, hash-verified

116// 5. add more data to the master branch, commit it
117// 5. Run combined diff between master and cloned
118func TestCommand_RunCombinedDiff(t *testing.T) {
119 g, w, clean := testutil.SetupDefaultRepoAndWorkspace(t, testutil.Dataset1)
120 defer clean()
121
122 // create a commit with dataset2 and tag it v2, then add another commit on top with dataset3
123 commit0, err := g.GetCommit()
124 assert.NoError(t, err)
125 err = g.ReplaceData(testutil.Dataset2)
126 assert.NoError(t, err)
127 err = g.Commit("new-data for v2")
128 assert.NoError(t, err)
129 commit, err := g.GetCommit()
130 assert.NoError(t, err)
131 err = g.Tag("v2")
132 assert.NoError(t, err)
133 err = g.ReplaceData(testutil.Dataset3)
134 assert.NoError(t, err)
135 err = g.Commit("new-data post-v2")
136 assert.NoError(t, err)
137 commit2, err := g.GetCommit()
138 assert.NoError(t, err)
139 assert.NotEqual(t, commit, commit0)
140 assert.NotEqual(t, commit, commit2)
141
142 err = get.Command{Git: kptfile.Git{
143 Repo: g.RepoDirectory, Ref: "refs/tags/v2", Directory: "/"},
144 Destination: filepath.Base(g.RepoDirectory)}.Run()
145 assert.NoError(t, err)
146
147 localPkg := filepath.Join(w.WorkspaceDirectory, g.RepoName)
148
149 diffOutput := &bytes.Buffer{}
150
151 err = (&Command{
152 Path: localPkg,
153 Ref: "master",
154 DiffType: "combined",
155 DiffTool: "diff",
156 DiffToolOpts: "-r -i -w",
157 Output: diffOutput,
158 }).Run()
159 assert.NoError(t, err)
160
161 filteredOutput := filterDiffMetadata(diffOutput)
162
163 diffTestOutputDir := filepath.Join(g.DatasetDirectory, testutil.DiffOutput)
164 diffOutputGoldenFile := filepath.Join(diffTestOutputDir, "combined_v2_master.txt")
165
166 // If KPT_GENERATE_DIFF_TEST_GOLDEN_FILE env is set, update the golden
167 // files.
168 if os.Getenv("KPT_GENERATE_DIFF_TEST_GOLDEN_FILE") != "" {
169 err = ioutil.WriteFile(diffOutputGoldenFile, []byte(filteredOutput), 0666)
170 if err != nil {
171 t.Errorf("error writing golden output file: %v", err)
172 return
173 }
174 return
175 }

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