Fix failing windows tests (#5574)

See commit messages for details.
This commit is contained in:
Stefan Haller 2026-05-02 18:04:34 +02:00 committed by GitHub
commit f2ff1eb24b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 7 deletions

View file

@ -91,7 +91,11 @@ func TestOSCommandFileType(t *testing.T) {
{
"testFile",
func() {
if _, err := os.Create("testFile"); err != nil {
f, err := os.Create("testFile")
if err != nil {
panic(err)
}
if err := f.Close(); err != nil {
panic(err)
}
},
@ -102,7 +106,11 @@ func TestOSCommandFileType(t *testing.T) {
{
"file with spaces",
func() {
if _, err := os.Create("file with spaces"); err != nil {
f, err := os.Create("file with spaces")
if err != nil {
panic(err)
}
if err := f.Close(); err != nil {
panic(err)
}
},
@ -133,7 +141,7 @@ func TestOSCommandFileType(t *testing.T) {
for _, s := range scenarios {
s.setup()
s.test(FileType(s.path))
_ = os.RemoveAll(s.path)
assert.NoError(t, os.RemoveAll(s.path))
}
}

View file

@ -1,7 +1,6 @@
package presentation
import (
"os"
"strings"
"testing"
"time"
@ -531,8 +530,6 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelNone)
defer color.ForceSetColorLevel(oldColorLevel)
os.Setenv("TZ", "UTC")
focusing := false
for _, scenario := range scenarios {
if scenario.focus {

View file

@ -57,7 +57,7 @@ func formatSecondsAgo(secondsAgo int64) string {
// formats the date in a smart way, if the date is today, it will show the time, otherwise it will show the date
func UnixToDateSmart(now time.Time, timestamp int64, longTimeFormat string, shortTimeFormat string) string {
date := time.Unix(timestamp, 0)
date := time.Unix(timestamp, 0).In(now.Location())
if date.Day() == now.Day() && date.Month() == now.Month() && date.Year() == now.Year() {
return date.Format(shortTimeFormat)

View file

@ -2,6 +2,9 @@ package utils
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestFormatSecondsAgo(t *testing.T) {
@ -95,3 +98,18 @@ func TestFormatSecondsAgo(t *testing.T) {
})
}
}
func TestUnixToDateSmart_UsesNowLocationForFormatting(t *testing.T) {
timestamp := int64(1577844184) // 2020-01-01 02:03:04 UTC
now := time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC)
assert.Equal(t, "2:03AM", UnixToDateSmart(now, timestamp, "2006-01-02", "3:04PM"))
}
func TestUnixToDateSmart_SameTimestampDifferentNowLocation(t *testing.T) {
timestamp := int64(1577844184) // 2020-01-01 02:03:04 UTC
loc := time.FixedZone("UTC+1", 3600)
now := time.Date(2020, 1, 1, 6, 3, 4, 0, loc)
assert.Equal(t, "3:03AM", UnixToDateSmart(now, timestamp, "2006-01-02", "3:04PM"))
}