Files
opencloud/services/search/pkg/parity/response_entity_test.go
T
2435420f69 [full-ci] chore: bump reva to 2.52.2 (#3955)
* chore: bump reva to 2.52.2

* Merge pull request #42 from opencloud-eu/fix-web-theme-merge

fix(web): merge copies of the theme sources so themeDefaults is never mutated

* Merge pull request #43 from opencloud-eu/fix-search-trailing-not

fix(search): handle missing operands in the bleve compiler

* Merge pull request #44 from opencloud-eu/fix-search-highlight-escaping

fix(search): escape file content in OpenSearch highlights

---------

Co-authored-by: Ralf Haferkamp <r.haferkamp@opencloud.eu>
Co-authored-by: Florian Schade <f.schade@icloud.com>
2026-11-11 14:14:34 +01:00

113 lines
4.7 KiB
Go

package parity
import (
"fmt"
searchMessage "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/messages/search/v0"
searchService "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/search/v0"
"github.com/opencloud-eu/opencloud/services/search/pkg/search"
)
func entityGroup() responseGroup {
parent := fixtureFolder("parent", withID("1$1!2"))
doc := fixtureDoc("bar.pdf",
withID("1$1!3"),
withParent(parent.ID),
withPath("./parent/bar.pdf"),
withMime("application/pdf"),
withSize(1234),
)
notes := fixtureDoc("notes.txt", withID("1$1!4"), withContent("foo bar baz"))
markup := fixtureDoc("markup.txt", withID("1$1!5"), withContent("foo <img src=x> qux"))
escaped := fixtureDoc("escaped.txt", withID("1$1!6"), withContent("foo &lt;img src=x&gt; zap"))
moved := func(e search.Engine) error { return e.Move(parent.ID, "1$1!9", "./somewhere/newname") }
return responseGroup{
name: "entity",
fixtures: []search.Resource{parent, doc, notes, markup, escaped},
cases: []responseCase{
{
id: 1, query: `name:"bar.pdf"`, reads: "Ref.Path", want: []string{"./parent/bar.pdf"},
read: reads(func(m *searchMessage.Match) string { return m.GetEntity().GetRef().GetPath() }),
},
{
id: 2, query: `name:"bar.pdf"`, reads: "Name", want: []string{"bar.pdf"},
read: reads(func(m *searchMessage.Match) string { return m.GetEntity().GetName() }),
},
{
id: 3, query: `name:"bar.pdf"`, reads: "Id", want: []string{"1$1!3"},
read: reads(func(m *searchMessage.Match) string { return resourceID(m.GetEntity().GetId()) }),
},
{
id: 4, query: `name:"bar.pdf"`, reads: "ParentId", want: []string{"1$1!2"},
read: reads(func(m *searchMessage.Match) string { return resourceID(m.GetEntity().GetParentId()) }),
},
{
id: 5, query: `name:"bar.pdf"`, reads: "Ref.ResourceId", want: []string{"1$1!1"},
read: reads(func(m *searchMessage.Match) string { return resourceID(m.GetEntity().GetRef().GetResourceId()) }),
},
{
id: 6, query: `name:"bar.pdf"`, reads: "Size", want: []string{"1234"},
read: reads(func(m *searchMessage.Match) string { return fmt.Sprint(m.GetEntity().GetSize()) }),
},
{
id: 7, query: `name:"bar.pdf"`, reads: "Type", want: []string{"1"},
read: reads(func(m *searchMessage.Match) string { return fmt.Sprint(m.GetEntity().GetType()) }),
},
{
id: 8, query: `name:"bar.pdf"`, reads: "MimeType", want: []string{"application/pdf"},
read: reads(func(m *searchMessage.Match) string { return m.GetEntity().GetMimeType() }),
},
{
id: 9, query: `name:"bar.pdf"`, reads: "Deleted", want: []string{"false"},
read: reads(func(m *searchMessage.Match) string { return fmt.Sprint(m.GetEntity().GetDeleted()) }),
},
{
id: 10, query: `name:"bar.pdf"`, reads: "Score", want: []string{"above zero"},
read: reads(func(m *searchMessage.Match) string {
if m.GetScore() > 0 {
return "above zero"
}
return fmt.Sprint(m.GetScore())
}),
},
{
id: 11, query: `path:"./parent"`, reads: "TotalMatches", want: []string{"2"},
read: func(resp *searchService.SearchIndexResponse) []string {
return []string{fmt.Sprint(resp.GetTotalMatches())}
},
},
{
id: 12, query: `name:"*notes*"`, reads: "Highlights", want: []string{`""`},
read: reads(func(m *searchMessage.Match) string { return fmt.Sprintf("%q", m.GetEntity().GetHighlights()) }),
},
{
id: 13, query: `content:bar`, reads: "Highlights", want: []string{"foo <mark>bar</mark> baz"},
read: reads(func(m *searchMessage.Match) string { return m.GetEntity().GetHighlights() }),
},
{
id: 17, query: `content:qux`, reads: "Highlights", want: []string{"foo &lt;img src=x&gt; <mark>qux</mark>"},
read: reads(func(m *searchMessage.Match) string { return m.GetEntity().GetHighlights() }),
},
{
id: 18, query: `content:zap`, reads: "Highlights", want: []string{"foo &amp;lt;img src=x&amp;gt; <mark>zap</mark>"},
read: reads(func(m *searchMessage.Match) string { return m.GetEntity().GetHighlights() }),
},
{
id: 14, do: moved, after: "moved to another parent", query: `name:"newname"`, reads: "ParentId", want: []string{"1$1!9"},
read: reads(func(m *searchMessage.Match) string { return resourceID(m.GetEntity().GetParentId()) }),
},
{
id: 15, do: moved, after: "moved to another parent", query: `name:"bar.pdf"`, reads: "ParentId", want: []string{"1$1!2"},
read: reads(func(m *searchMessage.Match) string { return resourceID(m.GetEntity().GetParentId()) }),
},
{
id: 16, do: moved, after: "moved to another parent", query: `name:"bar.pdf"`, reads: "Ref.Path", want: []string{"./somewhere/newname/bar.pdf"},
read: reads(func(m *searchMessage.Match) string { return m.GetEntity().GetRef().GetPath() }),
},
},
}
}