Skip to content

Commit 6746059

Browse files
committed
Review feedback.
Signed-off-by: Peter Štibraný <[email protected]>
1 parent 8e944e0 commit 6746059

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

pkg/alertmanager/multitenant_test.go

+23-15
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ templates:
146146
dirs := am.getPerUserDirectories()
147147
user3Dir := dirs["user3"]
148148
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")))
153153

154154
assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
155155
# HELP cortex_alertmanager_config_last_reload_successful Boolean set to 1 whenever the last configuration reload attempt was successful.
@@ -187,7 +187,7 @@ templates:
187187
require.NotZero(t, dirs["user1"])
188188
require.NotZero(t, dirs["user2"])
189189
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))
191191

192192
assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
193193
# HELP cortex_alertmanager_config_last_reload_successful Boolean set to 1 whenever the last configuration reload attempt was successful.
@@ -214,10 +214,10 @@ templates:
214214
require.Equal(t, user3Dir, dirs["user3"]) // Dir should exist, even though state files are not generated yet.
215215

216216
// 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")))
221221

222222
assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
223223
# 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
254254
createFile(t, filepath.Join(cfg.DataDir, "templates", user2, "template.tpl"))
255255

256256
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")))
262262
}
263263

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 {
265273
fi, err := os.Stat(path)
266274
if err != nil {
267275
if os.IsNotExist(err) {

0 commit comments

Comments
 (0)