Skip to content

Commit

Permalink
[Dembo] Add standard slack notification message
Browse files Browse the repository at this point in the history
  • Loading branch information
walbertus committed Sep 17, 2019
1 parent 885e52c commit b970e6e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions plugins/slack-notification-plugin/slack/message.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
package slack

import "encoding/json"

type Message interface {
JSON() (string, error)
}

type standardMessage struct {
Text string `json:"text"`
}

func (message *standardMessage) JSON() (string, error) {
byteMessage, err := json.Marshal(message)
if err != nil {
return "", err
}
return string(byteMessage), nil
}

func NewStandardMessage(text string) Message {
return &standardMessage{
Text: text,
}
}
13 changes: 13 additions & 0 deletions plugins/slack-notification-plugin/slack/message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package slack

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestStandardMessage_JSON(t *testing.T) {
message := NewStandardMessage("content")
result, err := message.JSON()
assert.NoError(t, err)
assert.Equal(t, "{\"text\":\"content\"}", result)
}

0 comments on commit b970e6e

Please sign in to comment.