2020-05-02 09:51:47 +00:00
|
|
|
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"
|
2020-05-02 09:51:47 +00:00
|
|
|
"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)})
|
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
|
|
|
}
|