Skip to content

Commit 4316fff

Browse files
feat: move ftaggregate tests to search_test.go
1 parent ae07968 commit 4316fff

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

search_test.go

+66
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,72 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
806806
}
807807
})
808808

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

0 commit comments

Comments
 (0)