(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestAuthors(t *testing.T) { |
| 14 | sdb, cleanup := sqltest.SQLite(t, []string{"schema.sql"}) |
| 15 | defer sdb.Close() |
| 16 | defer cleanup() |
| 17 | |
| 18 | ctx := context.Background() |
| 19 | db := New(sdb) |
| 20 | |
| 21 | // list all authors |
| 22 | authors, err := db.ListAuthors(ctx) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | t.Log(authors) |
| 27 | |
| 28 | // create an author |
| 29 | result, err := db.CreateAuthor(ctx, CreateAuthorParams{ |
| 30 | Name: "Brian Kernighan", |
| 31 | Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true}, |
| 32 | }) |
| 33 | if err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | authorID, err := result.LastInsertId() |
| 37 | if err != nil { |
| 38 | t.Fatal(err) |
| 39 | } |
| 40 | t.Log(authorID) |
| 41 | |
| 42 | // get the author we just inserted |
| 43 | fetchedAuthor, err := db.GetAuthor(ctx, authorID) |
| 44 | if err != nil { |
| 45 | t.Fatal(err) |
| 46 | } |
| 47 | t.Log(fetchedAuthor) |
| 48 | } |
nothing calls this directly
no test coverage detected