statping/notifiers/notifiers_test.go

19 lines
724 B
Go
Raw Normal View History

package notifiers
import (
"github.com/magiconair/properties/assert"
2020-06-15 08:10:13 +00:00
"github.com/statping/statping/types/failures"
"github.com/statping/statping/types/services"
"testing"
)
func TestReplaceTemplate(t *testing.T) {
temp := `{"id":{{.Service.Id}},"name":"{{.Service.Name}}"}`
2020-06-15 08:10:13 +00:00
replaced := ReplaceTemplate(temp, replacer{Service: services.Example(true)})
assert.Equal(t, `{"id":6283,"name":"Statping"}`, 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()})
assert.Equal(t, `{"id":6283,"name":"Statping","failure":"HTTP returned a 500 status code"}`, replaced)
}