statping/notifiers/notifiers_test.go

57 lines
1.1 KiB
Go
Raw Permalink Normal View History

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"
"github.com/stretchr/testify/assert"
)
func TestReplaceTemplate(t *testing.T) {
t.Parallel()
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-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)
}
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))
}
}