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

Function TestCommand_Run_localPackageChanges

internal/util/update/update_test.go:259–356  ·  view source on GitHub ↗

TestCommand_Run_localPackageChanges updates a package that has been locally modified - Get a package using a branch ref - Modify upstream with new content - Modify local package with new content - Update the local package to fetch the upstream content

(t *testing.T)

Source from the content-addressed store, hash-verified

257// - Modify local package with new content
258// - Update the local package to fetch the upstream content
259func TestCommand_Run_localPackageChanges(t *testing.T) {
260 updates := []struct {
261 updater StrategyType // update strategy type
262 expectedData string // expect
263 expectedErr string
264 expectedCommit func(writer *testutil.TestSetupManager) string
265 }{
266 {FastForward,
267 testutil.Dataset3, // expect no changes to the data
268 "local package files have been modified", // expect an error
269 func(writer *testutil.TestSetupManager) string { // expect Kptfile to keep the commit
270 f, err := kptfileutil.ReadFile(filepath.Join(writer.LocalWorkspace.WorkspaceDirectory, writer.UpstreamRepo.RepoName))
271 if !assert.NoError(writer.T, err) {
272 return ""
273 }
274 return f.Upstream.Git.Commit
275 },
276 },
277 // forcedeletereplace should reset hard to dataset 2 -- upstream modified copy
278 {ForceDeleteReplace,
279 testutil.Dataset2, // expect the upstream changes
280 "", // expect no error
281 func(writer *testutil.TestSetupManager) string {
282 c, _ := writer.UpstreamRepo.GetCommit() // expect the upstream commit
283 return c
284 },
285 },
286 // gitpatch should create a merge conflict between 2 and 3
287 {AlphaGitPatch,
288 testutil.UpdateMergeConflict, // expect a merge conflict
289 "Failed to merge in the changes", // expect an error
290 func(writer *testutil.TestSetupManager) string {
291 c, _ := writer.UpstreamRepo.GetCommit() // expect the upstream commit as a staged change
292 return c
293 },
294 },
295 {KResourceMerge,
296 testutil.DatasetMerged, // expect a merge conflict
297 "", // expect an error
298 func(writer *testutil.TestSetupManager) string {
299 c, _ := writer.UpstreamRepo.GetCommit() // expect the upstream commit as a staged change
300 return c
301 },
302 },
303 }
304 for i := range updates {
305 u := updates[i]
306 t.Run(string(u.updater), func(t *testing.T) {
307 g := &testutil.TestSetupManager{
308 T: t,
309 // Update upstream to Dataset2
310 UpstreamChanges: []testutil.Content{{Data: testutil.Dataset2}},
311 }
312 defer g.Clean()
313 if !g.Init(testutil.Dataset1) {
314 t.FailNow()
315 }
316

Callers

nothing calls this directly

Calls 10

CleanMethod · 0.95
InitMethod · 0.95
SetLocalDataMethod · 0.95
AssertLocalDataEqualsMethod · 0.95
AssertKptfileMethod · 0.95
ReadFileFunction · 0.92
toAbsPathFunction · 0.85
GetCommitMethod · 0.80
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected