(t *testing.T)
| 295 | } |
| 296 | |
| 297 | func TestJoinQueryContext(t *testing.T) { |
| 298 | type Employee struct { |
| 299 | Name string |
| 300 | ID int64 |
| 301 | // BossID is an id into the employee table |
| 302 | BossID sql.NullInt64 `db:"boss_id"` |
| 303 | } |
| 304 | type Boss Employee |
| 305 | |
| 306 | RunWithSchemaContext(context.Background(), defaultSchema, t, func(ctx context.Context, db *DB, t *testing.T) { |
| 307 | loadDefaultFixtureContext(ctx, db, t) |
| 308 | |
| 309 | var employees []struct { |
| 310 | Employee |
| 311 | Boss `db:"boss"` |
| 312 | } |
| 313 | |
| 314 | err := db.SelectContext(ctx, |
| 315 | &employees, |
| 316 | `SELECT employees.*, boss.id "boss.id", boss.name "boss.name" FROM employees |
| 317 | JOIN employees AS boss ON employees.boss_id = boss.id`) |
| 318 | if err != nil { |
| 319 | t.Fatal(err) |
| 320 | } |
| 321 | |
| 322 | for _, em := range employees { |
| 323 | if len(em.Employee.Name) == 0 { |
| 324 | t.Errorf("Expected non zero lengthed name.") |
| 325 | } |
| 326 | if em.Employee.BossID.Int64 != em.Boss.ID { |
| 327 | t.Errorf("Expected boss ids to match") |
| 328 | } |
| 329 | } |
| 330 | }) |
| 331 | } |
| 332 | |
| 333 | func TestJoinQueryNamedPointerStructsContext(t *testing.T) { |
| 334 | type Employee struct { |
nothing calls this directly
no test coverage detected