Don't match all notes when `--link-to` or `--linked-by` have no match (#115)

pull/117/head
Mickaël Menu 2 years ago committed by GitHub
parent 9c06068cce
commit f3527ba60e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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, ",") + ")"

@ -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{

Loading…
Cancel
Save