MCPcopy Create free account
hub / github.com/AdRoll/baker / assertRows

Function assertRows

output/sqlite_test.go:108–154  ·  view source on GitHub ↗
(t *testing.T, fname string, want [][]string)

Source from the content-addressed store, hash-verified

106}
107
108func 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
156func TestSQLiteInsertRows(t *testing.T) { testSQLiteInsertRows(t, false) }
157

Callers 1

testSQLiteInsertRowsFunction · 0.85

Calls 1

CloseMethod · 0.65

Tested by

no test coverage detected