(t *testing.T)
| 63 | } |
| 64 | |
| 65 | func 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 | |
| 105 | func TestQueryWithNoArgsAndWithArgsPanic(t *testing.T) { |
| 106 | defer func() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…