-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: making Slack action URL configurable
- Loading branch information
Showing
6 changed files
with
93 additions
and
4 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,49 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSlackConfig(t *testing.T) { | ||
// test when a value is only specified for webhook | ||
cfgText := ` | ||
[slack] | ||
webhook = "https://example.com" | ||
` | ||
cfgBytes := []byte(cfgText) | ||
config, _ := loadConfigFromBytes(cfgBytes) | ||
|
||
assert.Equal(t, "https://example.com", config.Slack.Webhook) | ||
assert.Equal(t, false, config.Slack.Reporting) | ||
assert.Equal(t, "", config.Slack.Host) | ||
|
||
// test when a value is specified for reporting | ||
cfgText = ` | ||
[slack] | ||
webhook = "https://example.com" | ||
reporting = true | ||
` | ||
cfgBytes = []byte(cfgText) | ||
config, _ = loadConfigFromBytes(cfgBytes) | ||
|
||
assert.Equal(t, "https://example.com", config.Slack.Webhook) | ||
assert.Equal(t, true, config.Slack.Reporting) | ||
assert.Equal(t, "", config.Slack.Host) | ||
|
||
// test when a value is specified for host | ||
cfgText = ` | ||
[slack] | ||
webhook = "https://example.com" | ||
reporting = true | ||
host = "https://example.com/komiser" | ||
` | ||
cfgBytes = []byte(cfgText) | ||
config, _ = loadConfigFromBytes(cfgBytes) | ||
|
||
assert.Equal(t, "https://example.com", config.Slack.Webhook) | ||
assert.Equal(t, true, config.Slack.Reporting) | ||
assert.Equal(t, "https://example.com/komiser", config.Slack.Host) | ||
|
||
} |
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,19 @@ | ||
package internal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSlackAttachment(t *testing.T) { | ||
// default - no slack host specified in config | ||
attachment := createSlackAttachment("testViewName", 3000, 101, 99, 99.99, "", "RESOURCES") | ||
expectedActionUrl := "http://localhost:3000/inventory?view=101" | ||
assert.Equal(t, expectedActionUrl, attachment.Actions[0].URL) | ||
|
||
// explicit - slack host specified in config | ||
attachment = createSlackAttachment("testViewName", 3000, 101, 99, 99.99, "https://example.com", "RESOURCES") | ||
expectedActionUrl = "https://example.com/inventory?view=101" | ||
assert.Equal(t, expectedActionUrl, attachment.Actions[0].URL) | ||
} |
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