Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: moving the preserve mtiem test logic to Go for portability #907

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions e2e/smoke/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
load("@aspect_bazel_lib//lib:yq.bzl", "yq")
load("@io_bazel_rules_go//go:def.bzl", "go_test")

# Validate that JQ works and resolves its toolchain
jq(
Expand Down Expand Up @@ -105,33 +106,25 @@ copy_to_directory(
srcs = ["d"],
out = "copy_to_directory_mtime_out",
preserve_mtime = True,
tags = ["no-remote"],
)

copy_directory(
name = "copy_directory_mtime_case",
src = "d",
out = "copy_directory_mtime_out",
preserve_mtime = True,
tags = ["no-remote"],
)

sh_test(
go_test(
name = "test_preserve_mtime",
size = "small",
srcs = ["test_preserve_mtime.sh"],
srcs = ["test_preserve_mtime.go"],
data = [
"d",
":copy_directory_mtime_case",
":copy_to_directory_mtime_case",
],
# FIXME(#898)
# On macos, fails with
# stat: illegal option -- -
# usage: stat [-FLnq] [-f format | -l | -r | -s | -x] [-t timefmt] [file ...]
# On windows, fails with
# stat: cannot stat 'd/1': No such file or directory
# On Linux, it's helplessly flaky, often failing in 2/2 attempts like
# Preserve mtime test failed. Modify times do not match for d/1 and copy_to_directory_mtime_out/d/1
# Original modify time: 2024-08-14 18:23:01.413642851 +0000
# Copied modify time: 2024-08-14 18:23:31.501819589 +0000
tags = ["manual"],
tags = ["no-remote", "external"],
)
1 change: 1 addition & 0 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ local_path_override(
)

bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True)
bazel_dep(name = "rules_go", version = "0.46.0", repo_name = "io_bazel_rules_go")
52 changes: 52 additions & 0 deletions e2e/smoke/test_preserve_mtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package smoketest

import (
"os"
"path/filepath"
"time"
"testing"
)

func mtime(path string) (time.Time, error) {
info, err := os.Stat(path)
if err != nil {
return time.Time{}, err
}

return info.ModTime(), nil
}

func TestPreserveMTime(t *testing.T) {
cases := map[string]struct{
originalPath string
copiedPath string
}{
"copy_directory": {
originalPath: filepath.Join("d", "1"),
copiedPath: filepath.Join("copy_directory_mtime_out", "1"),
},
"copy_to_directory": {
originalPath: filepath.Join("d", "1"),
copiedPath: filepath.Join("copy_to_directory_mtime_out", "d", "1"),
},
}

for name, test := range cases {
t.Run(name, func(t *testing.T) {
originalMTime, err := mtime(test.originalPath)
if err != nil {
t.Fatal(err.Error())
}
copiedMTime, err := mtime(test.copiedPath)
if err != nil {
t.Fatal(err.Error())
}

if originalMTime != copiedMTime {
t.Fatalf(`Modify times do not match for %s and %s:
Original modify time: %s
Copied modify time: %s`, test.originalPath, test.copiedPath, originalMTime, copiedMTime)
}
})
}
}
30 changes: 0 additions & 30 deletions e2e/smoke/test_preserve_mtime.sh

This file was deleted.