(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestBatchBooks(t *testing.T) { |
| 17 | uri := local.PostgreSQL(t, []string{"schema.sql"}) |
| 18 | |
| 19 | ctx := context.Background() |
| 20 | |
| 21 | db, err := pgx.Connect(ctx, uri) |
| 22 | if err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | defer db.Close(ctx) |
| 26 | |
| 27 | dq := New(db) |
| 28 | |
| 29 | // create an author |
| 30 | a, err := dq.CreateAuthor(ctx, "Unknown Master") |
| 31 | if err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | |
| 35 | now := pgtype.Timestamptz{Time: time.Now(), Valid: true} |
| 36 | |
| 37 | // batch insert new books |
| 38 | newBooksParams := []CreateBookParams{ |
| 39 | { |
| 40 | AuthorID: a.AuthorID, |
| 41 | Isbn: "1", |
| 42 | Title: "my book title", |
| 43 | BookType: BookTypeFICTION, |
| 44 | Year: 2016, |
| 45 | Available: now, |
| 46 | Tags: []string{}, |
| 47 | }, |
| 48 | { |
| 49 | AuthorID: a.AuthorID, |
| 50 | Isbn: "2", |
| 51 | Title: "the second book", |
| 52 | BookType: BookTypeFICTION, |
| 53 | Year: 2016, |
| 54 | Available: now, |
| 55 | Tags: []string{"cool", "unique"}, |
| 56 | }, |
| 57 | { |
| 58 | AuthorID: a.AuthorID, |
| 59 | Isbn: "3", |
| 60 | Title: "the third book", |
| 61 | BookType: BookTypeFICTION, |
| 62 | Year: 2001, |
| 63 | Available: now, |
| 64 | Tags: []string{"cool"}, |
| 65 | }, |
| 66 | { |
| 67 | AuthorID: a.AuthorID, |
| 68 | Isbn: "4", |
| 69 | Title: "4th place finisher", |
| 70 | BookType: BookTypeNONFICTION, |
| 71 | Year: 2011, |
| 72 | Available: now, |
| 73 | Tags: []string{"other"}, |
nothing calls this directly
no test coverage detected