@@ -14,7 +14,8 @@ func Test_UpdateLastUsedFileNotExisting(t *testing.T) {
14
14
testBuildDir := paths .New (t .TempDir (), "sketches" , "sketch-xxx" )
15
15
err := os .MkdirAll (testBuildDir .String (), 0770 )
16
16
require .Nil (t , err )
17
- requireCorrectUpdate (t , testBuildDir )
17
+ timeBeforeUpdating := time .Unix (0 , 0 )
18
+ requireCorrectUpdate (t , testBuildDir , timeBeforeUpdating )
18
19
}
19
20
20
21
func Test_UpdateLastUsedFileExisting (t * testing.T ) {
@@ -24,21 +25,22 @@ func Test_UpdateLastUsedFileExisting(t *testing.T) {
24
25
require .Nil (t , err )
25
26
26
27
// create the file
27
- err = paths .New (testBuildDir .Join (lastUsedFileName ).String ()).WriteFile ([]byte {})
28
+ preExistingFile := testBuildDir .Join (lastUsedFileName ).String ()
29
+ err = paths .New (preExistingFile ).WriteFile ([]byte {})
28
30
require .Nil (t , err )
29
-
30
- requireCorrectUpdate (t , testBuildDir )
31
+ timeBeforeUpdating := time .Now ().Add (- time .Second )
32
+ os .Chtimes (preExistingFile , time .Now (), timeBeforeUpdating )
33
+ requireCorrectUpdate (t , testBuildDir , timeBeforeUpdating )
31
34
}
32
35
33
- func requireCorrectUpdate (t * testing.T , dir * paths.Path ) {
34
- timeBeforeUpdating := time .Now ()
36
+ func requireCorrectUpdate (t * testing.T , dir * paths.Path , prevModTime time.Time ) {
35
37
err := UpdateLastUsedTime (dir )
36
38
require .Nil (t , err )
37
39
expectedFile := dir .Join (lastUsedFileName )
38
40
fileInfo , err := os .Stat (expectedFile .String ())
39
41
require .Nil (t , err )
40
42
41
- require .GreaterOrEqual (t , fileInfo .ModTime (), timeBeforeUpdating )
43
+ require .GreaterOrEqual (t , fileInfo .ModTime (), prevModTime )
42
44
}
43
45
44
46
func TestPurge (t * testing.T ) {
0 commit comments