-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathalertnow_test.go
48 lines (39 loc) · 1.3 KB
/
alertnow_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package itests
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/curio/alertmanager"
"github.com/filecoin-project/curio/alertmanager/curioalerting"
"github.com/filecoin-project/curio/alertmanager/plugin"
"github.com/filecoin-project/curio/deps/config"
"github.com/filecoin-project/curio/harmony/harmonydb"
)
func TestAlertNow(t *testing.T) {
// TestAlertNow tests alerting system
tp := &testPlugin{}
plugin.TestPlugins = []plugin.Plugin{
tp,
}
// Create dependencies
sharedITestID := harmonydb.ITestNewID()
db, err := harmonydb.NewFromConfigWithITestID(t, sharedITestID)
require.NoError(t, err)
an := alertmanager.NewAlertNow(db, "alertNowMachine")
an.AddAlert("testMessage")
as := curioalerting.NewAlertingSystem()
alertmanager.AlertFuncs = []alertmanager.AlertFunc{alertmanager.NowCheck}
// Create a new alert task
at := alertmanager.NewAlertTask(nil, db, config.CurioAlertingConfig{}, as)
done, err := at.Do(123, func() bool { return true })
require.NoError(t, err)
require.True(t, done)
require.Equal(t, "Machine alertNowMachine: testMessage", tp.output)
}
// testPlugin is a test plugin
type testPlugin struct {
output string
}
func (tp *testPlugin) SendAlert(data *plugin.AlertPayload) error {
tp.output = data.Details["NowCheck"].(string)
return nil
}