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