fix!: Default Alert.Enabled to true (#380)
BREAKING CHANGE: It used to default to false, which meant that users had to explicitly set endpoints[].alerts[].enabled to true
This commit is contained in:
@ -17,6 +17,8 @@ type Alert struct {
|
||||
|
||||
// Enabled defines whether the alert is enabled
|
||||
//
|
||||
// Use Alert.IsEnabled() to retrieve the value of this field.
|
||||
//
|
||||
// This is a pointer, because it is populated by YAML and we need to know whether it was explicitly set to a value
|
||||
// or not for provider.ParseWithDefaultAlert to work.
|
||||
Enabled *bool `yaml:"enabled,omitempty"`
|
||||
@ -77,10 +79,10 @@ func (alert Alert) GetDescription() string {
|
||||
}
|
||||
|
||||
// IsEnabled returns whether an alert is enabled or not
|
||||
// Returns true if not set
|
||||
func (alert Alert) IsEnabled() bool {
|
||||
if alert.Enabled == nil {
|
||||
// TODO: Default to true in v5.0.0 (unless default-alert.enabled is set to false)
|
||||
return false
|
||||
return true
|
||||
}
|
||||
return *alert.Enabled
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ func TestAlert_ValidateAndSetDefaults(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAlert_IsEnabled(t *testing.T) {
|
||||
if (Alert{Enabled: nil}).IsEnabled() {
|
||||
t.Error("alert.IsEnabled() should've returned false, because Enabled was set to nil")
|
||||
if !(Alert{Enabled: nil}).IsEnabled() {
|
||||
t.Error("alert.IsEnabled() should've returned true, because Enabled was set to nil")
|
||||
}
|
||||
if value := false; (Alert{Enabled: &value}).IsEnabled() {
|
||||
t.Error("alert.IsEnabled() should've returned false, because Enabled was set to false")
|
||||
|
Reference in New Issue
Block a user