Files
grafana/pkg/services/store/entity/sqlstash/sqltemplate/sqltemplate_test.go
T
Diego Augusto Molina cbcd945251 Unified Storage: in SQL template, also handle output data, improve API, examples and docs (#87560)
* preview of work so far

* stylistic improvements

* fix linters

* remove golden tests, they may cause the system to be too rigid to changes

* remove unnecessary code for golden tests

* remove white space mangling in Execute

* also handle output data, improve API, examples and docs

* add helper methods

* fix interface
2024-05-14 12:32:21 -03:00

29 lines
469 B
Go

package sqltemplate
import (
"testing"
"text/template"
)
func TestExecute(t *testing.T) {
t.Parallel()
tmpl := template.Must(template.New("test").Parse(`{{ .ID }}`))
data := struct {
ID int
}{
ID: 1,
}
txt, err := Execute(tmpl, data)
if txt != "1" || err != nil {
t.Fatalf("unexpected error, txt: %q, err: %v", txt, err)
}
txt, err = Execute(tmpl, 1)
if txt != "" || err == nil {
t.Fatalf("unexpected result, txt: %q, err: %v", txt, err)
}
}