Files
grafana/pkg/services/store/entity/sqlstash/sqltemplate/into_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

37 lines
898 B
Go

package sqltemplate
import (
"reflect"
"testing"
)
func TestScanDest_Into(t *testing.T) {
t.Parallel()
var d ScanDest
colName, err := d.Into(reflect.Value{}, "some field")
if colName != "" || err == nil || len(d.GetScanDest()) != 0 {
t.Fatalf("unexpected outcome, got colname %q, err: %v, scan dest: %#v",
colName, err, d)
}
data := struct {
X int
Y byte
}{}
dataVal := reflect.ValueOf(&data).Elem()
colName, err = d.Into(dataVal.FieldByName("X"), "some int")
if err != nil || colName != "some int" || len(d) != 1 || d[0] != &data.X {
t.Fatalf("unexpected outcome, got colname %q, err: %v, scan dest: %#v",
colName, err, d)
}
colName, err = d.Into(dataVal.FieldByName("Y"), "some byte")
if err != nil || colName != "some byte" || len(d) != 2 || d[1] != &data.Y {
t.Fatalf("unexpected outcome, got colname %q, err: %v, scan dest: %#v",
colName, err, d)
}
}