Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test codes for search_commands.go #3285

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions search_commands_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package redis_test

import (
"reflect"

. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
"github.com/redis/go-redis/v9"
)

var _ = Describe("FTAggregateQuery", func() {
Comment on lines +3 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should either be moved in search_test.go or move all the search_test.go logic here. Feel free to decide which file would you like to use.

It("returns only the base query when options is nil", func() {
args := redis.FTAggregateQuery("testQuery", nil)
Expect(args).To(Equal(redis.AggregateQuery{"testQuery"}))
})

It("includes VERBATIM and SCORER when options are set", func() {
options := &redis.FTAggregateOptions{
Verbatim: true,
Scorer: "BM25",
}
args := redis.FTAggregateQuery("testQuery", options)
Expect(args[0]).To(Equal("testQuery"))
Expect(args).To(ContainElement("VERBATIM"))
Expect(args).To(ContainElement("SCORER"))
Expect(args).To(ContainElement("BM25"))
})

It("includes ADDSCORES when AddScores is true", func() {
options := &redis.FTAggregateOptions{
AddScores: true,
}
args := redis.FTAggregateQuery("q", options)
Expect(args).To(ContainElement("ADDSCORES"))
})

It("includes LOADALL when LoadAll is true", func() {
options := &redis.FTAggregateOptions{
LoadAll: true,
}
args := redis.FTAggregateQuery("q", options)
Expect(args).To(ContainElement("LOAD"))
Expect(args).To(ContainElement("*"))
})

It("includes LOAD when Load is provided", func() {
options := &redis.FTAggregateOptions{
Load: []redis.FTAggregateLoad{
{Field: "field1", As: "alias1"},
{Field: "field2"},
},
}
args := redis.FTAggregateQuery("q", options)
// Verify LOAD options related arguments
Expect(args).To(ContainElement("LOAD"))
// Check that field names and aliases are present
Expect(args).To(ContainElement("field1"))
Expect(args).To(ContainElement("alias1"))
Expect(args).To(ContainElement("field2"))
})

It("includes TIMEOUT when Timeout > 0", func() {
options := &redis.FTAggregateOptions{
Timeout: 500,
}
args := redis.FTAggregateQuery("q", options)
Expect(args).To(ContainElement("TIMEOUT"))
found := false
for _, a := range args {
if reflect.DeepEqual(a, 500) {
found = true
break
}
}
Expect(found).To(BeTrue())
})
})
Loading