FIXME: this function is kinda big but it slows things down to be constantly loading and reloading the schema..
(t *testing.T)
| 912 | // loading and reloading the schema.. |
| 913 | |
| 914 | func TestUsage(t *testing.T) { |
| 915 | RunWithSchema(defaultSchema, t, func(db *DB, t *testing.T, now string) { |
| 916 | loadDefaultFixture(db, t) |
| 917 | slicemembers := []SliceMember{} |
| 918 | err := db.Select(&slicemembers, "SELECT * FROM place ORDER BY telcode ASC") |
| 919 | if err != nil { |
| 920 | t.Fatal(err) |
| 921 | } |
| 922 | |
| 923 | people := []Person{} |
| 924 | |
| 925 | err = db.Select(&people, "SELECT * FROM person ORDER BY first_name ASC") |
| 926 | if err != nil { |
| 927 | t.Fatal(err) |
| 928 | } |
| 929 | |
| 930 | jason, john := people[0], people[1] |
| 931 | if jason.FirstName != "Jason" { |
| 932 | t.Errorf("Expecting FirstName of Jason, got %s", jason.FirstName) |
| 933 | } |
| 934 | if jason.LastName != "Moiron" { |
| 935 | t.Errorf("Expecting LastName of Moiron, got %s", jason.LastName) |
| 936 | } |
| 937 | if jason.Email != "jmoiron@jmoiron.net" { |
| 938 | t.Errorf("Expecting Email of jmoiron@jmoiron.net, got %s", jason.Email) |
| 939 | } |
| 940 | if john.FirstName != "John" || john.LastName != "Doe" || john.Email != "johndoeDNE@gmail.net" { |
| 941 | t.Errorf("John Doe's person record not what expected: Got %v\n", john) |
| 942 | } |
| 943 | |
| 944 | jason = Person{} |
| 945 | err = db.Get(&jason, db.Rebind("SELECT * FROM person WHERE first_name=?"), "Jason") |
| 946 | |
| 947 | if err != nil { |
| 948 | t.Fatal(err) |
| 949 | } |
| 950 | if jason.FirstName != "Jason" { |
| 951 | t.Errorf("Expecting to get back Jason, but got %v\n", jason.FirstName) |
| 952 | } |
| 953 | |
| 954 | err = db.Get(&jason, db.Rebind("SELECT * FROM person WHERE first_name=?"), "Foobar") |
| 955 | if err == nil { |
| 956 | t.Errorf("Expecting an error, got nil\n") |
| 957 | } |
| 958 | if err != sql.ErrNoRows { |
| 959 | t.Errorf("Expected sql.ErrNoRows, got %v\n", err) |
| 960 | } |
| 961 | |
| 962 | // The following tests check statement reuse, which was actually a problem |
| 963 | // due to copying being done when creating Stmt's which was eventually removed |
| 964 | stmt1, err := db.Preparex(db.Rebind("SELECT * FROM person WHERE first_name=?")) |
| 965 | if err != nil { |
| 966 | t.Fatal(err) |
| 967 | } |
| 968 | jason = Person{} |
| 969 | |
| 970 | row := stmt1.QueryRowx("DoesNotExist") |
| 971 | row.Scan(&jason) |
nothing calls this directly
no test coverage detected