@@ -6,10 +6,12 @@ import (
66 "os"
77 "runtime"
88 "testing"
9+ "time"
910
1011 "github.com/go-git/go-billy/v5"
1112 "github.com/go-git/go-billy/v5/util"
1213 "github.com/stretchr/testify/assert"
14+ "github.com/stretchr/testify/require"
1315)
1416
1517func TestRootExists (t * testing.T ) {
@@ -28,6 +30,39 @@ func TestCapabilities(t *testing.T) {
2830 assert .Equal (t , billy .DefaultCapabilities &^billy .LockCapability , caps )
2931}
3032
33+ func TestModTime (t * testing.T ) {
34+ fs := New ()
35+ _ , err := fs .Create ("/file1" )
36+ require .NoError (t , err )
37+
38+ if runtime .GOOS == "windows" {
39+ time .Sleep (20 * time .Millisecond )
40+ }
41+
42+ _ , err = fs .Create ("/file2" )
43+ require .NoError (t , err )
44+
45+ fi1a , err := fs .Stat ("/file1" )
46+ require .NoError (t , err )
47+
48+ fi2 , err := fs .Stat ("/file2" )
49+ require .NoError (t , err )
50+
51+ fi1b , err := fs .Stat ("/file1" )
52+ require .NoError (t , err )
53+
54+ modtime := fi1a .ModTime ()
55+
56+ // file 1 and file 2 should have different mod times.
57+ assert .NotEqual (t , modtime , fi2 .ModTime ())
58+
59+ // a new file info for the same unmodified file, should still match mod time.
60+ assert .Equal (t , modtime , fi1b .ModTime ())
61+
62+ // new calls to ModTime() retain existing mod time.
63+ assert .Equal (t , modtime , fi1a .ModTime ())
64+ }
65+
3166func TestNegativeOffsets (t * testing.T ) {
3267 fs := New ()
3368 f , err := fs .Create ("negative" )
0 commit comments