(t *testing.T)
| 203 | } |
| 204 | |
| 205 | func TestEmbeddedStructsContextContext(t *testing.T) { |
| 206 | type Loop1 struct{ Person } |
| 207 | type Loop2 struct{ Loop1 } |
| 208 | type Loop3 struct{ Loop2 } |
| 209 | |
| 210 | RunWithSchemaContext(context.Background(), defaultSchema, t, func(ctx context.Context, db *DB, t *testing.T) { |
| 211 | loadDefaultFixtureContext(ctx, db, t) |
| 212 | peopleAndPlaces := []PersonPlace{} |
| 213 | err := db.SelectContext( |
| 214 | ctx, |
| 215 | &peopleAndPlaces, |
| 216 | `SELECT person.*, place.* FROM |
| 217 | person natural join place`) |
| 218 | if err != nil { |
| 219 | t.Fatal(err) |
| 220 | } |
| 221 | for _, pp := range peopleAndPlaces { |
| 222 | if len(pp.Person.FirstName) == 0 { |
| 223 | t.Errorf("Expected non zero lengthed first name.") |
| 224 | } |
| 225 | if len(pp.Place.Country) == 0 { |
| 226 | t.Errorf("Expected non zero lengthed country.") |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // test embedded structs with StructScan |
| 231 | rows, err := db.QueryxContext( |
| 232 | ctx, |
| 233 | `SELECT person.*, place.* FROM |
| 234 | person natural join place`) |
| 235 | if err != nil { |
| 236 | t.Error(err) |
| 237 | } |
| 238 | |
| 239 | perp := PersonPlace{} |
| 240 | rows.Next() |
| 241 | err = rows.StructScan(&perp) |
| 242 | if err != nil { |
| 243 | t.Error(err) |
| 244 | } |
| 245 | |
| 246 | if len(perp.Person.FirstName) == 0 { |
| 247 | t.Errorf("Expected non zero lengthed first name.") |
| 248 | } |
| 249 | if len(perp.Place.Country) == 0 { |
| 250 | t.Errorf("Expected non zero lengthed country.") |
| 251 | } |
| 252 | |
| 253 | rows.Close() |
| 254 | |
| 255 | // test the same for embedded pointer structs |
| 256 | peopleAndPlacesPtrs := []PersonPlacePtr{} |
| 257 | err = db.SelectContext( |
| 258 | ctx, |
| 259 | &peopleAndPlacesPtrs, |
| 260 | `SELECT person.*, place.* FROM |
| 261 | person natural join place`) |
| 262 | if err != nil { |
nothing calls this directly
no test coverage detected