(t *testing.T)
| 152 | } |
| 153 | |
| 154 | func TestListBooks(t *testing.T) { |
| 155 | // Setup |
| 156 | db := database.InitTestMemoryDB(t) |
| 157 | defer db.Close() |
| 158 | |
| 159 | b1UUID := "js-book-uuid" |
| 160 | b2UUID := "linux-book-uuid" |
| 161 | |
| 162 | database.MustExec(t, "inserting book 1", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", b1UUID, "javascript") |
| 163 | database.MustExec(t, "inserting book 2", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", b2UUID, "linux") |
| 164 | |
| 165 | // Add notes to test count |
| 166 | database.MustExec(t, "inserting note 1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on) VALUES (?, ?, ?, ?)", "note-1", b1UUID, "note body 1", 1515199943) |
| 167 | database.MustExec(t, "inserting note 2", db, "INSERT INTO notes (uuid, book_uuid, body, added_on) VALUES (?, ?, ?, ?)", "note-2", b1UUID, "note body 2", 1515199944) |
| 168 | |
| 169 | ctx := context.DnoteCtx{DB: db} |
| 170 | var buf bytes.Buffer |
| 171 | |
| 172 | // Execute |
| 173 | err := listBooks(ctx, &buf, false) |
| 174 | if err != nil { |
| 175 | t.Fatal(err) |
| 176 | } |
| 177 | |
| 178 | got := buf.String() |
| 179 | |
| 180 | // Verify output |
| 181 | assert.Equal(t, strings.Contains(got, "javascript"), true, "should contain javascript book") |
| 182 | assert.Equal(t, strings.Contains(got, "linux"), true, "should contain linux book") |
| 183 | assert.Equal(t, strings.Contains(got, "(2)"), true, "should show 2 notes for javascript") |
| 184 | } |
nothing calls this directly
no test coverage detected