-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
testfixtures.go
793 lines (698 loc) · 20.4 KB
/
testfixtures.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
package testfixtures // import "github.com/go-testfixtures/testfixtures/v3"
import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
"io/fs"
"os"
"path"
"path/filepath"
"regexp"
"strings"
"text/template"
"time"
"gopkg.in/yaml.v3"
)
// Loader is the responsible to loading fixtures.
type Loader struct {
db *sql.DB
helper helper
fixturesFiles []*fixtureFile
skipCleanup bool
skipChecksumComputation bool
skipTestDatabaseCheck bool
location *time.Location
template bool
templateFuncs template.FuncMap
templateLeftDelim string
templateRightDelim string
templateOptions []string
templateData interface{}
fs fs.FS
}
type fixtureFile struct {
path string
fileName string
content []byte
insertSQLs []insertSQL
}
type insertSQL struct {
sql string
params []interface{}
}
var (
testDatabaseRegexp = regexp.MustCompile("(?i)test")
errDatabaseIsRequired = fmt.Errorf("testfixtures: database is required")
errDialectIsRequired = fmt.Errorf("testfixtures: dialect is required")
)
// New instantiates a new Loader instance. The "Database" and "Driver"
// options are required.
func New(options ...func(*Loader) error) (*Loader, error) {
l := &Loader{
templateLeftDelim: "{{",
templateRightDelim: "}}",
templateOptions: []string{"missingkey=zero"},
fs: defaultFS{},
}
for _, option := range options {
if err := option(l); err != nil {
return nil, err
}
}
if l.db == nil {
return nil, errDatabaseIsRequired
}
if l.helper == nil {
return nil, errDialectIsRequired
}
if err := l.helper.init(l.db); err != nil {
return nil, err
}
if err := l.buildInsertSQLs(); err != nil {
return nil, err
}
return l, nil
}
// FS sets other fs.FS implementation
//
// Example embed.FS
// By default usage os package implementation
func FS(fs fs.FS) func(*Loader) error {
return func(l *Loader) error {
l.fs = fs
return nil
}
}
// Database sets an existing sql.DB instant to Loader.
func Database(db *sql.DB) func(*Loader) error {
return func(l *Loader) error {
l.db = db
return nil
}
}
// Dialect informs Loader about which database dialect you're using.
//
// Possible options are "postgresql", "timescaledb", "mysql", "mariadb",
// "sqlite", "sqlserver", "clickhouse", "spanner".
func Dialect(dialect string) func(*Loader) error {
return func(l *Loader) error {
h, err := helperForDialect(dialect)
if err != nil {
return err
}
l.helper = h
return nil
}
}
func helperForDialect(dialect string) (helper, error) {
switch dialect {
case "postgres", "postgresql", "timescaledb", "pgx":
return &postgreSQL{}, nil
case "mysql", "mariadb":
return &mySQL{}, nil
case "sqlite", "sqlite3":
return &sqlite{}, nil
case "mssql", "sqlserver":
return &sqlserver{}, nil
case "clickhouse":
return &clickhouse{}, nil
case "spanner":
return &spanner{}, nil
default:
return nil, fmt.Errorf(`testfixtures: unrecognized dialect "%s"`, dialect)
}
}
// UseAlterConstraint If true, the contraint disabling will do
// using ALTER CONTRAINT sintax, only allowed in PG >= 9.4.
// If false, the constraint disabling will use DISABLE TRIGGER ALL,
// which requires SUPERUSER privileges.
//
// Only valid for PostgreSQL. Returns an error otherwise.
func UseAlterConstraint() func(*Loader) error {
return func(l *Loader) error {
pgHelper, ok := l.helper.(*postgreSQL)
if !ok {
return fmt.Errorf("testfixtures: UseAlterConstraint is only valid for PostgreSQL databases")
}
pgHelper.useAlterConstraint = true
return nil
}
}
// UseDropConstraint If true, the constraints will be dropped
// and recreated after loading fixtures. This is implemented mainly to support
// CockroachDB which does not support other methods.
// Only valid for PostgreSQL dialect. Returns an error otherwise.
func UseDropConstraint() func(*Loader) error {
return func(l *Loader) error {
pgHelper, ok := l.helper.(*postgreSQL)
if !ok {
return fmt.Errorf("testfixtures: UseDropConstraint is only valid for PostgreSQL databases")
}
pgHelper.useDropConstraint = true
return nil
}
}
// SkipResetSequences prevents Loader from reseting sequences after loading
// fixtures.
//
// Only valid for PostgreSQL and MySQL. Returns an error otherwise.
func SkipResetSequences() func(*Loader) error {
return func(l *Loader) error {
switch helper := l.helper.(type) {
case *postgreSQL:
helper.skipResetSequences = true
case *mySQL:
helper.skipResetSequences = true
default:
return fmt.Errorf("testfixtures: SkipResetSequences is valid for PostgreSQL and MySQL databases")
}
return nil
}
}
// AllowMultipleStatementsInOneQuery is a performance tweak for running some setup statements in one query for better performance.
//
// Your database and connection must be configured to support it: https://github.com/go-sql-driver/mysql?tab=readme-ov-file#multistatements
//
// Only valid for MySQL as it is not enabled by default.
func AllowMultipleStatementsInOneQuery() func(*Loader) error {
return func(l *Loader) error {
switch helper := l.helper.(type) {
case *mySQL:
helper.allowMultipleStatementsInOneQuery = true
default:
return fmt.Errorf("testfixtures: AllowMultipleStatementsInOneQuery is valid for MySQL database")
}
return nil
}
}
// ResetSequencesTo sets the value the sequences will be reset to.
//
// Defaults to 10000.
//
// Only valid for PostgreSQL and MySQL. Returns an error otherwise.
func ResetSequencesTo(value int64) func(*Loader) error {
return func(l *Loader) error {
switch helper := l.helper.(type) {
case *postgreSQL:
helper.resetSequencesTo = value
case *mySQL:
helper.resetSequencesTo = value
default:
return fmt.Errorf("testfixtures: ResetSequencesTo is only valid for PostgreSQL and MySQL databases")
}
return nil
}
}
// DangerousSkipTestDatabaseCheck will make Loader not check if the database
// name contains "test". Use with caution!
func DangerousSkipTestDatabaseCheck() func(*Loader) error {
return func(l *Loader) error {
l.skipTestDatabaseCheck = true
return nil
}
}
// DangerousSkipCleanupFixtureTables will make Loader not wipe data from fixture tables.
// This may lead to dirty data in the test database.
// Use with caution!
func DangerousSkipCleanupFixtureTables() func(*Loader) error {
return func(l *Loader) error {
l.skipCleanup = true
return nil
}
}
// SkipTableChecksumComputation will make Loader not compute table checksum at the end of the Loader.Load.
// This may improve performance. It may also slow down subsequent calls to Loader.Load, because checksums are used
// to not reload unchanged tables.
func SkipTableChecksumComputation() func(*Loader) error {
return func(l *Loader) error {
l.skipChecksumComputation = true
return nil
}
}
// Directory informs Loader to load YAML files from a given directory.
func Directory(dir string) func(*Loader) error {
return func(l *Loader) error {
fixtures, err := l.fixturesFromDir(dir)
if err != nil {
return err
}
l.fixturesFiles = append(l.fixturesFiles, fixtures...)
return nil
}
}
// Files informs Loader to load a given set of YAML files.
func Files(files ...string) func(*Loader) error {
return func(l *Loader) error {
fixtures, err := l.fixturesFromFiles(files...)
if err != nil {
return err
}
l.fixturesFiles = append(l.fixturesFiles, fixtures...)
return nil
}
}
// Paths inform Loader to load a given set of YAML files and directories.
func Paths(paths ...string) func(*Loader) error {
return func(l *Loader) error {
fixtures, err := l.fixturesFromPaths(paths...)
if err != nil {
return err
}
l.fixturesFiles = append(l.fixturesFiles, fixtures...)
return nil
}
}
// Files informs Loader to load a given set of YAML files as mutiple fixtures.
func FilesMultiTables(files ...string) func(*Loader) error {
return func(l *Loader) error {
fixtures, err := l.fixturesFromFilesMultiTables(files...)
if err != nil {
return err
}
l.fixturesFiles = append(l.fixturesFiles, fixtures...)
return nil
}
}
// Location makes Loader use the given location by default when parsing
// dates. If not given, by default it uses the value of time.Local.
func Location(location *time.Location) func(*Loader) error {
return func(l *Loader) error {
l.location = location
return nil
}
}
// Template makes loader process each YAML file as an template using the
// text/template package.
//
// For more information on how templates work in Go please read:
// https://golang.org/pkg/text/template/
//
// If not given the YAML files are parsed as is.
func Template() func(*Loader) error {
return func(l *Loader) error {
l.template = true
return nil
}
}
// TemplateFuncs allow choosing which functions will be available
// when processing templates.
//
// For more information see: https://golang.org/pkg/text/template/#Template.Funcs
func TemplateFuncs(funcs template.FuncMap) func(*Loader) error {
return func(l *Loader) error {
if !l.template {
return fmt.Errorf(`testfixtures: the Template() options is required in order to use the TemplateFuns() option`)
}
l.templateFuncs = funcs
return nil
}
}
// TemplateDelims allow choosing which delimiters will be used for templating.
// This defaults to "{{" and "}}".
//
// For more information see https://golang.org/pkg/text/template/#Template.Delims
func TemplateDelims(left, right string) func(*Loader) error {
return func(l *Loader) error {
if !l.template {
return fmt.Errorf(`testfixtures: the Template() options is required in order to use the TemplateDelims() option`)
}
l.templateLeftDelim = left
l.templateRightDelim = right
return nil
}
}
// TemplateOptions allows you to specific which text/template options will
// be enabled when processing templates.
//
// This defaults to "missingkey=zero". Check the available options here:
// https://golang.org/pkg/text/template/#Template.Option
func TemplateOptions(options ...string) func(*Loader) error {
return func(l *Loader) error {
if !l.template {
return fmt.Errorf(`testfixtures: the Template() options is required in order to use the TemplateOptions() option`)
}
l.templateOptions = options
return nil
}
}
// TemplateData allows you to specify which data will be available
// when processing templates. Data is accesible by prefixing it with a "."
// like {{.MyKey}}.
func TemplateData(data interface{}) func(*Loader) error {
return func(l *Loader) error {
if !l.template {
return fmt.Errorf(`testfixtures: the Template() options is required in order to use the TemplateData() option`)
}
l.templateData = data
return nil
}
}
// ClickhouseUseDeleteFrom If true, then "DELETE FROM …" syntax will be used
// to clean data from Clickhouse.
// Default syntax is "TRUNCATE TABLE …"
//
// Only valid for Clickhouse. Returns an error otherwise.
func ClickhouseUseDeleteFrom() func(*Loader) error {
return func(l *Loader) error {
chHelper, ok := l.helper.(*clickhouse)
if !ok {
return fmt.Errorf("testfixtures: ClickhouseUseDeleteFrom is only valid for Clickhouse databases")
}
chHelper.cleanTableFn = func(tableName string) string {
return fmt.Sprintf("DELETE FROM %s", tableName)
}
return nil
}
}
// EnsureTestDatabase returns an error if the database name does not contains
// "test".
func (l *Loader) EnsureTestDatabase() error {
dbName, err := l.helper.databaseName(l.db)
if err != nil {
return err
}
if !testDatabaseRegexp.MatchString(dbName) {
return fmt.Errorf(`testfixtures: database "%s" does not appear to be a test database`, dbName)
}
return nil
}
// Load wipes and after load all fixtures in the database.
//
// if err := fixtures.Load(); err != nil {
// ...
// }
func (l *Loader) Load() error {
if !l.skipTestDatabaseCheck {
if err := l.EnsureTestDatabase(); err != nil {
return err
}
}
err := l.helper.disableReferentialIntegrity(l.db, func(tx *sql.Tx) error {
modifiedTables := make(map[string]bool, len(l.fixturesFiles))
for _, file := range l.fixturesFiles {
tableName := file.fileNameWithoutExtension()
modified, err := l.helper.isTableModified(tx, tableName)
if err != nil {
return err
}
modifiedTables[tableName] = modified
}
// Delete existing table data for specified fixtures before populating the data. This helps avoid
// DELETE CASCADE constraints when using the `UseAlterConstraint()` option.
if !l.skipCleanup {
for _, file := range l.fixturesFiles {
modified := modifiedTables[file.fileNameWithoutExtension()]
if !modified {
continue
}
if err := file.delete(tx, l.helper); err != nil {
return err
}
}
}
for _, file := range l.fixturesFiles {
modified := modifiedTables[file.fileNameWithoutExtension()]
if !modified {
continue
}
err := l.helper.whileInsertOnTable(tx, file.fileNameWithoutExtension(), func() error {
for j, i := range file.insertSQLs {
if _, err := tx.Exec(i.sql, i.params...); err != nil {
return &InsertError{
Err: err,
File: file.fileName,
Index: j,
SQL: i.sql,
Params: i.params,
}
}
}
return nil
})
if err != nil {
return err
}
}
return nil
})
if err != nil {
return err
}
if !l.skipChecksumComputation {
if err := l.helper.computeTablesChecksum(l.db); err != nil {
return err
}
}
return nil
}
// InsertError will be returned if any error happens on database while
// inserting the record.
type InsertError struct {
Err error
File string
Index int
SQL string
Params []interface{}
}
func (e *InsertError) Error() string {
return fmt.Sprintf(
"testfixtures: error inserting record: %v, on file: %s, index: %d, sql: %s, params: %v",
e.Err,
e.File,
e.Index,
e.SQL,
e.Params,
)
}
func (l *Loader) buildInterfacesSlice(records interface{}) ([]interface{}, error) {
switch records := records.(type) {
case []interface{}:
return records, nil
case map[string]interface{}:
var result []interface{}
for _, record := range records {
result = append(result, record)
}
return result, nil
}
return nil, fmt.Errorf("testfixtures: fixture is not a slice or map")
}
func (l *Loader) buildInsertSQLs() error {
for _, f := range l.fixturesFiles {
var records interface{}
if err := yaml.Unmarshal(f.content, &records); err != nil {
return fmt.Errorf("testfixtures: could not unmarshal YAML: %w", err)
}
result, err := l.buildInterfacesSlice(records)
if err != nil {
return err
}
f.insertSQLs = make([]insertSQL, 0, len(result))
for _, record := range result {
recordMap, ok := record.(map[string]interface{})
if !ok {
return fmt.Errorf("testfixtures: could not cast record: not a map[interface{}]interface{}")
}
sql, values, err := l.buildInsertSQL(f, recordMap)
if err != nil {
return err
}
f.insertSQLs = append(f.insertSQLs, insertSQL{sql, values})
}
}
return nil
}
func (f *fixtureFile) fileNameWithoutExtension() string {
return strings.Replace(f.fileName, filepath.Ext(f.fileName), "", 1)
}
func (f *fixtureFile) delete(tx *sql.Tx, h helper) error {
deleteQuery := h.cleanTableQuery(h.quoteKeyword(f.fileNameWithoutExtension()))
if _, err := tx.Exec(deleteQuery); err != nil {
return fmt.Errorf(`testfixtures: could not clean table "%s": %w`, f.fileNameWithoutExtension(), err)
}
return nil
}
func (l *Loader) buildInsertSQL(f *fixtureFile, record map[string]interface{}) (sqlStr string, values []interface{}, err error) {
var (
sqlColumns = make([]string, 0, len(record))
sqlValues = make([]string, 0, len(record))
i = 1
)
for key, value := range record {
sqlColumns = append(sqlColumns, l.helper.quoteKeyword(key))
// if string, try convert to SQL or time
// if map or array, convert to json
switch v := value.(type) {
case string:
if strings.HasPrefix(v, "RAW=") {
sqlValues = append(sqlValues, strings.TrimPrefix(v, "RAW="))
continue
}
if b, err := l.tryHexStringToBytes(v); err == nil {
value = b
} else if t, err := l.tryStrToDate(v); err == nil {
value = t
}
case []interface{}, map[string]interface{}:
var bytes []byte
bytes, err = json.Marshal(recursiveToJSON(v))
if err != nil {
return
}
value = string(bytes)
}
switch l.helper.paramType() {
case paramTypeDollar:
sqlValues = append(sqlValues, fmt.Sprintf("$%d", i))
case paramTypeQuestion:
sqlValues = append(sqlValues, "?")
case paramTypeAtSign:
sqlValues = append(sqlValues, fmt.Sprintf("@p%d", i))
}
values = append(values, value)
i++
}
sqlStr, err = l.helper.buildInsertSQL(
l.db,
l.helper.quoteKeyword(f.fileNameWithoutExtension()),
sqlColumns, sqlValues,
)
return
}
func (l *Loader) fixturesFromDir(dir string) ([]*fixtureFile, error) {
fileinfos, err := fs.ReadDir(l.fs, dir)
if err != nil {
return nil, fmt.Errorf(`testfixtures: could not stat directory "%s": %w`, dir, err)
}
files := make([]*fixtureFile, 0, len(fileinfos))
for _, fileinfo := range fileinfos {
fileExt := filepath.Ext(fileinfo.Name())
if !fileinfo.IsDir() && (fileExt == ".yml" || fileExt == ".yaml") {
fixture := &fixtureFile{
path: path.Join(dir, fileinfo.Name()),
fileName: fileinfo.Name(),
}
fixture.content, err = fs.ReadFile(l.fs, fixture.path)
if err != nil {
return nil, fmt.Errorf(`testfixtures: could not read file "%s": %w`, fixture.path, err)
}
if err := l.processFileTemplate(fixture); err != nil {
return nil, err
}
files = append(files, fixture)
}
}
return files, nil
}
func (l *Loader) fixturesFromFiles(fileNames ...string) ([]*fixtureFile, error) {
var (
fixtureFiles = make([]*fixtureFile, 0, len(fileNames))
err error
)
for _, f := range fileNames {
fixture := &fixtureFile{
path: f,
fileName: filepath.Base(f),
}
fixture.content, err = fs.ReadFile(l.fs, fixture.path)
if err != nil {
return nil, fmt.Errorf(`testfixtures: could not read file "%s": %w`, fixture.path, err)
}
if err := l.processFileTemplate(fixture); err != nil {
return nil, err
}
fixtureFiles = append(fixtureFiles, fixture)
}
return fixtureFiles, nil
}
func (l *Loader) fixturesFromPaths(paths ...string) ([]*fixtureFile, error) {
fixtureExtractor := func(p string, isDir bool) ([]*fixtureFile, error) {
if isDir {
return l.fixturesFromDir(p)
}
return l.fixturesFromFiles(p)
}
var fixtureFiles []*fixtureFile
for _, p := range paths {
f, err := os.Stat(p)
if err != nil {
return nil, fmt.Errorf(`testfixtures: could not stat path "%s": %w`, p, err)
}
fixtures, err := fixtureExtractor(p, f.IsDir())
if err != nil {
return nil, err
}
fixtureFiles = append(fixtureFiles, fixtures...)
}
return fixtureFiles, nil
}
func (l *Loader) fixturesFromFilesMultiTables(fileNames ...string) ([]*fixtureFile, error) {
fixtureFiles := make([]*fixtureFile, 0, len(fileNames))
for _, f := range fileNames {
var (
content []byte
err error
)
content, err = fs.ReadFile(l.fs, f)
if err != nil {
return nil, fmt.Errorf(`testfixtures: could not read file "%s": %w`, f, err)
}
content, err = l.processTemplate(content)
if err != nil {
return nil, err
}
var data interface{}
if err := yaml.Unmarshal(content, &data); err != nil {
return nil, fmt.Errorf("testfixtures: could not unmarshal YAML: %w", err)
}
tables, ok := data.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("testfixtures: could not cast tables: not a map[string]interface{}")
}
for table, records := range tables {
result, err := l.buildInterfacesSlice(records)
if err != nil {
return nil, err
}
var content []byte
if content, err = yaml.Marshal(result); err != nil {
return nil, fmt.Errorf("testfixtures: could not marshal YAML: %w", err)
}
file := fmt.Sprintf("%s.yml", table)
path := filepath.Join(filepath.Dir(f), file)
fixtureFiles = append(fixtureFiles, &fixtureFile{
path: path,
fileName: file,
content: content,
})
}
}
return fixtureFiles, nil
}
func (l *Loader) processFileTemplate(f *fixtureFile) error {
if !l.template {
return nil
}
var err error
f.content, err = l.processTemplate(f.content)
if err != nil {
return fmt.Errorf(`textfixtures: error on parsing template in %s: %w`, f.fileName, err)
}
return nil
}
func (l *Loader) processTemplate(content []byte) ([]byte, error) {
t := template.New("").
Funcs(l.templateFuncs).
Delims(l.templateLeftDelim, l.templateRightDelim).
Option(l.templateOptions...)
t, err := t.Parse(string(content))
if err != nil {
return nil, err
}
var buffer bytes.Buffer
if err := t.Execute(&buffer, l.templateData); err != nil {
return nil, err
}
return buffer.Bytes(), nil
}