2020-09-14 12:01:03 +00:00
|
|
|
package journal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDisabledEvents(t *testing.T) {
|
|
|
|
req := require.New(t)
|
|
|
|
|
|
|
|
test := func(dis DisabledEvents) func(*testing.T) {
|
|
|
|
return func(t *testing.T) {
|
|
|
|
registry := NewEventTypeRegistry(dis)
|
|
|
|
|
|
|
|
reg1 := registry.RegisterEventType("system1", "disabled1")
|
2020-09-28 20:13:18 +00:00
|
|
|
reg2 := registry.RegisterEventType("system1", "disabled2")
|
2020-09-14 12:01:03 +00:00
|
|
|
|
|
|
|
req.False(reg1.Enabled())
|
|
|
|
req.False(reg2.Enabled())
|
|
|
|
req.True(reg1.safe)
|
|
|
|
req.True(reg2.safe)
|
|
|
|
|
|
|
|
reg3 := registry.RegisterEventType("system3", "enabled3")
|
|
|
|
req.True(reg3.Enabled())
|
|
|
|
req.True(reg3.safe)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("direct", test(DisabledEvents{
|
|
|
|
EventType{System: "system1", Event: "disabled1"},
|
2020-09-28 20:13:18 +00:00
|
|
|
EventType{System: "system1", Event: "disabled2"},
|
2020-09-14 12:01:03 +00:00
|
|
|
}))
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
dis, err := ParseDisabledEvents("system1:disabled1,system1:disabled2")
|
2020-09-14 12:01:03 +00:00
|
|
|
req.NoError(err)
|
|
|
|
|
|
|
|
t.Run("parsed", test(dis))
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
dis, err = ParseDisabledEvents(" system1:disabled1 , system1:disabled2 ")
|
2020-09-14 12:01:03 +00:00
|
|
|
req.NoError(err)
|
|
|
|
|
|
|
|
t.Run("parsed_spaces", test(dis))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseDisableEvents(t *testing.T) {
|
2020-09-28 20:13:18 +00:00
|
|
|
_, err := ParseDisabledEvents("system1:disabled1:failed,system1:disabled2")
|
2020-09-14 12:01:03 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
}
|