16
16
package buildcache
17
17
18
18
import (
19
- "os"
20
19
"testing"
21
20
"time"
22
21
@@ -25,36 +24,29 @@ import (
25
24
)
26
25
27
26
func Test_UpdateLastUsedFileNotExisting (t * testing.T ) {
28
-
29
27
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 ())
32
29
timeBeforeUpdating := time .Unix (0 , 0 )
33
30
requireCorrectUpdate (t , testBuildDir , timeBeforeUpdating )
34
31
}
35
32
36
33
func Test_UpdateLastUsedFileExisting (t * testing.T ) {
37
-
38
34
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 ())
41
36
42
37
// 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 {}))
46
40
timeBeforeUpdating := time .Now ().Add (- time .Second )
47
- os .Chtimes (preExistingFile , time .Now (), timeBeforeUpdating )
41
+ preExistingFile .Chtimes (time .Now (), timeBeforeUpdating )
48
42
requireCorrectUpdate (t , testBuildDir , timeBeforeUpdating )
49
43
}
50
44
51
45
func 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 ))
54
47
expectedFile := dir .Join (lastUsedFileName )
55
- fileInfo , err := os .Stat (expectedFile . String () )
48
+ fileInfo , err := expectedFile .Stat ()
56
49
require .Nil (t , err )
57
-
58
50
require .GreaterOrEqual (t , fileInfo .ModTime (), prevModTime )
59
51
}
60
52
@@ -70,22 +62,18 @@ func TestPurge(t *testing.T) {
70
62
71
63
// create the metadata files
72
64
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 {}))
78
68
// make sure access time does not matter
79
69
accesstime := time .Now ()
80
- err = os .Chtimes (infoFilePath , accesstime , lastUsedTime )
81
- require .Nil (t , err )
70
+ require .NoError (t , infoFilePath .Chtimes (accesstime , lastUsedTime ))
82
71
}
83
72
84
73
Purge (dirToPurge , ttl )
85
74
86
- fileinfo , err := os . Stat ( dirToPurge .Join ("fresh" ).String () )
75
+ files , err := dirToPurge .Join ("fresh" ).Stat ( )
87
76
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 ())
91
79
}
0 commit comments