Fixes test

This commit is contained in:
mattn 2013-09-09 11:27:04 +09:00
parent 9150577da1
commit fc9f8cab24
1 changed files with 37 additions and 1 deletions

View File

@ -590,7 +590,7 @@ func TestExecer(t *testing.T) {
defer db.Close() defer db.Close()
_, err = db.Exec(` _, err = db.Exec(`
create table foo (id integer)"); create table foo (id integer);
insert into foo values(1); insert into foo values(1);
insert into foo values(2); insert into foo values(2);
insert into foo values(3); insert into foo values(3);
@ -598,5 +598,41 @@ func TestExecer(t *testing.T) {
if err != nil { if err != nil {
t.Error("Failed to call db.Exec:", err) t.Error("Failed to call db.Exec:", err)
} }
if err != nil {
t.Error("Failed to call res.RowsAffected:", err)
}
}
func TestQueryer(t *testing.T) {
tempFilename := TempFilename()
db, err := sql.Open("sqlite3", tempFilename)
if err != nil {
t.Fatal("Failed to open database:", err)
}
defer os.Remove(tempFilename)
defer db.Close()
rows, err := db.Query(`
create table foo (id integer);
insert into foo values(1);
insert into foo values(2);
insert into foo values(3);
select id from foo order by id;
`)
if err != nil {
t.Error("Failed to call db.Exec:", err)
}
defer rows.Close()
n := 1
for rows.Next() {
var id int
err = rows.Scan(&id)
if err != nil {
t.Error("Failed to db.Query:", err)
}
if id != n {
t.Error("Failed to db.Query: not matched results")
}
}
} }