Merge pull request #318 from bvwells/notifier-fields

Fix slack/teams notification fields
This commit is contained in:
Stefan Prodan
2019-10-03 09:50:25 +03:00
committed by GitHub
4 changed files with 22 additions and 4 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ func (s *Slack) Post(workload string, namespace string, message string, fields [
color = "danger" color = "danger"
} }
sfields := make([]SlackField, len(fields)) sfields := make([]SlackField, 0, len(fields))
for _, f := range fields { for _, f := range fields {
sfields = append(sfields, SlackField{f.Name, f.Value, false}) sfields = append(sfields, SlackField{f.Name, f.Value, false})
} }
+10 -1
View File
@@ -9,6 +9,11 @@ import (
) )
func TestSlack_Post(t *testing.T) { func TestSlack_Post(t *testing.T) {
fields := []Field{
{Name: "name1", Value: "value1"},
{Name: "name2", Value: "value2"},
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body) b, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
@@ -20,6 +25,10 @@ func TestSlack_Post(t *testing.T) {
if payload.Attachments[0].AuthorName != "podinfo.test" { if payload.Attachments[0].AuthorName != "podinfo.test" {
t.Fatal("wrong author name") t.Fatal("wrong author name")
} }
if len(payload.Attachments[0].Fields) != len(fields) {
t.Fatal("wrong facts")
}
})) }))
defer ts.Close() defer ts.Close()
@@ -28,7 +37,7 @@ func TestSlack_Post(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = slack.Post("podinfo", "test", "test", nil, true) err = slack.Post("podinfo", "test", "test", fields, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
+1 -1
View File
@@ -45,7 +45,7 @@ func NewMSTeams(hookURL string) (*MSTeams, error) {
// Post MS Teams message // Post MS Teams message
func (s *MSTeams) Post(workload string, namespace string, message string, fields []Field, warn bool) error { func (s *MSTeams) Post(workload string, namespace string, message string, fields []Field, warn bool) error {
facts := make([]MSTeamsField, len(fields)) facts := make([]MSTeamsField, 0, len(fields))
for _, f := range fields { for _, f := range fields {
facts = append(facts, MSTeamsField{f.Name, f.Value}) facts = append(facts, MSTeamsField{f.Name, f.Value})
} }
+10 -1
View File
@@ -9,6 +9,12 @@ import (
) )
func TestTeams_Post(t *testing.T) { func TestTeams_Post(t *testing.T) {
fields := []Field{
{Name: "name1", Value: "value1"},
{Name: "name2", Value: "value2"},
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body) b, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
@@ -20,6 +26,9 @@ func TestTeams_Post(t *testing.T) {
if payload.Sections[0].ActivitySubtitle != "podinfo.test" { if payload.Sections[0].ActivitySubtitle != "podinfo.test" {
t.Fatal("wrong activity subtitle") t.Fatal("wrong activity subtitle")
} }
if len(payload.Sections[0].Facts) != len(fields) {
t.Fatal("wrong facts")
}
})) }))
defer ts.Close() defer ts.Close()
@@ -28,7 +37,7 @@ func TestTeams_Post(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = teams.Post("podinfo", "test", "test", nil, true) err = teams.Post("podinfo", "test", "test", fields, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }