fix(tests): resolve flaky ID generation and symlink resolution on macOS

This commit is contained in:
courtmanr@gmail.com 2025-11-27 10:50:13 +00:00
parent 185476750d
commit 0a12200e58
2 changed files with 11 additions and 4 deletions

View file

@ -369,8 +369,14 @@ func TestSymlinkResolution(t *testing.T) {
t.Fatalf("EvalSymlinks failed: %v", err)
}
if resolved != realFile {
t.Errorf("EvalSymlinks(%q) = %q, want %q", linkFile, resolved, realFile)
// Normalize realFile in case tmpDir itself contains symlinks (e.g. /var -> /private/var on macOS)
realFileResolved, err := filepath.EvalSymlinks(realFile)
if err != nil {
t.Fatalf("EvalSymlinks on realFile failed: %v", err)
}
if resolved != realFileResolved {
t.Errorf("EvalSymlinks(%q) = %q, want %q", linkFile, resolved, realFileResolved)
}
// Verify temp file in same dir as resolved path allows rename

View file

@ -6,12 +6,13 @@ import (
"net/http"
"os"
"strings"
"time"
"github.com/google/uuid"
)
// GenerateID generates a unique ID with the given prefix
func GenerateID(prefix string) string {
return fmt.Sprintf("%s-%d", prefix, time.Now().UnixNano())
return fmt.Sprintf("%s-%s", prefix, uuid.NewString())
}
// WriteJSONResponse writes a JSON response to the http.ResponseWriter