(t *testing.T, fname string, want [][]string)
| 106 | } |
| 107 | |
| 108 | func assertRows(t *testing.T, fname string, want [][]string) { |
| 109 | // this helper asserts we're going to find these rows and records in |
| 110 | // the sqlite database at the given path, in a table called 'lines'. |
| 111 | t.Helper() |
| 112 | |
| 113 | conn, err := sql.Open("sqlite3", fname) |
| 114 | if err != nil { |
| 115 | t.Fatalf("sqlite database %q not found: %s", fname, err) |
| 116 | } |
| 117 | defer conn.Close() |
| 118 | |
| 119 | rows, err := conn.Query("SELECT * FROM lines") |
| 120 | if err != nil { |
| 121 | t.Fatalf("failed select: %s", err) |
| 122 | } |
| 123 | defer rows.Close() |
| 124 | |
| 125 | cols := make([]interface{}, len(want[0])) |
| 126 | for i := range cols { |
| 127 | cols[i] = new(string) |
| 128 | } |
| 129 | |
| 130 | irow := 0 |
| 131 | for rows.Next() { |
| 132 | if irow+1 >= len(want) { |
| 133 | // There are more rows than we expected, anyway consume and count |
| 134 | // them all to report the actual number in the error message. |
| 135 | irow++ |
| 136 | continue |
| 137 | } |
| 138 | |
| 139 | if err := rows.Scan(cols...); err != nil { |
| 140 | t.Fatalf("failed scan: %s", err) |
| 141 | } |
| 142 | for i := range cols { |
| 143 | col := *(cols[i].(*string)) |
| 144 | if want[irow][i] != col { |
| 145 | t.Errorf("row[%d][%d] = %q, want %q", irow, i, col, want[irow][i]) |
| 146 | } |
| 147 | } |
| 148 | irow++ |
| 149 | } |
| 150 | |
| 151 | if irow != len(want) { |
| 152 | t.Errorf("got %d total rows, want %d", irow, len(want)) |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | func TestSQLiteInsertRows(t *testing.T) { testSQLiteInsertRows(t, false) } |
| 157 |
no test coverage detected