fix: tests that fail because of environment specific fixtures
This commit is contained in:
parent
5a8348eeba
commit
8b96f6c791
6 changed files with 38 additions and 17 deletions
|
|
@ -2276,6 +2276,7 @@ func TestIncludesMissingTaskfile(t *testing.T) {
|
|||
task.WithSilent(true),
|
||||
),
|
||||
WithSetupError(),
|
||||
WithFixtureTemplating(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -2724,6 +2725,11 @@ func TestDryChecksum(t *testing.T) {
|
|||
)
|
||||
}
|
||||
|
||||
// fixedSourceModTime pins a source file's modification time so that
|
||||
// timestamp-fingerprinting output (which reads that mtime) is deterministic
|
||||
// across machines and test runs, and can be golden-fixture compared.
|
||||
var fixedSourceModTime = time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
func TestStatusVariables(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
@ -2743,6 +2749,9 @@ func TestStatusVariables(t *testing.T) {
|
|||
assert.Contains(t, r.Output, "3e464c4b03f4b65d740e1e130d4d108a")
|
||||
}),
|
||||
)
|
||||
|
||||
sourceFile := filepathext.SmartJoin(dir, "source.txt")
|
||||
require.NoError(t, os.Chtimes(sourceFile, fixedSourceModTime, fixedSourceModTime))
|
||||
NewExecutorTest(t,
|
||||
WithName("build-ts"),
|
||||
WithExecutorOptions(
|
||||
|
|
@ -2752,7 +2761,7 @@ func TestStatusVariables(t *testing.T) {
|
|||
WithTask("build-ts"),
|
||||
WithAssert(func(t *testing.T, r *ExecutorTestResult) {
|
||||
t.Helper()
|
||||
inf, err := os.Stat(filepathext.SmartJoin(dir, "source.txt"))
|
||||
inf, err := os.Stat(sourceFile)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, r.Output, fmt.Sprintf("%d", inf.ModTime().Unix()))
|
||||
assert.Contains(t, r.Output, inf.ModTime().String())
|
||||
|
|
@ -2778,6 +2787,9 @@ func TestCmdsVariables(t *testing.T) {
|
|||
assert.Contains(t, r.Output, "3e464c4b03f4b65d740e1e130d4d108a")
|
||||
}),
|
||||
)
|
||||
|
||||
sourceFile := filepathext.SmartJoin(dir, "source.txt")
|
||||
require.NoError(t, os.Chtimes(sourceFile, fixedSourceModTime, fixedSourceModTime))
|
||||
NewExecutorTest(t,
|
||||
WithName("build-ts"),
|
||||
WithExecutorOptions(
|
||||
|
|
@ -2787,7 +2799,7 @@ func TestCmdsVariables(t *testing.T) {
|
|||
WithTask("build-ts"),
|
||||
WithAssert(func(t *testing.T, r *ExecutorTestResult) {
|
||||
t.Helper()
|
||||
inf, err := os.Stat(filepathext.SmartJoin(dir, "source.txt"))
|
||||
inf, err := os.Stat(sourceFile)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, r.Output, fmt.Sprintf("%d", inf.ModTime().Unix()))
|
||||
assert.Contains(t, r.Output, inf.ModTime().String())
|
||||
|
|
@ -2799,15 +2811,19 @@ func TestFingerprintVarMethod(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
dir string
|
||||
executorOpts []task.ExecutorOption
|
||||
wantErr bool
|
||||
assertOutput func(t *testing.T, output string)
|
||||
name string
|
||||
dir string
|
||||
executorOpts []task.ExecutorOption
|
||||
wantErr bool
|
||||
pinSourceModTime bool
|
||||
assertOutput func(t *testing.T, output string)
|
||||
}{
|
||||
{
|
||||
name: "TIMESTAMP is injected when the method is inherited from the Taskfile",
|
||||
dir: "testdata/method_taskfile_timestamp",
|
||||
// The output embeds the source file's modification time; pin it
|
||||
// so the value is deterministic across machines and test runs.
|
||||
pinSourceModTime: true,
|
||||
assertOutput: func(t *testing.T, output string) {
|
||||
t.Helper()
|
||||
// An unresolved variable renders as an empty string, so this
|
||||
|
|
@ -2840,6 +2856,10 @@ func TestFingerprintVarMethod(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
_ = os.RemoveAll(filepathext.SmartJoin(tt.dir, ".task"))
|
||||
if tt.pinSourceModTime {
|
||||
sourceFile := filepathext.SmartJoin(tt.dir, "source.txt")
|
||||
require.NoError(t, os.Chtimes(sourceFile, fixedSourceModTime, fixedSourceModTime))
|
||||
}
|
||||
|
||||
opts := []ExecutorTestOption{
|
||||
WithName(tt.name),
|
||||
|
|
@ -3136,6 +3156,7 @@ func TestGenerates(t *testing.T) {
|
|||
WithName(destTask+" (first run)"),
|
||||
WithExecutorOptions(task.WithDir(dir)),
|
||||
WithTask(destTask),
|
||||
WithFixtureTemplating(),
|
||||
WithAssert(func(t *testing.T, r *ExecutorTestResult) {
|
||||
t.Helper()
|
||||
_, err := os.Stat(srcFile)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
task: "build-ts" started
|
||||
task: [build-ts] echo '1753303393'
|
||||
1753303393
|
||||
task: [build-ts] echo '2025-07-23 20:43:13.954226267 +0000 UTC'
|
||||
2025-07-23 20:43:13.954226267 +0000 UTC
|
||||
task: [build-ts] echo '1704067200'
|
||||
1704067200
|
||||
task: [build-ts] echo '2024-01-01 00:00:00 +0000 UTC'
|
||||
2024-01-01 00:00:00 +0000 UTC
|
||||
task: "build-ts" finished
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
task: Task "sub/src.txt" is up to date
|
||||
task: [abs.txt] cat src.txt > '/home/pete/dev/github.com/go-task/task/testdata/generates/abs.txt'
|
||||
task: [abs.txt] cat src.txt > '{{.TEST_DIR}}/testdata/generates/abs.txt'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
err: include must specify taskfile or dir
|
||||
file: /home/pete/dev/github.com/go-task/task/testdata/includes_missing_taskfile/Taskfile.yml:5:5
|
||||
file: {{.TEST_DIR}}/testdata/includes_missing_taskfile/Taskfile.yml:5:5
|
||||
3 | [33mincludes[0m[1m[30m:[0m[1m[30m[0m
|
||||
4 | [1m[30m [0m[33mGOBIN[0m[1m[30m:[0m[1m[30m[0m
|
||||
> 5 | [1m[30m [0m[33msh[0m[1m[30m:[0m[1m[30m [0m[36mecho $(go env GOPATH)/bin[0m[1m[30m[0m
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
task: [build] echo "ts=2026-09-15 14:42:24.182648796 +0000 UTC"
|
||||
ts=2026-09-15 14:42:24.182648796 +0000 UTC
|
||||
task: [build] echo "ts=2024-01-01 00:00:00 +0000 UTC"
|
||||
ts=2024-01-01 00:00:00 +0000 UTC
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
task: "build-ts" started
|
||||
task: status command echo '1683294816' exited zero
|
||||
task: status command echo '2023-05-05 13:53:36 +0000 UTC' exited zero
|
||||
task: status command echo '1704067200' exited zero
|
||||
task: status command echo '2024-01-01 00:00:00 +0000 UTC' exited zero
|
||||
task: "build-ts" finished
|
||||
|
|
|
|||
Loading…
Reference in a new issue