mirror of
https://github.com/redis/go-redis.git
synced 2025-04-17 20:17:02 +03:00
Add test codes for search_commands.go (#3285)
* feat: add test codes for search_commands.go * feat: move ftaggregate tests to search_test.go * Update search_test.go Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com> * feat: remove reflect from test * Update search_test.go fix type in Sprintf --------- Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com>
This commit is contained in:
parent
aa7019d718
commit
d4e74b125d
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ testdata/*
|
|||||||
*.tar.gz
|
*.tar.gz
|
||||||
*.dic
|
*.dic
|
||||||
redis8tests.sh
|
redis8tests.sh
|
||||||
|
.vscode
|
||||||
|
@ -805,6 +805,73 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should return only the base query when options is nil", Label("search", "ftaggregate"), func() {
|
||||||
|
args := redis.FTAggregateQuery("testQuery", nil)
|
||||||
|
Expect(args).To(Equal(redis.AggregateQuery{"testQuery"}))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should include VERBATIM and SCORER when options are set", Label("search", "ftaggregate"), 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("should include ADDSCORES when AddScores is true", Label("search", "ftaggregate"), func() {
|
||||||
|
options := &redis.FTAggregateOptions{
|
||||||
|
AddScores: true,
|
||||||
|
}
|
||||||
|
args := redis.FTAggregateQuery("q", options)
|
||||||
|
Expect(args).To(ContainElement("ADDSCORES"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should include LOADALL when LoadAll is true", Label("search", "ftaggregate"), func() {
|
||||||
|
options := &redis.FTAggregateOptions{
|
||||||
|
LoadAll: true,
|
||||||
|
}
|
||||||
|
args := redis.FTAggregateQuery("q", options)
|
||||||
|
Expect(args).To(ContainElement("LOAD"))
|
||||||
|
Expect(args).To(ContainElement("*"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should include LOAD when Load is provided", Label("search", "ftaggregate"), 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("should include TIMEOUT when Timeout > 0", Label("search", "ftaggregate"), func() {
|
||||||
|
options := &redis.FTAggregateOptions{
|
||||||
|
Timeout: 500,
|
||||||
|
}
|
||||||
|
args := redis.FTAggregateQuery("q", options)
|
||||||
|
Expect(args).To(ContainElement("TIMEOUT"))
|
||||||
|
found := false
|
||||||
|
for i, a := range args {
|
||||||
|
if fmt.Sprintf("%s", a) == "TIMEOUT" {
|
||||||
|
Expect(fmt.Sprintf("%d", args[i+1])).To(Equal("500"))
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Expect(found).To(BeTrue())
|
||||||
|
})
|
||||||
|
|
||||||
It("should FTSearch SkipInitialScan", Label("search", "ftsearch"), func() {
|
It("should FTSearch SkipInitialScan", Label("search", "ftsearch"), func() {
|
||||||
client.HSet(ctx, "doc1", "foo", "bar")
|
client.HSet(ctx, "doc1", "foo", "bar")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user