MCPcopy Create free account
hub / github.com/DATA-DOG/go-sqlmock / TestCustomValueConverterQueryScan

Function TestCustomValueConverterQueryScan

expectations_test.go:65–103  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func TestCustomValueConverterQueryScan(t *testing.T) {
66 db, mock, _ := New(ValueConverterOption(CustomConverter{}))
67 query := `
68 SELECT
69 name,
70 email,
71 address,
72 anotherfield
73 FROM user
74 where
75 name = 'John'
76 and
77 address = 'Jakarta'
78
79 `
80 expectedStringValue := "ValueOne"
81 expectedIntValue := 2
82 expectedArrayValue := []string{"Three", "Four"}
83 mock.ExpectQuery(query).WillReturnRows(mock.NewRows([]string{"One", "Two", "Three"}).AddRow(expectedStringValue, expectedIntValue, []string{"Three", "Four"}))
84 row := db.QueryRow(query)
85 var stringValue string
86 var intValue int
87 var arrayValue []string
88 if e := row.Scan(&stringValue, &intValue, &arrayValue); e != nil {
89 t.Error(e)
90 }
91 if stringValue != expectedStringValue {
92 t.Errorf("Expectation %s does not met: %s", expectedStringValue, stringValue)
93 }
94 if intValue != expectedIntValue {
95 t.Errorf("Expectation %d does not met: %d", expectedIntValue, intValue)
96 }
97 if !reflect.DeepEqual(expectedArrayValue, arrayValue) {
98 t.Errorf("Expectation %v does not met: %v", expectedArrayValue, arrayValue)
99 }
100 if err := mock.ExpectationsWereMet(); err != nil {
101 t.Error(err)
102 }
103}
104
105func TestQueryWithNoArgsAndWithArgsPanic(t *testing.T) {
106 defer func() {

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
ValueConverterOptionFunction · 0.85
AddRowMethod · 0.80
ExpectQueryMethod · 0.65
NewRowsMethod · 0.65
ExpectationsWereMetMethod · 0.65
WillReturnRowsMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…