(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestBooks(t *testing.T) { |
| 17 | ctx := context.Background() |
| 18 | uri := local.PostgreSQL(t, []string{"schema.sql"}) |
| 19 | db, err := pgx.Connect(ctx, uri) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | defer db.Close(ctx) |
| 24 | |
| 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(ctx) |
| 35 | if err != nil { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | |
| 39 | tq := dq.WithTx(tx) |
| 40 | |
| 41 | // save first book |
| 42 | now := pgtype.Timestamptz{Time: time.Now(), Valid: true} |
| 43 | _, err = tq.CreateBook(ctx, CreateBookParams{ |
| 44 | AuthorID: a.AuthorID, |
| 45 | Isbn: "1", |
| 46 | Title: "my book title", |
| 47 | BookType: BookTypeFICTION, |
| 48 | Year: 2016, |
| 49 | Available: now, |
| 50 | Tags: []string{}, |
| 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: BookTypeFICTION, |
| 62 | Year: 2016, |
| 63 | Available: now, |
| 64 | Tags: []string{"cool", "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", |
nothing calls this directly
no test coverage detected