@@ -146,10 +146,10 @@ templates:
146
146
dirs := am .getPerUserDirectories ()
147
147
user3Dir := dirs ["user3" ]
148
148
require .NotZero (t , user3Dir )
149
- require .True (t , exists (t , user3Dir , true ))
150
- require .True (t , exists (t , filepath .Join (user3Dir , templatesDir ), true ))
151
- require .True (t , exists (t , filepath .Join (user3Dir , templatesDir , "first.tpl" ), false ))
152
- require .True (t , exists (t , filepath .Join (user3Dir , templatesDir , "second.tpl" ), false ))
149
+ require .True (t , dirExists (t , user3Dir ))
150
+ require .True (t , dirExists (t , filepath .Join (user3Dir , templatesDir )))
151
+ require .True (t , fileExists (t , filepath .Join (user3Dir , templatesDir , "first.tpl" )))
152
+ require .True (t , fileExists (t , filepath .Join (user3Dir , templatesDir , "second.tpl" )))
153
153
154
154
assert .NoError (t , testutil .GatherAndCompare (reg , bytes .NewBufferString (`
155
155
# HELP cortex_alertmanager_config_last_reload_successful Boolean set to 1 whenever the last configuration reload attempt was successful.
@@ -187,7 +187,7 @@ templates:
187
187
require .NotZero (t , dirs ["user1" ])
188
188
require .NotZero (t , dirs ["user2" ])
189
189
require .Zero (t , dirs ["user3" ]) // User3 is deleted, so we should have no more files for it.
190
- require .False (t , exists (t , user3Dir , false ))
190
+ require .False (t , fileExists (t , user3Dir ))
191
191
192
192
assert .NoError (t , testutil .GatherAndCompare (reg , bytes .NewBufferString (`
193
193
# HELP cortex_alertmanager_config_last_reload_successful Boolean set to 1 whenever the last configuration reload attempt was successful.
@@ -214,10 +214,10 @@ templates:
214
214
require .Equal (t , user3Dir , dirs ["user3" ]) // Dir should exist, even though state files are not generated yet.
215
215
216
216
// Hierarchy that existed before should exist again.
217
- require .True (t , exists (t , user3Dir , true ))
218
- require .True (t , exists (t , filepath .Join (user3Dir , templatesDir ), true ))
219
- require .True (t , exists (t , filepath .Join (user3Dir , templatesDir , "first.tpl" ), false ))
220
- require .True (t , exists (t , filepath .Join (user3Dir , templatesDir , "second.tpl" ), false ))
217
+ require .True (t , dirExists (t , user3Dir ))
218
+ require .True (t , dirExists (t , filepath .Join (user3Dir , templatesDir )))
219
+ require .True (t , fileExists (t , filepath .Join (user3Dir , templatesDir , "first.tpl" )))
220
+ require .True (t , fileExists (t , filepath .Join (user3Dir , templatesDir , "second.tpl" )))
221
221
222
222
assert .NoError (t , testutil .GatherAndCompare (reg , bytes .NewBufferString (`
223
223
# HELP cortex_alertmanager_config_last_reload_successful Boolean set to 1 whenever the last configuration reload attempt was successful.
@@ -254,14 +254,22 @@ func TestMultitenantAlertmanager_migrateStateFilesToPerTenantDirectories(t *test
254
254
createFile (t , filepath .Join (cfg .DataDir , "templates" , user2 , "template.tpl" ))
255
255
256
256
require .NoError (t , am .migrateStateFilesToPerTenantDirectories ())
257
- require .True (t , exists (t , filepath .Join (cfg .DataDir , user1 , notificationLogSnapshot ), false ))
258
- require .True (t , exists (t , filepath .Join (cfg .DataDir , user1 , silencesSnapshot ), false ))
259
- require .True (t , exists (t , filepath .Join (cfg .DataDir , user2 , notificationLogSnapshot ), false ))
260
- require .True (t , exists (t , filepath .Join (cfg .DataDir , user2 , templatesDir ), true ))
261
- require .True (t , exists (t , filepath .Join (cfg .DataDir , user2 , templatesDir , "template.tpl" ), false ))
257
+ require .True (t , fileExists (t , filepath .Join (cfg .DataDir , user1 , notificationLogSnapshot )))
258
+ require .True (t , fileExists (t , filepath .Join (cfg .DataDir , user1 , silencesSnapshot )))
259
+ require .True (t , fileExists (t , filepath .Join (cfg .DataDir , user2 , notificationLogSnapshot )))
260
+ require .True (t , dirExists (t , filepath .Join (cfg .DataDir , user2 , templatesDir )))
261
+ require .True (t , fileExists (t , filepath .Join (cfg .DataDir , user2 , templatesDir , "template.tpl" )))
262
262
}
263
263
264
- func exists (t * testing.T , path string , dir bool ) bool {
264
+ func fileExists (t * testing.T , path string ) bool {
265
+ return checkExists (t , path , false )
266
+ }
267
+
268
+ func dirExists (t * testing.T , path string ) bool {
269
+ return checkExists (t , path , true )
270
+ }
271
+
272
+ func checkExists (t * testing.T , path string , dir bool ) bool {
265
273
fi , err := os .Stat (path )
266
274
if err != nil {
267
275
if os .IsNotExist (err ) {
0 commit comments