@@ -12,6 +12,7 @@ import (
1212
1313 "cdr.dev/slog"
1414 "github.com/coder/coder/v2/provisionersdk"
15+ "github.com/coder/coder/v2/provisionersdk/tfpath"
1516 "github.com/coder/coder/v2/testutil"
1617)
1718
@@ -40,11 +41,11 @@ func TestStaleSessions(t *testing.T) {
4041 fs , logger := prepare ()
4142
4243 // given
43- first := provisionersdk . SessionDir ( uuid .NewString ())
44+ first := tfpath . Session ( workDirectory , uuid .NewString ())
4445 addSessionFolder (t , fs , first , now .Add (- 7 * 24 * time .Hour ))
45- second := provisionersdk . SessionDir ( uuid .NewString ())
46+ second := tfpath . Session ( workDirectory , uuid .NewString ())
4647 addSessionFolder (t , fs , second , now .Add (- 8 * 24 * time .Hour ))
47- third := provisionersdk . SessionDir ( uuid .NewString ())
48+ third := tfpath . Session ( workDirectory , uuid .NewString ())
4849 addSessionFolder (t , fs , third , now .Add (- 9 * 24 * time .Hour ))
4950
5051 // when
@@ -65,9 +66,9 @@ func TestStaleSessions(t *testing.T) {
6566 fs , logger := prepare ()
6667
6768 // given
68- first := provisionersdk . SessionDir ( uuid .NewString ())
69+ first := tfpath . Session ( workDirectory , uuid .NewString ())
6970 addSessionFolder (t , fs , first , now .Add (- 7 * 24 * time .Hour ))
70- second := provisionersdk . SessionDir ( uuid .NewString ())
71+ second := tfpath . Session ( workDirectory , uuid .NewString ())
7172 addSessionFolder (t , fs , second , now .Add (- 6 * 24 * time .Hour ))
7273
7374 // when
@@ -77,7 +78,7 @@ func TestStaleSessions(t *testing.T) {
7778 entries , err := afero .ReadDir (fs , workDirectory )
7879 require .NoError (t , err )
7980 require .Len (t , entries , 1 , "one session should be present" )
80- require .Equal (t , second , entries [0 ].Name (), 1 )
81+ require .Equal (t , second . WorkDirectory (), filepath . Join ( workDirectory , entries [0 ].Name () ), 1 )
8182 })
8283
8384 t .Run ("no stale sessions" , func (t * testing.T ) {
@@ -89,9 +90,9 @@ func TestStaleSessions(t *testing.T) {
8990 fs , logger := prepare ()
9091
9192 // given
92- first := provisionersdk . SessionDir ( uuid .NewString ())
93+ first := tfpath . Session ( workDirectory , uuid .NewString ())
9394 addSessionFolder (t , fs , first , now .Add (- 6 * 24 * time .Hour ))
94- second := provisionersdk . SessionDir ( uuid .NewString ())
95+ second := tfpath . Session ( workDirectory , uuid .NewString ())
9596 addSessionFolder (t , fs , second , now .Add (- 5 * 24 * time .Hour ))
9697
9798 // when
@@ -104,9 +105,10 @@ func TestStaleSessions(t *testing.T) {
104105 })
105106}
106107
107- func addSessionFolder (t * testing.T , fs afero.Fs , sessionName string , modTime time.Time ) {
108- err := fs .MkdirAll (filepath .Join (workDirectory , sessionName ), 0o755 )
108+ func addSessionFolder (t * testing.T , fs afero.Fs , files tfpath.Layout , modTime time.Time ) {
109+ workdir := files .WorkDirectory ()
110+ err := fs .MkdirAll (workdir , 0o755 )
109111 require .NoError (t , err , "can't create session folder" )
110- require .NoError (t , fs .Chtimes (filepath . Join ( workDirectory , sessionName ) , now , modTime ), "can't chtime of session dir" )
112+ require .NoError (t , fs .Chtimes (workdir , now , modTime ), "can't chtime of session dir" )
111113 require .NoError (t , err , "can't set times" )
112114}
0 commit comments