Skip to content

Commit

Permalink
feat: move ftaggregate tests to search_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
tomfrombayesians committed Feb 25, 2025
1 parent ae07968 commit cff6483
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ testdata/*
*.tar.gz
*.dic
redis8tests.sh
.vscode
77 changes: 0 additions & 77 deletions search_commands_test.go

This file was deleted.

67 changes: 67 additions & 0 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redis_test
import (
"context"
"fmt"
"reflect"
"strconv"
"time"

Expand Down Expand Up @@ -806,6 +807,72 @@ 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 _, a := range args {
if reflect.DeepEqual(a, 500) {
found = true
break
}
}
Expect(found).To(BeTrue())
})

It("should FTSearch SkipInitialScan", Label("search", "ftsearch"), func() {
client.HSet(ctx, "doc1", "foo", "bar")

Expand Down

0 comments on commit cff6483

Please sign in to comment.