2020-05-02 09:51:47 +00:00
|
|
|
package notifiers
|
|
|
|
|
|
|
|
import (
|
2020-10-12 22:30:21 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-06-15 08:10:13 +00:00
|
|
|
"github.com/statping/statping/types/failures"
|
|
|
|
"github.com/statping/statping/types/services"
|
2020-07-20 22:02:01 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-05-02 09:51:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReplaceTemplate(t *testing.T) {
|
2020-07-23 22:05:10 +00:00
|
|
|
t.Parallel()
|
2020-05-02 09:51:47 +00:00
|
|
|
temp := `{"id":{{.Service.Id}},"name":"{{.Service.Name}}"}`
|
2020-06-15 08:10:13 +00:00
|
|
|
replaced := ReplaceTemplate(temp, replacer{Service: services.Example(true)})
|
2020-06-15 08:12:03 +00:00
|
|
|
assert.Equal(t, `{"id":6283,"name":"Statping Example"}`, replaced)
|
2020-05-02 09:51:47 +00:00
|
|
|
|
2020-05-04 00:33:26 +00:00
|
|
|
temp = `{"id":{{.Service.Id}},"name":"{{.Service.Name}}","failure":"{{.Failure.Issue}}"}`
|
2020-06-15 08:10:13 +00:00
|
|
|
replaced = ReplaceTemplate(temp, replacer{Service: services.Example(false), Failure: failures.Example()})
|
2020-06-15 08:12:03 +00:00
|
|
|
assert.Equal(t, `{"id":6283,"name":"Statping Example","failure":"Response did not response a 200 status code"}`, replaced)
|
2020-05-02 09:51:47 +00:00
|
|
|
}
|
2020-08-10 03:10:37 +00:00
|
|
|
|
|
|
|
func TestPushover_Select(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
Value string
|
|
|
|
Expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"lowest",
|
|
|
|
"-2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"low",
|
|
|
|
"-1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"normal",
|
|
|
|
"0",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"high",
|
|
|
|
"1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"emergency",
|
|
|
|
"2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
"0",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range tests {
|
|
|
|
assert.Equal(t, v.Expected, priority(v.Value))
|
|
|
|
}
|
|
|
|
}
|