(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestBooks(t *testing.T) { |
| 20 | db, cleanup := sqltest.SQLite(t, []string{"schema.sql"}) |
| 21 | defer db.Close() |
| 22 | defer cleanup() |
| 23 | |
| 24 | ctx := context.Background() |
| 25 | dq := New(db) |
| 26 | |
| 27 | // create an author |
| 28 | a, err := dq.CreateAuthor(ctx, "Unknown Master") |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | |
| 33 | // create transaction |
| 34 | tx, err := db.Begin() |
| 35 | if err != nil { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | |
| 39 | tq := dq.WithTx(tx) |
| 40 | |
| 41 | // save first book |
| 42 | now := time.Now() |
| 43 | _, err = tq.CreateBook(ctx, CreateBookParams{ |
| 44 | AuthorID: a.AuthorID, |
| 45 | Isbn: "1", |
| 46 | Title: "my book title", |
| 47 | BookType: BooksBookTypeFICTION, |
| 48 | Yr: 2016, |
| 49 | Available: now, |
| 50 | Tag: "", |
| 51 | }) |
| 52 | if err != nil { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | |
| 56 | // save second book |
| 57 | b1, err := tq.CreateBook(ctx, CreateBookParams{ |
| 58 | AuthorID: a.AuthorID, |
| 59 | Isbn: "2", |
| 60 | Title: "the second book", |
| 61 | BookType: BooksBookTypeFICTION, |
| 62 | Yr: 2016, |
| 63 | Available: now, |
| 64 | Tag: "unique", |
| 65 | }) |
| 66 | if err != nil { |
| 67 | t.Fatal(err) |
| 68 | } |
| 69 | |
| 70 | // update the title and tags |
| 71 | err = tq.UpdateBook(ctx, UpdateBookParams{ |
| 72 | BookID: b1.BookID, |
| 73 | Title: "changed second title", |
| 74 | Tag: "disastor", |
| 75 | }) |
| 76 | if err != nil { |
nothing calls this directly
no test coverage detected