@@ -19,16 +19,18 @@ import (
19
19
20
20
const workDirectory = "/tmp/coder/provisioner-34/work"
21
21
22
+ var now = time .Date (2023 , time .June , 3 , 4 , 5 , 6 , 0 , time .UTC )
23
+
22
24
func TestStaleSessions (t * testing.T ) {
23
25
t .Parallel ()
24
26
25
- prepare := func () (afero.Fs , time. Time , slog.Logger ) {
26
- fs := afero . NewMemMapFs ()
27
- now := time . Date ( 2023 , time . June , 3 , 4 , 5 , 6 , 0 , time . UTC )
27
+ prepare := func () (afero.Fs , slog.Logger ) {
28
+ tempDir := t . TempDir ()
29
+ fs := afero . NewBasePathFs ( afero . NewOsFs (), tempDir )
28
30
logger := slogtest .Make (t , nil ).
29
31
Leveled (slog .LevelDebug ).
30
32
Named ("cleanup-test" )
31
- return fs , now , logger
33
+ return fs , logger
32
34
}
33
35
34
36
t .Run ("all sessions are stale" , func (t * testing.T ) {
@@ -37,7 +39,7 @@ func TestStaleSessions(t *testing.T) {
37
39
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
38
40
defer cancel ()
39
41
40
- fs , now , logger := prepare ()
42
+ fs , logger := prepare ()
41
43
42
44
// given
43
45
first := provisionersdk .SessionDir (uuid .NewString ())
@@ -62,7 +64,7 @@ func TestStaleSessions(t *testing.T) {
62
64
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
63
65
defer cancel ()
64
66
65
- fs , now , logger := prepare ()
67
+ fs , logger := prepare ()
66
68
67
69
// given
68
70
first := provisionersdk .SessionDir (uuid .NewString ())
@@ -86,7 +88,7 @@ func TestStaleSessions(t *testing.T) {
86
88
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
87
89
defer cancel ()
88
90
89
- fs , now , logger := prepare ()
91
+ fs , logger := prepare ()
90
92
91
93
// given
92
94
first := provisionersdk .SessionDir (uuid .NewString ())
@@ -104,9 +106,9 @@ func TestStaleSessions(t *testing.T) {
104
106
})
105
107
}
106
108
107
- func addSessionFolder (t * testing.T , fs afero.Fs , sessionName string , accessTime time.Time ) {
109
+ func addSessionFolder (t * testing.T , fs afero.Fs , sessionName string , modTime time.Time ) {
108
110
err := fs .MkdirAll (filepath .Join (workDirectory , sessionName ), 0o755 )
109
111
require .NoError (t , err , "can't create session folder" )
110
- fs .Chtimes (filepath .Join (workDirectory , sessionName ), accessTime , accessTime )
112
+ require . NoError ( t , fs .Chtimes (filepath .Join (workDirectory , sessionName ), now , modTime ), "can't chtime of session dir" )
111
113
require .NoError (t , err , "can't set times" )
112
114
}
0 commit comments