Skip to content

Commit 3cec04c

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

File tree

11 files changed

+99
-61
lines changed

11 files changed

+99
-61
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Go parameters
2-
GOCMD=go
2+
GOCMD=GO111MODULE=on go
3+
34
GOBUILD=$(GOCMD) build
45
GOINSTALL=$(GOCMD) install
56
GOCLEAN=$(GOCMD) clean

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: 11 additions & 12 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")
@@ -43,7 +42,7 @@ func init() {
4342

4443
sc := NewSchema(DefaultOptions).
4544
AddField(NewTextField("foo"))
46-
c.Drop()
45+
Flush(c)
4746
if err := c.CreateIndex(sc); err != nil {
4847
log.Fatal(err)
4948
}
@@ -144,7 +143,7 @@ func Init() {
144143
AddField(NewSortableNumericField("price")).
145144
AddField(NewTagField("categories"))
146145

147-
c.Drop()
146+
Flush(c)
148147
c.CreateIndex(sc)
149148

150149
AddValues(c)
@@ -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: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestClient_Get(t *testing.T) {
1313

1414
c := createClient("test-get")
15-
c.Drop()
15+
Flush(c)
1616

1717
sc := NewSchema(DefaultOptions).
1818
AddField(NewTextField("foo"))
@@ -72,9 +72,8 @@ func TestClient_Get(t *testing.T) {
7272
}
7373

7474
func TestClient_MultiGet(t *testing.T) {
75-
7675
c := createClient("test-get")
77-
c.Drop()
76+
Flush(c)
7877

7978
sc := NewSchema(DefaultOptions).
8079
AddField(NewTextField("foo"))
@@ -135,8 +134,7 @@ func TestClient_MultiGet(t *testing.T) {
135134

136135
func TestClient_DictAdd(t *testing.T) {
137136
c := createClient("test-get")
138-
_, err := c.pool.Get().Do("FLUSHALL")
139-
assert.Nil(t, err)
137+
Flush(c)
140138

141139
type fields struct {
142140
pool ConnPool
@@ -179,8 +177,7 @@ func TestClient_DictAdd(t *testing.T) {
179177
func TestClient_DictDel(t *testing.T) {
180178

181179
c := createClient("test-get")
182-
_, err := c.pool.Get().Do("FLUSHALL")
183-
assert.Nil(t, err)
180+
Flush(c)
184181

185182
terms := make([]string, 10)
186183
for i := 0; i < 10; i++ {
@@ -228,8 +225,7 @@ func TestClient_DictDel(t *testing.T) {
228225

229226
func TestClient_DictDump(t *testing.T) {
230227
c := createClient("test-get")
231-
_, err := c.pool.Get().Do("FLUSHALL")
232-
assert.Nil(t, err)
228+
Flush(c)
233229

234230
terms1 := make([]string, 10)
235231
for i := 0; i < 10; i++ {
@@ -279,7 +275,7 @@ func TestClient_AliasAdd(t *testing.T) {
279275
sc := NewSchema(DefaultOptions).
280276
AddField(NewTextField("foo")).
281277
AddField(NewTextField("bar"))
282-
c.Drop()
278+
Flush(c)
283279
assert.Nil(t, c.CreateIndex(sc))
284280

285281
docs := make([]Document, 100)
@@ -326,7 +322,7 @@ func TestClient_AliasDel(t *testing.T) {
326322
sc := NewSchema(DefaultOptions).
327323
AddField(NewTextField("foo")).
328324
AddField(NewTextField("bar"))
329-
c.Drop()
325+
Flush(c)
330326
err := c.CreateIndex(sc)
331327
assert.Nil(t, err)
332328

@@ -375,13 +371,13 @@ func TestClient_AliasUpdate(t *testing.T) {
375371
sc := NewSchema(DefaultOptions).
376372
AddField(NewTextField("foo")).
377373
AddField(NewTextField("bar"))
378-
c.Drop()
374+
Flush(c)
379375
err := c.CreateIndex(sc)
380376
assert.Nil(t, err)
381377

382378
docs := make([]Document, 100)
383379
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")
380+
docs[i] = NewDocument(fmt.Sprintf("doc-alias-update-%d", i), 1).Set("foo", "hello world").Set("bar", "hello world foo bar baz")
385381
}
386382
err = c.Index(docs...)
387383

@@ -418,7 +414,7 @@ func TestClient_AliasUpdate(t *testing.T) {
418414

419415
func TestClient_Config(t *testing.T) {
420416
c := createClient("testconfigindex")
421-
417+
Flush(c)
422418
ret, err := c.SetConfig("TIMEOUT", "100")
423419
assert.Nil(t, err)
424420
assert.Equal(t, "OK", ret)
@@ -453,7 +449,7 @@ func TestClient_GetTagVals(t *testing.T) {
453449
AddField(NewTextField("name")).
454450
AddField(NewTagField("tags"))
455451

456-
c.Drop()
452+
Flush(c)
457453
c.CreateIndex(sc)
458454

459455
docs := make([]Document, 1)
@@ -477,7 +473,7 @@ func TestClient_SynAdd(t *testing.T) {
477473
sc := NewSchema(DefaultOptions).
478474
AddField(NewTextField("name")).
479475
AddField(NewTextField("addr"))
480-
c.Drop()
476+
Flush(c)
481477
err := c.CreateIndex(sc)
482478
assert.Nil(t, err)
483479

@@ -495,7 +491,7 @@ func TestClient_SynDump(t *testing.T) {
495491
sc := NewSchema(DefaultOptions).
496492
AddField(NewTextField("name")).
497493
AddField(NewTextField("addr"))
498-
c.Drop()
494+
Flush(c)
499495
err := c.CreateIndex(sc)
500496
assert.Nil(t, err)
501497

@@ -519,24 +515,28 @@ func TestClient_AddHash(t *testing.T) {
519515
sc := NewSchema(DefaultOptions).
520516
AddField(NewTextField("name")).
521517
AddField(NewTextField("addr"))
522-
c.Drop()
518+
Flush(c)
523519
err := c.CreateIndex(sc)
524520
assert.Nil(t, err)
525521

526522
// Add a hash key
527523
c.pool.Get().Do("HMSET", "myhash", "field1", "Hello")
528524

529525
ret, err := c.AddHash("myhash", 1, "english", false)
530-
assert.Nil(t, err)
531-
assert.Equal(t, "OK", ret)
526+
// Given that FT.ADDHASH is no longer valid for search2+ we assert it's error
527+
if err != nil {
528+
assert.Equal(t, "ERR unknown command `FT.ADDHASH`, with args beginning with: `testAddHash`, `myhash`, `1`, `LANGUAGE`, `english`, ", err.Error())
529+
} else {
530+
assert.Equal(t, "OK", ret)
531+
}
532532
}
533533

534534
func TestClient_AddField(t *testing.T) {
535535
c := createClient("alterTest")
536536
sc := NewSchema(DefaultOptions).
537537
AddField(NewTextField("name")).
538538
AddField(NewTextField("addr"))
539-
c.Drop()
539+
Flush(c)
540540
err := c.CreateIndex(sc)
541541
assert.Nil(t, err)
542542
err = c.AddField(NewNumericField("age"))

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)