Skip to content

Commit d4e74b1

Browse files
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 <[email protected]> * feat: remove reflect from test * Update search_test.go fix type in Sprintf --------- Co-authored-by: Nedyalko Dyakov <[email protected]>
1 parent aa7019d commit d4e74b1

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ testdata/*
55
*.tar.gz
66
*.dic
77
redis8tests.sh
8+
.vscode

Diff for: search_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,73 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
805805
}
806806
})
807807

808+
It("should return only the base query when options is nil", Label("search", "ftaggregate"), func() {
809+
args := redis.FTAggregateQuery("testQuery", nil)
810+
Expect(args).To(Equal(redis.AggregateQuery{"testQuery"}))
811+
})
812+
813+
It("should include VERBATIM and SCORER when options are set", Label("search", "ftaggregate"), func() {
814+
options := &redis.FTAggregateOptions{
815+
Verbatim: true,
816+
Scorer: "BM25",
817+
}
818+
args := redis.FTAggregateQuery("testQuery", options)
819+
Expect(args[0]).To(Equal("testQuery"))
820+
Expect(args).To(ContainElement("VERBATIM"))
821+
Expect(args).To(ContainElement("SCORER"))
822+
Expect(args).To(ContainElement("BM25"))
823+
})
824+
825+
It("should include ADDSCORES when AddScores is true", Label("search", "ftaggregate"), func() {
826+
options := &redis.FTAggregateOptions{
827+
AddScores: true,
828+
}
829+
args := redis.FTAggregateQuery("q", options)
830+
Expect(args).To(ContainElement("ADDSCORES"))
831+
})
832+
833+
It("should include LOADALL when LoadAll is true", Label("search", "ftaggregate"), func() {
834+
options := &redis.FTAggregateOptions{
835+
LoadAll: true,
836+
}
837+
args := redis.FTAggregateQuery("q", options)
838+
Expect(args).To(ContainElement("LOAD"))
839+
Expect(args).To(ContainElement("*"))
840+
})
841+
842+
It("should include LOAD when Load is provided", Label("search", "ftaggregate"), func() {
843+
options := &redis.FTAggregateOptions{
844+
Load: []redis.FTAggregateLoad{
845+
{Field: "field1", As: "alias1"},
846+
{Field: "field2"},
847+
},
848+
}
849+
args := redis.FTAggregateQuery("q", options)
850+
// Verify LOAD options related arguments
851+
Expect(args).To(ContainElement("LOAD"))
852+
// Check that field names and aliases are present
853+
Expect(args).To(ContainElement("field1"))
854+
Expect(args).To(ContainElement("alias1"))
855+
Expect(args).To(ContainElement("field2"))
856+
})
857+
858+
It("should include TIMEOUT when Timeout > 0", Label("search", "ftaggregate"), func() {
859+
options := &redis.FTAggregateOptions{
860+
Timeout: 500,
861+
}
862+
args := redis.FTAggregateQuery("q", options)
863+
Expect(args).To(ContainElement("TIMEOUT"))
864+
found := false
865+
for i, a := range args {
866+
if fmt.Sprintf("%s", a) == "TIMEOUT" {
867+
Expect(fmt.Sprintf("%d", args[i+1])).To(Equal("500"))
868+
found = true
869+
break
870+
}
871+
}
872+
Expect(found).To(BeTrue())
873+
})
874+
808875
It("should FTSearch SkipInitialScan", Label("search", "ftsearch"), func() {
809876
client.HSet(ctx, "doc1", "foo", "bar")
810877

0 commit comments

Comments
 (0)