(t *testing.T)
| 378 | } |
| 379 | |
| 380 | func TestEmbeddedStructs(t *testing.T) { |
| 381 | type Loop1 struct{ Person } |
| 382 | type Loop2 struct{ Loop1 } |
| 383 | type Loop3 struct{ Loop2 } |
| 384 | |
| 385 | RunWithSchema(defaultSchema, t, func(db *DB, t *testing.T, now string) { |
| 386 | loadDefaultFixture(db, t) |
| 387 | peopleAndPlaces := []PersonPlace{} |
| 388 | err := db.Select( |
| 389 | &peopleAndPlaces, |
| 390 | `SELECT person.*, place.* FROM |
| 391 | person natural join place`) |
| 392 | if err != nil { |
| 393 | t.Fatal(err) |
| 394 | } |
| 395 | for _, pp := range peopleAndPlaces { |
| 396 | if len(pp.Person.FirstName) == 0 { |
| 397 | t.Errorf("Expected non zero lengthed first name.") |
| 398 | } |
| 399 | if len(pp.Place.Country) == 0 { |
| 400 | t.Errorf("Expected non zero lengthed country.") |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | // test embedded structs with StructScan |
| 405 | rows, err := db.Queryx( |
| 406 | `SELECT person.*, place.* FROM |
| 407 | person natural join place`) |
| 408 | if err != nil { |
| 409 | t.Error(err) |
| 410 | } |
| 411 | |
| 412 | perp := PersonPlace{} |
| 413 | rows.Next() |
| 414 | err = rows.StructScan(&perp) |
| 415 | if err != nil { |
| 416 | t.Error(err) |
| 417 | } |
| 418 | |
| 419 | if len(perp.Person.FirstName) == 0 { |
| 420 | t.Errorf("Expected non zero lengthed first name.") |
| 421 | } |
| 422 | if len(perp.Place.Country) == 0 { |
| 423 | t.Errorf("Expected non zero lengthed country.") |
| 424 | } |
| 425 | |
| 426 | rows.Close() |
| 427 | |
| 428 | // test the same for embedded pointer structs |
| 429 | peopleAndPlacesPtrs := []PersonPlacePtr{} |
| 430 | err = db.Select( |
| 431 | &peopleAndPlacesPtrs, |
| 432 | `SELECT person.*, place.* FROM |
| 433 | person natural join place`) |
| 434 | if err != nil { |
| 435 | t.Fatal(err) |
| 436 | } |
| 437 | for _, pp := range peopleAndPlacesPtrs { |
nothing calls this directly
no test coverage detected