-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
849 lines (691 loc) · 19.1 KB
/
main_test.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
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
package gos
import (
"context"
"database/sql"
"errors"
"fmt"
"os"
"os/user"
"reflect"
"strings"
"testing"
"time"
"unsafe"
_ "github.com/lib/pq"
"github.com/mitranim/sqlb"
)
const testDbName = `gos_test_db`
var testDb *sql.DB
func TestMain(m *testing.M) {
os.Exit(runTestMain(m))
}
// This is a separate function to allow `defer` before `os.Exit`.
func runTestMain(m *testing.M) int {
connParams := []string{
`host=localhost`,
`sslmode=disable`,
`dbname=gos_test_db`,
}
/**
Try using the current OS user as the Postgres user. Works on MacOS when
Postgres is installed via Homebrew. Might fail in other configurations.
*/
usr, err := user.Current()
if err != nil {
panic(err)
}
connParams = append(connParams, `user=`+usr.Username)
/**
Create a test database and drop it at the end. Note that two concurrent
instances of this test would conflict; we could create databases with random
names to allow multiple instances of the test; seems unnecessary.
*/
dropDb(connParams, testDbName)
err = createDb(connParams, testDbName)
if err != nil {
panic(err)
}
defer dropDb(connParams, testDbName)
testConnParams := append(connParams, `dbname=`+testDbName)
db, err := sql.Open("postgres", strings.Join(testConnParams, ` `))
if err != nil {
panic(err)
}
defer db.Close()
testDb = db
return m.Run()
}
func TestQuery_nil_dest(t *testing.T) {
ctx, conn := testInit(t)
testQuery := func(dest interface{}, query string) {
try(t, Query(ctx, conn, dest, query, nil))
}
testQueries := func(dest interface{}) {
testQuery(dest, `select true where false`)
testQuery(dest, `select true`)
testQuery(dest, `select * from (values (true), (false)) as _`)
}
testQueries(nil)
testQueries((*bool)(nil))
}
func TestQuery_scalar_basic(t *testing.T) {
ctx, conn := testInit(t)
var result string
query := `select 'blah'`
try(t, Query(ctx, conn, &result, query, nil))
expected := "blah"
if expected != result {
t.Fatalf(`expected %q, got %q`, expected, result)
}
}
func TestQuery_scalar_non_nullable(t *testing.T) {
ctx, conn := testInit(t)
var result string
query := `select null`
err := Query(ctx, conn, &result, query, nil)
/**
Why this doesn't inspect the error: the error comes from `database/sql`;
there's no programmatic API to detect its type. We return an `ErrNull` in
some other scenarios.
*/
if err == nil {
t.Fatalf(`expected scanning null into non-nullable scalar to produce an error`)
}
}
func TestQuery_scalar_nullable(t *testing.T) {
ctx, conn := testInit(t)
var result *string
query := `select 'blah'`
try(t, Query(ctx, conn, &result, query, nil))
expected := "blah"
if expected != *result {
t.Fatalf(`expected %q, got %q`, expected, *result)
}
query = `select null`
try(t, Query(ctx, conn, &result, query, nil))
if result != nil {
t.Fatalf(`expected selecting null to produce nil, got %q`, *result)
}
}
func TestQuery_scalars_basic(t *testing.T) {
ctx, conn := testInit(t)
var results []string
query := `select * from (values ('one'), ('two'), ('three')) as _`
try(t, Query(ctx, conn, &results, query, nil))
expected := []string{"one", "two", "three"}
eq(t, expected, results)
}
func TestQuery_scalars_non_nullable(t *testing.T) {
ctx, conn := testInit(t)
var results []string
query := `select * from (values ('one'), (null), ('three')) as _`
err := Query(ctx, conn, &results, query, nil)
/**
Why this doesn't inspect the error: the error comes from `database/sql`;
there's no programmatic API to detect its type. We return an `ErrNull` in
some other scenarios.
*/
if err == nil {
t.Fatalf(`expected scanning null into non-nullable scalar to produce an error`)
}
}
func TestQuery_scalars_nullable(t *testing.T) {
ctx, conn := testInit(t)
var results []*string
query := `select * from (values ('one'), (null), ('three')) as _`
try(t, Query(ctx, conn, &results, query, nil))
expected := []*string{strPtr("one"), nil, strPtr("three")}
eq(t, expected, results)
}
// Verify that we treat `time.Time` as an atomic scannable rather than a struct.
func TestQuery_scalar_time(t *testing.T) {
ctx, conn := testInit(t)
var result time.Time
query := `select '0001-01-01'::timestamp`
try(t, Query(ctx, conn, &result, query, nil))
expected := timeMustParse(`0001-01-01T00:00:00Z`)
if expected.UnixNano() != result.UnixNano() {
t.Fatalf(`expected %v, got %v`, expected, result)
}
}
// Verify that we treat `[]time.Time` as atomic scannables rather than structs.
func TestQuery_scalars_time(t *testing.T) {
ctx, conn := testInit(t)
var results []time.Time
query := `select * from (values ('0001-01-01'::timestamp), ('0002-01-01'::timestamp)) as _`
try(t, Query(ctx, conn, &results, query, nil))
expected := []int64{
timeMustParse(`0001-01-01T00:00:00Z`).UnixNano(),
timeMustParse(`0002-01-01T00:00:00Z`).UnixNano(),
}
received := []int64{
results[0].UnixNano(),
results[1].UnixNano(),
}
eq(t, expected, received)
}
func TestQuery_scalar_scannable(t *testing.T) {
ctx, conn := testInit(t)
var result ScannableString
query := `select 'blah'`
try(t, Query(ctx, conn, &result, query, nil))
expected := "blah_scanned"
received := string(result)
if expected != received {
t.Fatalf(`expected %q, got %q`, expected, received)
}
}
func TestQuery_scalars_scannable(t *testing.T) {
ctx, conn := testInit(t)
var results []ScannableString
query := `select * from (values ('one'), ('two'), ('three')) as _`
try(t, Query(ctx, conn, &results, query, nil))
expected := []string{"one_scanned", "two_scanned", "three_scanned"}
received := *(*[]string)(unsafe.Pointer(&results))
eq(t, expected, received)
}
/*
Verifies that when the output is a slice and the result set is empty, we
truncate the slice to empty, while retaining its nil or non-nil status, without
forcing it to become nil or non-nil. This allows users to define their own
empty semantics.
*/
func TestQuery_scalars_empty(t *testing.T) {
ctx, conn := testInit(t)
test := func(exp, res []string) {
query := `select 'blah' where false`
try(t, Query(ctx, conn, &res, query, nil))
eq(t, exp, res)
}
test([]string(nil), []string(nil))
test([]string{}, []string{})
test([]string{}, []string{"blah"})
}
func TestQuery_struct_scannable(t *testing.T) {
ctx, conn := testInit(t)
var result ScannableStruct
query := `select 'blah'`
try(t, Query(ctx, conn, &result, query, nil))
expected := ScannableStruct{Value: "blah_scanned"}
if expected != result {
t.Fatalf(`expected %q, got %q`, expected, result)
}
}
func TestQuery_structs_scannable(t *testing.T) {
ctx, conn := testInit(t)
var results []ScannableStruct
query := `select * from (values ('one'), ('two'), ('three')) as _`
try(t, Query(ctx, conn, &results, query, nil))
expected := []ScannableStruct{{"one_scanned"}, {"two_scanned"}, {"three_scanned"}}
eq(t, expected, results)
}
func TestQuery_struct_with_basic_types(t *testing.T) {
ctx, conn := testInit(t)
var result struct {
Int32 int32 `db:"int32"`
Int64 int64 `db:"int64"`
Float32 float32 `db:"float32"`
Float64 float64 `db:"float64"`
String string `db:"string"`
Bool bool `db:"bool"`
Time time.Time `db:"time"`
Scan ScannableString `db:"scan"`
}
query := `
select
1 :: int4 as int32,
2 :: int8 as int64,
3 :: float4 as float32,
4 :: float8 as float64,
'5' :: text as string,
true :: bool as bool,
current_timestamp :: timestamp as time,
'scan' :: text as scan
`
try(t, Query(ctx, conn, &result, query, nil))
tFieldEq(t, "Int32", result.Int32, int32(1))
tFieldEq(t, "Int64", result.Int64, int64(2))
tFieldEq(t, "Float32", result.Float32, float32(3))
tFieldEq(t, "Float64", result.Float64, float64(4))
tFieldEq(t, "String", result.String, "5")
tFieldEq(t, "Bool", result.Bool, true)
if result.Time.IsZero() {
t.Fatalf(`expected time to be non-zero`)
}
tFieldEq(t, "Scan", result.Scan, ScannableString("scan_scanned"))
}
func TestQuery_struct_field_naming(t *testing.T) {
ctx, conn := testInit(t)
var result struct {
One string `db:"one"`
Two *string `db:"six"`
Three **string `db:"seven"`
Four string `db:"-"`
Five string
}
two := "2"
three := "3"
three_ := &three
result.One = "1"
result.Two = &two
result.Three = &three_
result.Four = "4"
result.Five = "5"
query := `
select
'one' as one,
'two' as six,
'three' as seven
`
try(t, Query(ctx, conn, &result, query, nil))
tFieldEq(t, "One", result.One, "one")
tFieldEq(t, "Two", *result.Two, "two")
tFieldEq(t, "Three", **result.Three, "three")
tFieldEq(t, "Four", result.Four, "4")
tFieldEq(t, "Five", result.Five, "5")
}
func TestQuery_struct_no_rows(t *testing.T) {
ctx, conn := testInit(t)
var result struct{}
query := `select where false`
err := Query(ctx, conn, &result, query, nil)
if !errors.Is(err, ErrNoRows) {
t.Fatalf(`expected error ErrNoRows, got %+v`, err)
}
}
func TestQuery_struct_multiple_rows(t *testing.T) {
ctx, conn := testInit(t)
var result struct {
Val string `db:"val"`
}
query := `select * from (values ('one'), ('two')) as vals (val)`
err := Query(ctx, conn, &result, query, nil)
if !errors.Is(err, ErrMultipleRows) {
t.Fatalf(`expected error ErrMultipleRows, got %+v`, err)
}
}
func TestQuery_invalid_dest(t *testing.T) {
ctx, conn := testInit(t)
test := func(dest interface{}) {
err := Query(ctx, conn, dest, `select true`, nil)
if !errors.Is(err, ErrInvalidDest) {
t.Fatalf(`expected error ErrInvalidDest, got %+v`, err)
}
}
test("str")
test(struct{}{})
test([]struct{}{})
}
func TestQuery_struct_field_nullability(t *testing.T) {
ctx, conn := testInit(t)
type Result struct {
NonNilable string `db:"non_nilable"`
Nilable *string `db:"nilable"`
}
var result Result
query := `
select
'one' as non_nilable,
null as nilable
`
try(t, Query(ctx, conn, &result, query, nil))
expected := Result{NonNilable: "one", Nilable: nil}
if expected != result {
t.Fatalf("expected %#v, got %#v", expected, result)
}
}
func TestQuery_structs(t *testing.T) {
ctx, conn := testInit(t)
type Result struct {
One string `db:"one"`
Two int64 `db:"two"`
}
var results []Result
query := `select * from (values ('one', 10), ('two', 20)) as vals (one, two)`
try(t, Query(ctx, conn, &results, query, nil))
expected := []Result{{"one", 10}, {"two", 20}}
eq(t, expected, results)
}
func TestQuery_struct_missing_col_dest(t *testing.T) {
ctx, conn := testInit(t)
var result struct {
One string `db:"one"`
}
{
query := `select 'one' as one, 'two' as two`
err := Query(ctx, conn, &result, query, nil)
if !errors.Is(err, ErrNoColDest) {
t.Fatalf(`expected error ErrNoColDest, got %+v`, err)
}
}
{
query := `select 'one' as one, null::text as two`
err := Query(ctx, conn, &result, query, nil)
if !errors.Is(err, ErrNoColDest) {
t.Fatalf(`expected error ErrNoColDest, got %+v`, err)
}
}
}
func TestQuery_scalars_empty_result(t *testing.T) {
ctx, conn := testInit(t)
results := []string{"one", "two", "three"}
query := `select where false`
try(t, Query(ctx, conn, &results, query, nil))
expected := []string{}
eq(t, expected, results)
}
func TestQuery_structs_empty_result(t *testing.T) {
ctx, conn := testInit(t)
results := []struct{}{{}, {}, {}}
query := `select where false`
try(t, Query(ctx, conn, &results, query, nil))
expected := []struct{}{}
eq(t, expected, results)
}
func TestQuery_struct_nested_not_null_not_nilable(t *testing.T) {
ctx, conn := testInit(t)
type Nested struct {
Val string `db:"val"`
}
type Nesting struct {
Val string `db:"val"`
Nested Nested `db:"nested"`
}
var result Nesting
query := `
select
'one' as "val",
'two' as "nested.val"
`
try(t, Query(ctx, conn, &result, query, nil))
expected := Nesting{Val: "one", Nested: Nested{Val: "two"}}
eq(t, expected, result)
}
func TestQuery_struct_nested_not_null_nilable_struct(t *testing.T) {
ctx, conn := testInit(t)
type Nested struct {
Val string `db:"val"`
}
type Nesting struct {
Val string `db:"val"`
Nested *Nested `db:"nested"`
}
var result Nesting
query := `
select
'one' as "val",
'two' as "nested.val"
`
try(t, Query(ctx, conn, &result, query, nil))
expected := Nesting{Val: "one", Nested: &Nested{Val: "two"}}
eq(t, expected, result)
}
func TestQuery_struct_nested_not_null_nilable_field(t *testing.T) {
ctx, conn := testInit(t)
type Nested struct {
Val *string `db:"val"`
}
type Nesting struct {
Val string `db:"val"`
Nested Nested `db:"nested"`
}
var result Nesting
query := `
select
'one' as "val",
'two' as "nested.val"
`
try(t, Query(ctx, conn, &result, query, nil))
expected := Nesting{Val: "one", Nested: Nested{Val: strPtr("two")}}
eq(t, expected, result)
}
func TestQuery_struct_nested_not_null_nilable_both(t *testing.T) {
ctx, conn := testInit(t)
type Nested struct {
Val *string `db:"val"`
}
type Nesting struct {
Val string `db:"val"`
Nested *Nested `db:"nested"`
}
var result Nesting
query := `
select
'one' as "val",
'two' as "nested.val"
`
try(t, Query(ctx, conn, &result, query, nil))
expected := Nesting{Val: "one", Nested: &Nested{Val: strPtr("two")}}
eq(t, expected, result)
}
func TestQuery_struct_nested_null_not_nilable(t *testing.T) {
ctx, conn := testInit(t)
type Nested struct {
Val string `db:"val"`
}
type Nesting struct {
Val string `db:"val"`
Nested Nested `db:"nested"`
}
var result Nesting
query := `
select
'one' as "val",
null as "nested.val"
`
err := Query(ctx, conn, &result, query, nil)
if !errors.Is(err, ErrNull) {
t.Fatalf(`expected error ErrNull, got %+v`, err)
}
}
// This also tests for on-demand allocation: if all fields of the inner struct
// are nil, the struct is not allocated.
func TestQuery_struct_nested_null_nilable_struct(t *testing.T) {
ctx, conn := testInit(t)
type Nested struct {
Val string `db:"val"`
}
type Nesting struct {
Val string `db:"val"`
Nested *Nested `db:"nested"`
}
var result Nesting
query := `
select
'one' as "val",
null as "nested.val"
`
try(t, Query(ctx, conn, &result, query, nil))
expected := Nesting{Val: "one", Nested: nil}
eq(t, expected, result)
}
func TestQuery_struct_nested_null_nilable_field(t *testing.T) {
ctx, conn := testInit(t)
type Nested struct {
Val *string `db:"val"`
}
type Nesting struct {
Val string `db:"val"`
Nested Nested `db:"nested"`
}
var result Nesting
query := `
select
'one' as "val",
null as "nested.val"
`
try(t, Query(ctx, conn, &result, query, nil))
expected := Nesting{Val: "one", Nested: Nested{Val: nil}}
eq(t, expected, result)
}
// This also tests for on-demand allocation: if all fields of the inner struct
// are nil, the struct is not allocated.
func TestQuery_struct_nested_null_nilable_both(t *testing.T) {
ctx, conn := testInit(t)
type Nested struct {
Val *string `db:"val"`
}
type Nesting struct {
Val string `db:"val"`
Nested *Nested `db:"nested"`
}
var result Nesting
query := `
select
'one' as "val",
null as "nested.val"
`
try(t, Query(ctx, conn, &result, query, nil))
expected := Nesting{Val: "one", Nested: nil}
eq(t, expected, result)
}
func TestQuery_struct_nested_partially_null(t *testing.T) {
ctx, conn := testInit(t)
type Nested struct {
One *string `db:"one"`
Two *string `db:"two"`
}
type Nesting struct {
Nested *Nested `db:"nested"`
Three string `db:"three"`
}
var result Nesting
query := `
select
'one' as "nested.one",
'three' as "three"
`
try(t, Query(ctx, conn, &result, query, nil))
expected := Nesting{Nested: &Nested{One: strPtr("one")}, Three: "three"}
eq(t, expected, result)
}
/*
Fields without a matching source column must be left untouched. If they have
non-zero values, the existing values must be preserved.
*/
func TestQuery_struct_missing_col_src(t *testing.T) {
ctx, conn := testInit(t)
type Result struct {
One string `db:"one"`
Two string `db:"two"`
Three *string `db:"-"`
Four *Result
}
result := Result{Two: "two", Three: strPtr("three"), Four: &Result{One: "four"}}
query := `select 'one' as one`
try(t, Query(ctx, conn, &result, query, nil))
expected := Result{One: "one", Two: "two", Three: strPtr("three"), Four: &Result{One: "four"}}
eq(t, expected, result)
}
func TestQuery_write_to_existing_pointer(t *testing.T) {
ctx, conn := testInit(t)
type Result struct {
Val *string `db:"val"`
}
var target string
result := Result{&target}
query := `select 'val' as val`
try(t, Query(ctx, conn, &result, query, nil))
eq(t, Result{&target}, result)
eq(t, `val`, target)
query = `select null::text as val`
try(t, Query(ctx, conn, &result, query, nil))
eq(t, Result{nil}, result)
eq(t, `val`, target)
}
func TestCols(t *testing.T) {
type Nested struct {
Val *string `db:"val"`
}
type Nesting struct {
Val string `db:"val"`
Nested *Nested `db:"nested"`
}
actual := sqlb.Cols(Nesting{})
expected := `"val", ("nested")."val" as "nested.val"`
if expected != actual {
t.Fatalf(`expected Cols() to produce %q, got %q`, expected, actual)
}
}
func createDb(connParams []string, dbName string) error {
return withPostgresDb(connParams, func(db *sql.DB) error {
_, err := db.Exec(`create database ` + dbName)
return err
})
}
func dropDb(connParams []string, dbName string) {
err := withPostgresDb(connParams, func(db *sql.DB) error {
_, err := db.Exec(`drop database if exists ` + dbName)
return err
})
if err != nil {
panic(err)
}
}
func withPostgresDb(connParams []string, fun func(db *sql.DB) error) error {
connParams = append(connParams, `dbname=postgres`)
db, err := sql.Open("postgres", strings.Join(connParams, ` `))
if err != nil {
return err
}
err = fun(db)
if err != nil {
return err
}
return db.Close()
}
func testInit(t *testing.T) (context.Context, *sql.Tx) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
conn, err := testDb.BeginTx(ctx, nil)
if err != nil {
t.Fatalf("failed to start DB transaction: %+v", err)
}
return ctx, conn
}
func tFieldEq(t *testing.T, fieldName string, left interface{}, right interface{}) {
if !reflect.DeepEqual(left, right) {
t.Fatalf(`mismatch in field %q: %#v vs. %#v`, fieldName, left, right)
}
}
type ScannableString string
func (self *ScannableString) Scan(input interface{}) error {
*self = ScannableString(input.(string) + "_scanned")
return nil
}
func strPtr(str string) *string { return &str }
func timeMustParse(str string) time.Time {
out, err := time.Parse(time.RFC3339, str)
if err != nil {
panic(err)
}
return out
}
func try(t testing.TB, err error) {
if err != nil {
t.Fatalf("%+v", err)
}
}
func eq(t testing.TB, exp, act interface{}) {
t.Helper()
if !reflect.DeepEqual(exp, act) {
t.Fatalf("expected: %#v\nactual: %#v\n", exp, act)
}
}
type ScannableStruct struct {
Value string
}
func (self *ScannableStruct) Scan(input interface{}) error {
switch input := input.(type) {
case nil:
return nil
case string:
self.Value = input + "_scanned"
return nil
case []byte:
self.Value = string(input) + "_scanned"
return nil
default:
return fmt.Errorf("unrecognized input for type %T: type %T, value %v", self, input, input)
}
}