2017-05-03 05:35:07 +08:00
|
|
|
package mounttest
|
2017-03-24 03:41:21 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2017-05-09 01:05:12 +08:00
|
|
|
// TestFileModTime tests mod times on files
|
2017-03-24 03:41:21 +08:00
|
|
|
func TestFileModTime(t *testing.T) {
|
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
|
|
|
run.createFile(t, "file", "123")
|
|
|
|
|
|
|
|
mtime := time.Date(2012, 11, 18, 17, 32, 31, 0, time.UTC)
|
|
|
|
err := os.Chtimes(run.path("file"), mtime, mtime)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
info, err := os.Stat(run.path("file"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// avoid errors because of timezone differences
|
|
|
|
assert.Equal(t, info.ModTime().Unix(), mtime.Unix())
|
|
|
|
|
|
|
|
run.rm(t, "file")
|
|
|
|
}
|
2017-03-31 02:58:11 +08:00
|
|
|
|
2017-11-08 01:27:53 +08:00
|
|
|
// os.Create without opening for write too
|
|
|
|
func osCreate(name string) (*os.File, error) {
|
|
|
|
return os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
|
|
|
}
|
|
|
|
|
2017-05-09 01:05:12 +08:00
|
|
|
// TestFileModTimeWithOpenWriters tests mod time on open files
|
2017-03-31 02:58:11 +08:00
|
|
|
func TestFileModTimeWithOpenWriters(t *testing.T) {
|
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
|
|
|
mtime := time.Date(2012, 11, 18, 17, 32, 31, 0, time.UTC)
|
|
|
|
filepath := run.path("cp-archive-test")
|
|
|
|
|
2017-11-08 01:27:53 +08:00
|
|
|
f, err := osCreate(filepath)
|
2017-03-31 02:58:11 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = f.Write([]byte{104, 105})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = os.Chtimes(filepath, mtime, mtime)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = f.Close()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
info, err := os.Stat(filepath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// avoid errors because of timezone differences
|
|
|
|
assert.Equal(t, info.ModTime().Unix(), mtime.Unix())
|
|
|
|
|
|
|
|
run.rm(t, "cp-archive-test")
|
|
|
|
}
|