2020-05-02 09:51:47 +00:00
package notifiers
import (
"github.com/magiconair/properties/assert"
"testing"
)
func TestReplaceTemplate ( t * testing . T ) {
temp := ` { "id": {{ .Service .Id }} ,"name":" {{ .Service .Name }} "} `
replaced := ReplaceTemplate ( temp , replacer { Service : exampleService } )
assert . Equal ( t , ` { "id":1,"name":"Statping"} ` , replaced )
temp = ` { "id": {{ .Service .Id }} ,"name":" {{ .Service .Name }} ","downtime":" {{ .Service .DowntimeAgo }} ","failure":" {{ .Failure .Issue }} "} `
replaced = ReplaceTemplate ( temp , replacer { Service : exampleService , Failure : exampleFailure } )
2020-05-02 10:44:07 +00:00
assert . Equal ( t , ` { "id":1,"name":"Statping","failure":"HTTP returned a 500 status code"} want { "id":1,"name":"Statping","downtime":"15 seconds ago","failure":"HTTP returned a 500 status code"} ` , replaced )
2020-05-02 09:51:47 +00:00
}