Skip to content

Commit c4c4a84

Browse files
committed
[add] Enable Go Modules. [fix] Fix tests for 2.0+ version
1 parent 236fe93 commit c4c4a84

File tree

12 files changed

+144
-69
lines changed

12 files changed

+144
-69
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
4646
build: # test with redisearch:edge
4747
docker:
48-
- image: circleci/golang:1.9
48+
- image: circleci/golang:1.12
4949
- image: redislabs/redisearch:edge
5050

5151
working_directory: /go/src/github.com/RediSearch/redisearch-go
@@ -57,7 +57,7 @@ jobs:
5757

5858
build_nightly: # test nightly with redisearch:edge
5959
docker:
60-
- image: circleci/golang:1.9
60+
- image: circleci/golang:1.12
6161
- image: redislabs/redisearch:edge
6262

6363
working_directory: /go/src/github.com/RediSearch/redisearch-go

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*
22
!/**/
33
!**/*.go
4+
!**/go.mod
5+
!**/go.sum
46
!.gitignore
57
!.circleci/config.yml
68
!/tests/*.bz2

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Go parameters
2-
GOCMD=go
2+
GOCMD=GO111MODULE=on go
3+
34
GOBUILD=$(GOCMD) build
45
GOINSTALL=$(GOCMD) install
56
GOCLEAN=$(GOCMD) clean
6-
GOTEST=$(GOCMD) test
7+
GOTEST=$(GOCMD) test -count=1
78
GOGET=$(GOCMD) get
89
GOMOD=$(GOCMD) mod
910

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/RediSearch/redisearch-go
2+
3+
go 1.12
4+
5+
require (
6+
github.com/gomodule/redigo v2.0.0+incompatible
7+
github.com/stretchr/testify v1.6.1
8+
)

go.sum

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
4+
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
5+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
9+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
10+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
11+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
13+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

redisearch/aggregate_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import (
55
"compress/bzip2"
66
"encoding/json"
77
"fmt"
8-
"github.com/gomodule/redigo/redis"
9-
"github.com/stretchr/testify/assert"
108
"log"
119
"math/rand"
1210
"os"
1311
"reflect"
1412
"strconv"
1513
"strings"
1614
"testing"
17-
)
1815

16+
"github.com/gomodule/redigo/redis"
17+
"github.com/stretchr/testify/assert"
18+
)
1919

2020
// Game struct which contains a Asin, a Description, a Title, a Price, and a list of categories
2121
// a type and a list of social links
@@ -30,7 +30,6 @@ type Game struct {
3030
Categories []string `json:"categories"`
3131
}
3232

33-
3433
func init() {
3534
/* load test data */
3635
value, exists := os.LookupEnv("REDISEARCH_RDB_LOADED")
@@ -50,7 +49,7 @@ func init() {
5049
ndocs := 10000
5150
docs := make([]Document, ndocs)
5251
for i := 0; i < ndocs; i++ {
53-
docs[i] = NewDocument(fmt.Sprintf("doc%d", i), 1).Set("foo", "hello world")
52+
docs[i] = NewDocument(fmt.Sprintf("bench.ft.aggregate.doc%d", i), 1).Set("foo", "hello world")
5453
}
5554

5655
if err := c.IndexOptions(DefaultIndexingOptions, docs...); err != nil {
@@ -317,9 +316,9 @@ func TestCursor_Serialize(t *testing.T) {
317316
fields fields
318317
want redis.Args
319318
}{
320-
{"TestCursor_Serialize_1", fields{1, 0, 0,}, redis.Args{"WITHCURSOR"}},
321-
{"TestCursor_Serialize_2_MAXIDLE", fields{1, 0, 30000,}, redis.Args{"WITHCURSOR", "MAXIDLE", 30000}},
322-
{"TestCursor_Serialize_3_COUNT_MAXIDLE", fields{1, 10, 30000,}, redis.Args{"WITHCURSOR", "COUNT", 10, "MAXIDLE", 30000}},
319+
{"TestCursor_Serialize_1", fields{1, 0, 0}, redis.Args{"WITHCURSOR"}},
320+
{"TestCursor_Serialize_2_MAXIDLE", fields{1, 0, 30000}, redis.Args{"WITHCURSOR", "MAXIDLE", 30000}},
321+
{"TestCursor_Serialize_3_COUNT_MAXIDLE", fields{1, 10, 30000}, redis.Args{"WITHCURSOR", "COUNT", 10, "MAXIDLE", 30000}},
323322
}
324323
for _, tt := range tests {
325324
t.Run(tt.name, func(t *testing.T) {
@@ -352,7 +351,7 @@ func TestGroupBy_AddFields(t *testing.T) {
352351
}{
353352
{"TestGroupBy_AddFields_1",
354353
fields{[]string{}, nil, nil},
355-
args{"a",},
354+
args{"a"},
356355
&GroupBy{[]string{"a"}, nil, nil},
357356
},
358357
}
@@ -651,8 +650,8 @@ func TestProcessAggResponse(t *testing.T) {
651650
args args
652651
want [][]string
653652
}{
654-
{"empty-reply", args{[]interface{}{}}, [][]string{},},
655-
{"1-element-reply", args{[]interface{}{[]interface{}{"userFullName", "berge, julius", "count", "2783"}}}, [][]string{{"userFullName", "berge, julius", "count", "2783"}},},
653+
{"empty-reply", args{[]interface{}{}}, [][]string{}},
654+
{"1-element-reply", args{[]interface{}{[]interface{}{"userFullName", "berge, julius", "count", "2783"}}}, [][]string{{"userFullName", "berge, julius", "count", "2783"}}},
656655
}
657656
for _, tt := range tests {
658657
t.Run(tt.name, func(t *testing.T) {

redisearch/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,4 @@ func (i *Client) AddHash(docId string, score float32, language string, replace b
613613
args = args.Add("REPLACE")
614614
}
615615
return redis.String(conn.Do("FT.ADDHASH", args...))
616-
}
616+
}

redisearch/client_test.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1218
func TestClient_Get(t *testing.T) {
1319

1420
c := createClient("test-get")
@@ -72,7 +78,6 @@ func TestClient_Get(t *testing.T) {
7278
}
7379

7480
func 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

136141
func 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

179185
func 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

229234
func 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

419423
func 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

534542
func TestClient_AddField(t *testing.T) {

redisearch/example_client_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"crypto/tls"
55
"crypto/x509"
66
"fmt"
7-
"github.com/RediSearch/redisearch-go/redisearch"
8-
"github.com/gomodule/redigo/redis"
97
"io/ioutil"
108
"log"
119
"os"
1210
"time"
11+
12+
"github.com/RediSearch/redisearch-go/redisearch"
13+
"github.com/gomodule/redigo/redis"
1314
)
1415

1516
// exemplifies the NewClient function
@@ -33,7 +34,7 @@ func ExampleNewClient() {
3334
}
3435

3536
// Create a document with an id and given score
36-
doc := redisearch.NewDocument("doc1", 1.0)
37+
doc := redisearch.NewDocument("ExampleNewClient:doc1", 1.0)
3738
doc.Set("title", "Hello world").
3839
Set("body", "foo bar").
3940
Set("date", time.Now().Unix())
@@ -49,7 +50,7 @@ func ExampleNewClient() {
4950
SetReturnFields("title"))
5051

5152
fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err)
52-
// Output: doc1 Hello world 1 <nil>
53+
// Output: ExampleNewClient:doc1 Hello world 1 <nil>
5354
}
5455

5556
// exemplifies the NewClientFromPool function
@@ -76,7 +77,7 @@ func ExampleNewClientFromPool() {
7677
}
7778

7879
// Create a document with an id and given score
79-
doc := redisearch.NewDocument("doc1", 1.0)
80+
doc := redisearch.NewDocument("ExampleNewClientFromPool:doc2", 1.0)
8081
doc.Set("title", "Hello world").
8182
Set("body", "foo bar").
8283
Set("date", time.Now().Unix())
@@ -92,7 +93,7 @@ func ExampleNewClientFromPool() {
9293
SetReturnFields("title"))
9394

9495
fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err)
95-
// Output: doc1 Hello world 1 <nil>
96+
// Output: ExampleNewClientFromPool:doc2 Hello world 1 <nil>
9697
}
9798

9899
//Example of how to establish an SSL connection from your app to the RedisAI Server
@@ -163,7 +164,7 @@ func ExampleNewClientFromPool_ssl() {
163164
}
164165

165166
// Create a document with an id and given score
166-
doc := redisearch.NewDocument("doc1", 1.0)
167+
doc := redisearch.NewDocument("ExampleNewClientFromPool_ssl:doc3", 1.0)
167168
doc.Set("title", "Hello world").
168169
Set("body", "foo bar").
169170
Set("date", time.Now().Unix())

redisearch/example_schema_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package redisearch_test
22

33
import (
44
"fmt"
5-
"github.com/RediSearch/redisearch-go/redisearch"
65
"log"
76
"time"
7+
8+
"github.com/RediSearch/redisearch-go/redisearch"
89
)
910

1011
// exemplifies the CreateIndex function with a temporary index specification
@@ -25,7 +26,7 @@ func ExampleCreateIndex_temporary() {
2526
}
2627

2728
// Create a document with an id and given score
28-
doc := redisearch.NewDocument("doc1", 1.0)
29+
doc := redisearch.NewDocument("ExampleCreateIndex_temporary:doc1", 1.0)
2930
doc.Set("title", "Hello world").
3031
Set("body", "foo bar").
3132
Set("date", time.Now().Unix())
@@ -46,6 +47,6 @@ func ExampleCreateIndex_temporary() {
4647
// Searching with limit and sorting
4748
_, err = c.Info()
4849
fmt.Println(err)
49-
// Output: doc1 Hello world 1 <nil>
50+
// Output: ExampleCreateIndex_temporary:doc1 Hello world 1 <nil>
5051
// Unknown Index name
5152
}

0 commit comments

Comments
 (0)