From f3527ba60e9df85d52d6f565c8c82484b605150e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Menu?= Date: Sat, 11 Dec 2021 18:53:07 +0100 Subject: [PATCH] Don't match all notes when `--link-to` or `--linked-by` have no match (#115) --- internal/adapter/sqlite/note_dao.go | 2 +- internal/adapter/sqlite/note_dao_test.go | 44 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/internal/adapter/sqlite/note_dao.go b/internal/adapter/sqlite/note_dao.go index 30a32a8..574b324 100644 --- a/internal/adapter/sqlite/note_dao.go +++ b/internal/adapter/sqlite/note_dao.go @@ -454,7 +454,7 @@ func (d *NoteDAO) findRows(opts core.NoteFindOpts, selection noteSelection) (*sq return err } if len(ids) == 0 { - return nil + return fmt.Errorf("could not find notes at: " + strings.Join(hrefs, ", ")) } idsList := "(" + joinNoteIDs(ids, ",") + ")" diff --git a/internal/adapter/sqlite/note_dao_test.go b/internal/adapter/sqlite/note_dao_test.go index ce9e034..4be1a6a 100644 --- a/internal/adapter/sqlite/note_dao_test.go +++ b/internal/adapter/sqlite/note_dao_test.go @@ -633,6 +633,16 @@ func TestNoteDAOFindUnlinkedMentions(t *testing.T) { ) } +func TestNoteDAOFindMentionUnknown(t *testing.T) { + testNoteDAO(t, func(tx Transaction, dao *NoteDAO) { + opts := core.NoteFindOpts{ + Mention: []string{"will-not-be-found"}, + } + _, err := dao.Find(opts) + assert.Err(t, err, "could not find notes at: will-not-be-found") + }) +} + func TestNoteDAOFindMentionedBy(t *testing.T) { testNoteDAOFind(t, core.NoteFindOpts{MentionedBy: []string{"ref/test/b.md", "log/2021-01-04.md"}}, @@ -697,6 +707,16 @@ func TestNoteDAOFindUnlinkedMentionedBy(t *testing.T) { ) } +func TestNoteDAOFindMentionedByUnknown(t *testing.T) { + testNoteDAO(t, func(tx Transaction, dao *NoteDAO) { + opts := core.NoteFindOpts{ + MentionedBy: []string{"will-not-be-found"}, + } + _, err := dao.Find(opts) + assert.Err(t, err, "could not find notes at: will-not-be-found") + }) +} + func TestNoteDAOFindLinkedBy(t *testing.T) { testNoteDAOFindPaths(t, core.NoteFindOpts{ @@ -792,6 +812,18 @@ func TestNoteDAOFindLinkedByWithSnippets(t *testing.T) { ) } +func TestNoteDAOFindLinkedByUnknown(t *testing.T) { + testNoteDAO(t, func(tx Transaction, dao *NoteDAO) { + opts := core.NoteFindOpts{ + LinkedBy: &core.LinkFilter{ + Hrefs: []string{"will-not-be-found"}, + }, + } + _, err := dao.Find(opts) + assert.Err(t, err, "could not find notes at: will-not-be-found") + }) +} + func TestNoteDAOFindNotLinkedBy(t *testing.T) { testNoteDAOFindPaths(t, core.NoteFindOpts{ @@ -854,6 +886,18 @@ func TestNoteDAOFindNotLinkTo(t *testing.T) { ) } +func TestNoteDAOFindLinkToUnknown(t *testing.T) { + testNoteDAO(t, func(tx Transaction, dao *NoteDAO) { + opts := core.NoteFindOpts{ + LinkTo: &core.LinkFilter{ + Hrefs: []string{"will-not-be-found"}, + }, + } + _, err := dao.Find(opts) + assert.Err(t, err, "could not find notes at: will-not-be-found") + }) +} + func TestNoteDAOFindRelated(t *testing.T) { testNoteDAOFindPaths(t, core.NoteFindOpts{