@@ -23,9 +23,7 @@ func TestWatch(t *testing.T) {
23
23
}))
24
24
25
25
t .Run ("newly added files are discovered" , withWatch (func (t * testing.T , w * Watch ) {
26
- tmp , err := os .MkdirTemp ("" , "watch" )
27
- require .NoError (t , err )
28
- defer os .RemoveAll (tmp )
26
+ tmp := t .TempDir ()
29
27
30
28
path := filepath .Join (tmp , "hello.txt" )
31
29
empty , err := os .Create (path )
@@ -42,9 +40,7 @@ func TestWatch(t *testing.T) {
42
40
}))
43
41
44
42
t .Run ("ignore old files" , withWatch (func (t * testing.T , w * Watch ) {
45
- tmp , err := os .MkdirTemp ("" , "watch" )
46
- require .NoError (t , err )
47
- defer os .RemoveAll (tmp )
43
+ tmp := t .TempDir ()
48
44
49
45
path := filepath .Join (tmp , "hello.txt" )
50
46
empty , err := os .Create (path )
@@ -67,9 +63,7 @@ func TestWatch(t *testing.T) {
67
63
}))
68
64
69
65
t .Run ("can unwatch a watched file" , withWatch (func (t * testing.T , w * Watch ) {
70
- tmp , err := os .MkdirTemp ("" , "watch" )
71
- require .NoError (t , err )
72
- defer os .RemoveAll (tmp )
66
+ tmp := t .TempDir ()
73
67
74
68
path := filepath .Join (tmp , "hello.txt" )
75
69
empty , err := os .Create (path )
@@ -96,7 +90,7 @@ func TestWatch(t *testing.T) {
96
90
w .Unwatch (path )
97
91
98
92
// Add new content to the file.
99
- os .WriteFile (path , []byte ("heeeelo" ), 0644 )
93
+ assert . NoError ( t , os .WriteFile (path , []byte ("heeeelo" ), 0644 ) )
100
94
101
95
// Should not find the file.
102
96
r , u , err = w .scan ()
@@ -106,9 +100,7 @@ func TestWatch(t *testing.T) {
106
100
}))
107
101
108
102
t .Run ("can returns the list of watched files" , withWatch (func (t * testing.T , w * Watch ) {
109
- tmp , err := os .MkdirTemp ("" , "watch" )
110
- require .NoError (t , err )
111
- defer os .RemoveAll (tmp )
103
+ tmp := t .TempDir ()
112
104
113
105
path := filepath .Join (tmp , "hello.txt" )
114
106
empty , err := os .Create (path )
@@ -124,9 +116,7 @@ func TestWatch(t *testing.T) {
124
116
}))
125
117
126
118
t .Run ("update returns updated, unchanged and watched files" , withWatch (func (t * testing.T , w * Watch ) {
127
- tmp , err := os .MkdirTemp ("" , "watch" )
128
- require .NoError (t , err )
129
- defer os .RemoveAll (tmp )
119
+ tmp := t .TempDir ()
130
120
131
121
path1 := filepath .Join (tmp , "hello-1.txt" )
132
122
empty , err := os .Create (path1 )
@@ -151,7 +141,8 @@ func TestWatch(t *testing.T) {
151
141
w .Watch (path3 )
152
142
153
143
// Set initial state
154
- w .Update ()
144
+ _ , err = w .Update ()
145
+ require .NoError (t , err )
155
146
156
147
// Reset watched files.
157
148
w .Reset ()
@@ -165,7 +156,8 @@ func TestWatch(t *testing.T) {
165
156
// Add new content to the file.
166
157
f , err := os .OpenFile (path3 , os .O_APPEND | os .O_WRONLY , 0600 )
167
158
require .NoError (t , err )
168
- f .Write ([]byte ("more-hello" ))
159
+ _ , err = f .Write ([]byte ("more-hello" ))
160
+ require .NoError (t , err )
169
161
require .NoError (t , f .Sync ())
170
162
f .Close ()
171
163
@@ -183,9 +175,7 @@ func TestWatch(t *testing.T) {
183
175
}))
184
176
185
177
t .Run ("should cleanup files that disapear" , withWatch (func (t * testing.T , w * Watch ) {
186
- tmp , err := os .MkdirTemp ("" , "watch" )
187
- require .NoError (t , err )
188
- defer os .RemoveAll (tmp )
178
+ tmp := t .TempDir ()
189
179
190
180
path1 := filepath .Join (tmp , "hello.txt" )
191
181
empty , err := os .Create (path1 )
@@ -200,9 +190,7 @@ func TestWatch(t *testing.T) {
200
190
}))
201
191
202
192
t .Run ("should allow to invalidate the cache " , withWatch (func (t * testing.T , w * Watch ) {
203
- tmp , err := os .MkdirTemp ("" , "watch" )
204
- require .NoError (t , err )
205
- defer os .RemoveAll (tmp )
193
+ tmp := t .TempDir ()
206
194
207
195
path1 := filepath .Join (tmp , "hello.txt" )
208
196
empty , err := os .Create (path1 )
0 commit comments