1616package buildcache
1717
1818import (
19- "os"
2019 "testing"
2120 "time"
2221
@@ -25,36 +24,29 @@ import (
2524)
2625
2726func Test_UpdateLastUsedFileNotExisting (t * testing.T ) {
28-
2927 testBuildDir := paths .New (t .TempDir (), "sketches" , "sketch-xxx" )
30- err := os .MkdirAll (testBuildDir .String (), 0770 )
31- require .Nil (t , err )
28+ require .NoError (t , testBuildDir .MkdirAll ())
3229 timeBeforeUpdating := time .Unix (0 , 0 )
3330 requireCorrectUpdate (t , testBuildDir , timeBeforeUpdating )
3431}
3532
3633func Test_UpdateLastUsedFileExisting (t * testing.T ) {
37-
3834 testBuildDir := paths .New (t .TempDir (), "sketches" , "sketch-xxx" )
39- err := os .MkdirAll (testBuildDir .String (), 0770 )
40- require .Nil (t , err )
35+ require .NoError (t , testBuildDir .MkdirAll ())
4136
4237 // create the file
43- preExistingFile := testBuildDir .Join (lastUsedFileName ).String ()
44- err = paths .New (preExistingFile ).WriteFile ([]byte {})
45- require .Nil (t , err )
38+ preExistingFile := testBuildDir .Join (lastUsedFileName )
39+ require .NoError (t , preExistingFile .WriteFile ([]byte {}))
4640 timeBeforeUpdating := time .Now ().Add (- time .Second )
47- os .Chtimes (preExistingFile , time .Now (), timeBeforeUpdating )
41+ preExistingFile .Chtimes (time .Now (), timeBeforeUpdating )
4842 requireCorrectUpdate (t , testBuildDir , timeBeforeUpdating )
4943}
5044
5145func requireCorrectUpdate (t * testing.T , dir * paths.Path , prevModTime time.Time ) {
52- err := Used (dir )
53- require .Nil (t , err )
46+ require .NoError (t , Used (dir ))
5447 expectedFile := dir .Join (lastUsedFileName )
55- fileInfo , err := os .Stat (expectedFile . String () )
48+ fileInfo , err := expectedFile .Stat ()
5649 require .Nil (t , err )
57-
5850 require .GreaterOrEqual (t , fileInfo .ModTime (), prevModTime )
5951}
6052
@@ -70,22 +62,18 @@ func TestPurge(t *testing.T) {
7062
7163 // create the metadata files
7264 for dirPath , lastUsedTime := range lastUsedTimesByDirPath {
73- err := os .MkdirAll (dirPath .Canonical ().String (), 0770 )
74- require .Nil (t , err )
75- infoFilePath := dirPath .Join (lastUsedFileName ).Canonical ().String ()
76- err = paths .New (infoFilePath ).WriteFile ([]byte {})
77- require .Nil (t , err )
65+ require .NoError (t , dirPath .MkdirAll ())
66+ infoFilePath := dirPath .Join (lastUsedFileName ).Canonical ()
67+ require .NoError (t , infoFilePath .WriteFile ([]byte {}))
7868 // make sure access time does not matter
7969 accesstime := time .Now ()
80- err = os .Chtimes (infoFilePath , accesstime , lastUsedTime )
81- require .Nil (t , err )
70+ require .NoError (t , infoFilePath .Chtimes (accesstime , lastUsedTime ))
8271 }
8372
8473 Purge (dirToPurge , ttl )
8574
86- fileinfo , err := os . Stat ( dirToPurge .Join ("fresh" ).String () )
75+ files , err := dirToPurge .Join ("fresh" ).Stat ( )
8776 require .Nil (t , err )
88- require .True (t , fileinfo .IsDir ())
89- _ , err = os .Stat (dirToPurge .Join ("old" ).String ())
90- require .ErrorIs (t , err , os .ErrNotExist )
77+ require .True (t , files .IsDir ())
78+ require .True (t , dirToPurge .Exist ())
9179}
0 commit comments