MCPcopy
hub / github.com/go-task/task / TestStatusChecksumMissingGenerated

Function TestStatusChecksumMissingGenerated

task_test.go:610–654  ·  view source on GitHub ↗

TestStatusChecksumMissingGenerated is a regression test for https://github.com/go-task/task/issues/1230. When using method: checksum, deleting a generated file should cause the task to re-run, not be skipped because the checksum file still matches.

(t *testing.T)

Source from the content-addressed store, hash-verified

608// When using method: checksum, deleting a generated file should cause the task to re-run,
609// not be skipped because the checksum file still matches.
610func TestStatusChecksumMissingGenerated(t *testing.T) { // nolint:paralleltest // cannot run in parallel
611 const dir = "testdata/checksum"
612
613 generatedFile := filepathext.SmartJoin(dir, "generated.txt")
614 tempDir := task.TempDir{
615 Remote: filepathext.SmartJoin(dir, ".task"),
616 Fingerprint: filepathext.SmartJoin(dir, ".task"),
617 }
618
619 // Clean up any state from previous runs.
620 _ = os.Remove(generatedFile)
621 _ = os.RemoveAll(filepathext.SmartJoin(dir, ".task"))
622
623 var buff bytes.Buffer
624 e := task.NewExecutor(
625 task.WithDir(dir),
626 task.WithStdout(&buff),
627 task.WithStderr(&buff),
628 task.WithTempDir(tempDir),
629 )
630 require.NoError(t, e.Setup())
631
632 // First run: task should execute and create generated.txt.
633 require.NoError(t, e.Run(t.Context(), &task.Call{Task: "build"}))
634 _, err := os.Stat(generatedFile)
635 require.NoError(t, err, "generated.txt should exist after first run")
636 buff.Reset()
637
638 // Second run: task should be up to date.
639 require.NoError(t, e.Run(t.Context(), &task.Call{Task: "build"}))
640 assert.Equal(t, `task: Task "build" is up to date`+"\n", buff.String())
641 buff.Reset()
642
643 // Delete the generated file (simulate a clean), but leave the checksum file.
644 require.NoError(t, os.Remove(generatedFile))
645 _, err = os.Stat(generatedFile)
646 require.Error(t, err, "generated.txt should be gone")
647
648 // Third run: task MUST re-run because generated.txt is missing.
649 // This is the regression: previously the task was incorrectly skipped.
650 require.NoError(t, e.Run(t.Context(), &task.Call{Task: "build"}))
651 assert.NotContains(t, buff.String(), "is up to date", "task should re-run when generated file is missing")
652 _, err = os.Stat(generatedFile)
653 require.NoError(t, err, "generated.txt should be recreated after third run")
654}
655
656func writeFile(t *testing.T, dir, name, content string) {
657 t.Helper()

Callers

nothing calls this directly

Calls 5

SetupMethod · 0.95
RunMethod · 0.95
SmartJoinFunction · 0.92
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…