| 499 | } |
| 500 | |
| 501 | func TestStatusChecksum(t *testing.T) { // nolint:paralleltest // cannot run in parallel |
| 502 | const dir = "testdata/checksum" |
| 503 | |
| 504 | tests := []struct { |
| 505 | files []string |
| 506 | task string |
| 507 | }{ |
| 508 | {[]string{"generated.txt", ".task/checksum/build"}, "build"}, |
| 509 | {[]string{"generated-wildcard.txt", ".task/checksum/build-wildcard"}, "build-wildcard"}, |
| 510 | {[]string{"generated.txt", ".task/checksum/build-with-status"}, "build-with-status"}, |
| 511 | } |
| 512 | |
| 513 | for _, test := range tests { // nolint:paralleltest // cannot run in parallel |
| 514 | t.Run(test.task, func(t *testing.T) { |
| 515 | for _, f := range test.files { |
| 516 | _ = os.Remove(filepathext.SmartJoin(dir, f)) |
| 517 | |
| 518 | _, err := os.Stat(filepathext.SmartJoin(dir, f)) |
| 519 | require.Error(t, err) |
| 520 | } |
| 521 | |
| 522 | var buff bytes.Buffer |
| 523 | tempDir := task.TempDir{ |
| 524 | Remote: filepathext.SmartJoin(dir, ".task"), |
| 525 | Fingerprint: filepathext.SmartJoin(dir, ".task"), |
| 526 | } |
| 527 | e := task.NewExecutor( |
| 528 | task.WithDir(dir), |
| 529 | task.WithStdout(&buff), |
| 530 | task.WithStderr(&buff), |
| 531 | task.WithTempDir(tempDir), |
| 532 | ) |
| 533 | require.NoError(t, e.Setup()) |
| 534 | |
| 535 | require.NoError(t, e.Run(t.Context(), &task.Call{Task: test.task})) |
| 536 | for _, f := range test.files { |
| 537 | _, err := os.Stat(filepathext.SmartJoin(dir, f)) |
| 538 | require.NoError(t, err) |
| 539 | } |
| 540 | |
| 541 | // Capture the modification time, so we can ensure the checksum file |
| 542 | // is not regenerated when the hash hasn't changed. |
| 543 | s, err := os.Stat(filepathext.SmartJoin(tempDir.Fingerprint, "checksum/"+test.task)) |
| 544 | require.NoError(t, err) |
| 545 | time := s.ModTime() |
| 546 | |
| 547 | buff.Reset() |
| 548 | require.NoError(t, e.Run(t.Context(), &task.Call{Task: test.task})) |
| 549 | assert.Equal(t, `task: Task "`+test.task+`" is up to date`+"\n", buff.String()) |
| 550 | |
| 551 | s, err = os.Stat(filepathext.SmartJoin(tempDir.Fingerprint, "checksum/"+test.task)) |
| 552 | require.NoError(t, err) |
| 553 | assert.Equal(t, time, s.ModTime()) |
| 554 | }) |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | // TestStatusTimestamp is a regression test for https://github.com/go-task/task/issues/1230. |