mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-08 03:31:59 +02:00
b9a08c4dc9
we're repeating this quite a bit Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package gio
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestChtimes(t *testing.T) {
|
|
modTime := time.Now().AddDate(-1, 0, 0).Round(1 * time.Second).UTC()
|
|
path := filepath.Join(t.TempDir(), "file")
|
|
require.NoError(t, os.WriteFile(path, nil, 0o644))
|
|
|
|
require.NoError(t, Chtimes(path, fmt.Sprintf("%d", modTime.Unix())))
|
|
|
|
stat, err := os.Stat(path)
|
|
require.NoError(t, err)
|
|
require.True(t, modTime.Equal(stat.ModTime()))
|
|
}
|
|
|
|
func TestChtimesFileDoesNotExist(t *testing.T) {
|
|
modTime := time.Now().AddDate(-1, 0, 0).Round(1 * time.Second).UTC()
|
|
path := filepath.Join(t.TempDir(), "file")
|
|
|
|
require.ErrorIs(t, Chtimes(path, fmt.Sprintf("%d", modTime.Unix())), os.ErrNotExist)
|
|
}
|
|
|
|
func TestChtimesInvalidTS(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "file")
|
|
require.NoError(t, os.WriteFile(path, nil, 0o644))
|
|
|
|
require.ErrorIs(t, Chtimes(path, "fake"), strconv.ErrSyntax)
|
|
}
|
|
|
|
func TestChtimesEmpty(t *testing.T) {
|
|
modTime := time.Now().AddDate(-1, 0, 0).Round(1 * time.Second).UTC()
|
|
path := filepath.Join(t.TempDir(), "file")
|
|
require.NoError(t, os.WriteFile(path, nil, 0o644))
|
|
|
|
require.NoError(t, Chtimes(path, ""))
|
|
|
|
stat, err := os.Stat(path)
|
|
require.NoError(t, err)
|
|
require.False(t, modTime.Equal(stat.ModTime()))
|
|
}
|