Skip to content

Commit

Permalink
feat(pkger): extend SummaryNotifcationEndpoints with its env references
Browse files Browse the repository at this point in the history
references: #18407
  • Loading branch information
jsteenb2 committed Jun 10, 2020
1 parent 98cc30f commit 205d022
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8029,6 +8029,8 @@ components:
type: array
items:
$ref: "#/components/schemas/PkgSummaryLabel"
envReferences:
$ref: "#/components/schemas/PkgEnvReferences"
notificationRules:
type: array
items:
Expand Down
4 changes: 3 additions & 1 deletion pkger/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ func (s *SummaryChart) UnmarshalJSON(b []byte) error {
type SummaryNotificationEndpoint struct {
PkgName string `json:"pkgName"`
NotificationEndpoint influxdb.NotificationEndpoint `json:"notificationEndpoint"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`

LabelAssociations []SummaryLabel `json:"labelAssociations"`
EnvReferences []SummaryReference `json:"envReferences"`
}

// UnmarshalJSON unmarshals the notificatio endpoint. This is necessary b/c of
Expand Down
1 change: 1 addition & 0 deletions pkger/parser_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ func (n *notificationEndpoint) summarize() SummaryNotificationEndpoint {
sum := SummaryNotificationEndpoint{
PkgName: n.PkgName(),
LabelAssociations: toSummaryLabels(n.labels...),
EnvReferences: summarizeCommonReferences(n.identity, n.labels),
}

switch n.kind {
Expand Down
25 changes: 23 additions & 2 deletions pkger/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2417,8 +2417,8 @@ spec:
})
})

t.Run("pkg with notification endpoints and labels associated", func(t *testing.T) {
t.Run("happy path", func(t *testing.T) {
t.Run("pkg with notification endpoints", func(t *testing.T) {
t.Run("and labels associated should be successful", func(t *testing.T) {
testfileRunner(t, "testdata/notification_endpoint", func(t *testing.T, pkg *Pkg) {
expectedEndpoints := []SummaryNotificationEndpoint{
{
Expand Down Expand Up @@ -2512,6 +2512,27 @@ spec:
})
})

t.Run("with env refs should be valid", func(t *testing.T) {
testfileRunner(t, "testdata/notification_endpoint_ref.yml", func(t *testing.T, pkg *Pkg) {
actual := pkg.Summary().NotificationEndpoints
require.Len(t, actual, 1)

expectedEnvRefs := []SummaryReference{
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
},
}
assert.Equal(t, expectedEnvRefs, actual[0].EnvReferences)
})
})

t.Run("handles bad config", func(t *testing.T) {
tests := []struct {
kind Kind
Expand Down
13 changes: 13 additions & 0 deletions pkger/testdata/notification_endpoint_ref.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: influxdata.com/v2alpha1
kind: NotificationEndpointSlack
metadata:
name:
envRef:
key: meta-name
spec:
name:
envRef:
key: spec-name
url: https://hooks.slack.com/services/bip/piddy/boppidy
token: tokenval

0 comments on commit 205d022

Please sign in to comment.