Skip to content

Commit cff6483

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

File tree

3 files changed

+68
-77
lines changed

3 files changed

+68
-77
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_commands_test.go

-77
This file was deleted.

Diff for: search_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package redis_test
33
import (
44
"context"
55
"fmt"
6+
"reflect"
67
"strconv"
78
"time"
89

@@ -806,6 +807,72 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
806807
}
807808
})
808809

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

0 commit comments

Comments
 (0)