@@ -9,6 +9,12 @@ import (
99 "github.com/stretchr/testify/assert"
1010)
1111
12+ func flush (c * Client ) (err error ) {
13+ conn := c .pool .Get ()
14+ defer conn .Close ()
15+ return conn .Send ("FLUSHALL" )
16+ }
17+
1218func TestClient_Get (t * testing.T ) {
1319
1420 c := createClient ("test-get" )
@@ -72,7 +78,6 @@ func TestClient_Get(t *testing.T) {
7278}
7379
7480func TestClient_MultiGet (t * testing.T ) {
75-
7681 c := createClient ("test-get" )
7782 c .Drop ()
7883
@@ -134,9 +139,9 @@ func TestClient_MultiGet(t *testing.T) {
134139}
135140
136141func TestClient_DictAdd (t * testing.T ) {
137- c := createClient ("test-get " )
138- _ , err := c . pool . Get (). Do ( "FLUSHALL" )
139- assert . Nil ( t , err )
142+ c := createClient ("TestClient_DictAdd_Index " )
143+ // dict tests require flushall
144+ flush ( c )
140145
141146 type fields struct {
142147 pool ConnPool
@@ -155,8 +160,8 @@ func TestClient_DictAdd(t *testing.T) {
155160 }{
156161 {"empty-error" , fields {pool : c .pool , name : c .name }, args {"dict1" , []string {}}, 0 , true },
157162 {"1-term" , fields {pool : c .pool , name : c .name }, args {"dict1" , []string {"term1" }}, 1 , false },
158- {"2nd-time-term" , fields {pool : c .pool , name : c .name }, args {"dict1" , []string {"term1" }}, 0 , false },
159- {"multi-term" , fields {pool : c .pool , name : c .name }, args {"dict1 " , []string {"t1" , "t2" , "t3" , "t4" , "t5" }}, 5 , false },
163+ {"2nd-time-term" , fields {pool : c .pool , name : c .name }, args {"dict1" , []string {"term1" , "term1" }}, 1 , false },
164+ {"multi-term" , fields {pool : c .pool , name : c .name }, args {"dict-multi-term " , []string {"t1" , "t2" , "t3" , "t4" , "t5" }}, 5 , false },
160165 }
161166 for _ , tt := range tests {
162167 t .Run (tt .name , func (t * testing.T ) {
@@ -172,15 +177,15 @@ func TestClient_DictAdd(t *testing.T) {
172177 if gotNewTerms != tt .wantNewTerms {
173178 t .Errorf ("DictAdd() gotNewTerms = %v, want %v" , gotNewTerms , tt .wantNewTerms )
174179 }
180+ i .DictDel (tt .args .dictionaryName , tt .args .terms )
175181 })
176182 }
177183}
178184
179185func TestClient_DictDel (t * testing.T ) {
180186
181- c := createClient ("test-get" )
182- _ , err := c .pool .Get ().Do ("FLUSHALL" )
183- assert .Nil (t , err )
187+ c := createClient ("TestClient_DictDel_Index" )
188+ c .Drop ()
184189
185190 terms := make ([]string , 10 )
186191 for i := 0 ; i < 10 ; i ++ {
@@ -227,15 +232,14 @@ func TestClient_DictDel(t *testing.T) {
227232}
228233
229234func TestClient_DictDump (t * testing.T ) {
230- c := createClient ("test-get" )
231- _ , err := c .pool .Get ().Do ("FLUSHALL" )
232- assert .Nil (t , err )
235+ c := createClient ("TestClient_DictDump_Index" )
236+ c .Drop ()
233237
234238 terms1 := make ([]string , 10 )
235239 for i := 0 ; i < 10 ; i ++ {
236240 terms1 [i ] = fmt .Sprintf ("term%d" , i )
237241 }
238- c .DictAdd ("dict1" , terms1 )
242+ c .DictAdd ("dictdump- dict1" , terms1 )
239243
240244 type fields struct {
241245 pool ConnPool
@@ -252,7 +256,7 @@ func TestClient_DictDump(t *testing.T) {
252256 wantErr bool
253257 }{
254258 {"empty-error" , fields {pool : c .pool , name : c .name }, args {"dontexist" }, []string {}, true },
255- {"dict1" , fields {pool : c .pool , name : c .name }, args {"dict1" }, terms1 , false },
259+ {"dictdump- dict1" , fields {pool : c .pool , name : c .name }, args {"dictdump- dict1" }, terms1 , false },
256260 }
257261 for _ , tt := range tests {
258262 t .Run (tt .name , func (t * testing.T ) {
@@ -381,7 +385,7 @@ func TestClient_AliasUpdate(t *testing.T) {
381385
382386 docs := make ([]Document , 100 )
383387 for i := 0 ; i < 100 ; i ++ {
384- docs [i ] = NewDocument (fmt .Sprintf ("doc-alias-del -%d" , i ), 1 ).Set ("foo" , "hello world" ).Set ("bar" , "hello world foo bar baz" )
388+ docs [i ] = NewDocument (fmt .Sprintf ("doc-alias-update -%d" , i ), 1 ).Set ("foo" , "hello world" ).Set ("bar" , "hello world foo bar baz" )
385389 }
386390 err = c .Index (docs ... )
387391
@@ -418,7 +422,7 @@ func TestClient_AliasUpdate(t *testing.T) {
418422
419423func TestClient_Config (t * testing.T ) {
420424 c := createClient ("testconfigindex" )
421-
425+ c . Drop ()
422426 ret , err := c .SetConfig ("TIMEOUT" , "100" )
423427 assert .Nil (t , err )
424428 assert .Equal (t , "OK" , ret )
@@ -527,8 +531,12 @@ func TestClient_AddHash(t *testing.T) {
527531 c .pool .Get ().Do ("HMSET" , "myhash" , "field1" , "Hello" )
528532
529533 ret , err := c .AddHash ("myhash" , 1 , "english" , false )
530- assert .Nil (t , err )
531- assert .Equal (t , "OK" , ret )
534+ // Given that FT.ADDHASH is no longer valid for search2+ we assert it's error
535+ if err != nil {
536+ assert .Equal (t , "ERR unknown command `FT.ADDHASH`, with args beginning with: `testAddHash`, `myhash`, `1`, `LANGUAGE`, `english`, " , err .Error ())
537+ } else {
538+ assert .Equal (t , "OK" , ret )
539+ }
532540}
533541
534542func TestClient_AddField (t * testing.T ) {
0 commit comments