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