-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Motivation Similar to `Agent` or `Direct`, `AlertMethod` has different types based on its `spec` contents. Each type corresponds to the method's integration provider. It would be beneficial to be able to quickly tell what type of integration does given method support, just like `Agent.Spec.GetType`. ## Release Notes Added `AlertMethod.Spec.GetType()` function and `v1alpha.AlertMethodType` enum to help discern different types of alert methods.
- Loading branch information
1 parent
47439ff
commit 4bf666a
Showing
6 changed files
with
210 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package v1alpha | ||
|
||
//go:generate ../../bin/go-enum --values --noprefix | ||
|
||
// DataSourceType represents the specific type of alert method. | ||
// | ||
/* ENUM( | ||
Webhook = 1 | ||
PagerDuty | ||
Slack | ||
Discord | ||
Opsgenie | ||
ServiceNow | ||
Jira | ||
Teams | ||
)*/ | ||
type AlertMethodType int |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package alertmethod | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/nobl9/nobl9-go/manifest/v1alpha" | ||
) | ||
|
||
func TestAlertMethod_Spec_GetType(t *testing.T) { | ||
for _, method := range v1alpha.AlertMethodTypeValues() { | ||
t.Run(method.String(), func(t *testing.T) { | ||
spec := Spec{} | ||
methodTypeStr := method.String() | ||
setZeroValue(t, &spec, methodTypeStr) | ||
typ, err := spec.GetType() | ||
require.NoError(t, err) | ||
assert.Equal(t, typ.String(), method.String()) | ||
}) | ||
} | ||
} | ||
|
||
// setZeroValue sets a zero value of a pointer field in a struct using reflection. | ||
func setZeroValue(t *testing.T, obj interface{}, fieldName string) { | ||
t.Helper() | ||
objValue := reflect.ValueOf(obj).Elem() | ||
fieldValue := objValue.FieldByName(fieldName) | ||
if !fieldValue.IsValid() || !fieldValue.CanSet() { | ||
t.Fatalf("cannot set value for field: %s", fieldName) | ||
} | ||
fieldValue.Set(reflect.New(fieldValue.Type().Elem())) | ||
} |