FIXME: this function is kinda big but it slows things down to be constantly loading and reloading the schema..
(t *testing.T)
| 729 | // loading and reloading the schema.. |
| 730 | |
| 731 | func TestUsageContext(t *testing.T) { |
| 732 | RunWithSchemaContext(context.Background(), defaultSchema, t, func(ctx context.Context, db *DB, t *testing.T) { |
| 733 | loadDefaultFixtureContext(ctx, db, t) |
| 734 | slicemembers := []SliceMember{} |
| 735 | err := db.SelectContext(ctx, &slicemembers, "SELECT * FROM place ORDER BY telcode ASC") |
| 736 | if err != nil { |
| 737 | t.Fatal(err) |
| 738 | } |
| 739 | |
| 740 | people := []Person{} |
| 741 | |
| 742 | err = db.SelectContext(ctx, &people, "SELECT * FROM person ORDER BY first_name ASC") |
| 743 | if err != nil { |
| 744 | t.Fatal(err) |
| 745 | } |
| 746 | |
| 747 | jason, john := people[0], people[1] |
| 748 | if jason.FirstName != "Jason" { |
| 749 | t.Errorf("Expecting FirstName of Jason, got %s", jason.FirstName) |
| 750 | } |
| 751 | if jason.LastName != "Moiron" { |
| 752 | t.Errorf("Expecting LastName of Moiron, got %s", jason.LastName) |
| 753 | } |
| 754 | if jason.Email != "jmoiron@jmoiron.net" { |
| 755 | t.Errorf("Expecting Email of jmoiron@jmoiron.net, got %s", jason.Email) |
| 756 | } |
| 757 | if john.FirstName != "John" || john.LastName != "Doe" || john.Email != "johndoeDNE@gmail.net" { |
| 758 | t.Errorf("John Doe's person record not what expected: Got %v\n", john) |
| 759 | } |
| 760 | |
| 761 | jason = Person{} |
| 762 | err = db.GetContext(ctx, &jason, db.Rebind("SELECT * FROM person WHERE first_name=?"), "Jason") |
| 763 | |
| 764 | if err != nil { |
| 765 | t.Fatal(err) |
| 766 | } |
| 767 | if jason.FirstName != "Jason" { |
| 768 | t.Errorf("Expecting to get back Jason, but got %v\n", jason.FirstName) |
| 769 | } |
| 770 | |
| 771 | err = db.GetContext(ctx, &jason, db.Rebind("SELECT * FROM person WHERE first_name=?"), "Foobar") |
| 772 | if err == nil { |
| 773 | t.Errorf("Expecting an error, got nil\n") |
| 774 | } |
| 775 | if err != sql.ErrNoRows { |
| 776 | t.Errorf("Expected sql.ErrNoRows, got %v\n", err) |
| 777 | } |
| 778 | |
| 779 | // The following tests check statement reuse, which was actually a problem |
| 780 | // due to copying being done when creating Stmt's which was eventually removed |
| 781 | stmt1, err := db.PreparexContext(ctx, db.Rebind("SELECT * FROM person WHERE first_name=?")) |
| 782 | if err != nil { |
| 783 | t.Fatal(err) |
| 784 | } |
| 785 | jason = Person{} |
| 786 | |
| 787 | row := stmt1.QueryRowx("DoesNotExist") |
| 788 | row.Scan(&jason) |
nothing calls this directly
no test coverage detected