Test a new backwards compatible feature, that missing scan destinations will silently scan into sql.RawText rather than failing/panicing
(t *testing.T)
| 262 | // Test a new backwards compatible feature, that missing scan destinations |
| 263 | // will silently scan into sql.RawText rather than failing/panicing |
| 264 | func TestMissingNames(t *testing.T) { |
| 265 | RunWithSchema(defaultSchema, t, func(db *DB, t *testing.T, now string) { |
| 266 | loadDefaultFixture(db, t) |
| 267 | type PersonPlus struct { |
| 268 | FirstName string `db:"first_name"` |
| 269 | LastName string `db:"last_name"` |
| 270 | Email string |
| 271 | // AddedAt time.Time `db:"added_at"` |
| 272 | } |
| 273 | |
| 274 | // test Select first |
| 275 | pps := []PersonPlus{} |
| 276 | // pps lacks added_at destination |
| 277 | err := db.Select(&pps, "SELECT * FROM person") |
| 278 | if err == nil { |
| 279 | t.Error("Expected missing name from Select to fail, but it did not.") |
| 280 | } |
| 281 | |
| 282 | // test Get |
| 283 | pp := PersonPlus{} |
| 284 | err = db.Get(&pp, "SELECT * FROM person LIMIT 1") |
| 285 | if err == nil { |
| 286 | t.Error("Expected missing name Get to fail, but it did not.") |
| 287 | } |
| 288 | |
| 289 | // test naked StructScan |
| 290 | pps = []PersonPlus{} |
| 291 | rows, err := db.Query("SELECT * FROM person LIMIT 1") |
| 292 | if err != nil { |
| 293 | t.Fatal(err) |
| 294 | } |
| 295 | rows.Next() |
| 296 | err = StructScan(rows, &pps) |
| 297 | if err == nil { |
| 298 | t.Error("Expected missing name in StructScan to fail, but it did not.") |
| 299 | } |
| 300 | rows.Close() |
| 301 | |
| 302 | // now try various things with unsafe set. |
| 303 | db = db.Unsafe() |
| 304 | pps = []PersonPlus{} |
| 305 | err = db.Select(&pps, "SELECT * FROM person") |
| 306 | if err != nil { |
| 307 | t.Error(err) |
| 308 | } |
| 309 | |
| 310 | // test Get |
| 311 | pp = PersonPlus{} |
| 312 | err = db.Get(&pp, "SELECT * FROM person LIMIT 1") |
| 313 | if err != nil { |
| 314 | t.Error(err) |
| 315 | } |
| 316 | |
| 317 | // test naked StructScan |
| 318 | pps = []PersonPlus{} |
| 319 | rowsx, err := db.Queryx("SELECT * FROM person LIMIT 1") |
| 320 | if err != nil { |
| 321 | t.Fatal(err) |
nothing calls this directly
no test coverage detected