Skip to content

Commit

Permalink
[add] Added go fmt check to circleci. Applied go fmt ./... to the ent…
Browse files Browse the repository at this point in the history
…ire project. (#75)
  • Loading branch information
filipecosta90 authored Jul 28, 2020
1 parent a48d16f commit 3260786
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- run:
name: Generate a root CA and a server certificate using redis helpers
command: |
git clone git://github.com/antirez/redis.git --branch 6.0.1
git clone git://github.com/antirez/redis.git --branch 6.0.5
cd redis
./utils/gen-test-certs.sh
cd ..
Expand Down Expand Up @@ -52,6 +52,7 @@ jobs:
steps:
- checkout
- run: make get
- run: make checkfmt
- run: make coverage
- run: bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN}

Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test -count=1
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt

.PHONY: all test coverage
all: test coverage examples
Expand All @@ -19,6 +20,15 @@ TLS_KEY ?= redis.key
TLS_CACERT ?= ca.crt
REDISEARCH_TEST_HOST ?= 127.0.0.1:6379

checkfmt:
@echo 'Checking gofmt';\
bash -c "diff -u <(echo -n) <(gofmt -d .)";\
EXIT_CODE=$$?;\
if [ "$$EXIT_CODE" -ne 0 ]; then \
echo '$@: Go files must be formatted with gofmt'; \
fi && \
exit $$EXIT_CODE

examples: get
@echo " "
@echo "Building the examples..."
Expand All @@ -32,6 +42,7 @@ examples: get
--host $(REDISEARCH_TEST_HOST)

test: get
$(GOFMT) ./...
$(GOTEST) -race -covermode=atomic ./...

coverage: get test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err)
// Output: doc1 Hello world 1 <nil>

time.Sleep(15*time.Second)
time.Sleep(15 * time.Second)
// Searching with limit and sorting
_, err = c.Info()
fmt.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion redisearch/autocomplete.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package redisearch

import (
"strconv"
"github.com/gomodule/redigo/redis"
"strconv"
)

// Autocompleter implements a redisearch auto-completer API
Expand Down
10 changes: 5 additions & 5 deletions redisearch/autocomplete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func TestAutocompleter_Serialize(t *testing.T) {
want redis.Args
want1 int
}{
{"default options", fields{"key1"}, args{"ab", DefaultSuggestOptions,}, redis.Args{"key1", "ab", "MAX", 5}, 1},
{"FUZZY", fields{"key1"}, args{"ab", fuzzy,}, redis.Args{"key1", "ab", "MAX", 5, "FUZZY"}, 1},
{"WITHSCORES", fields{"key1"}, args{"ab", withscores,}, redis.Args{"key1", "ab", "MAX", 5, "WITHSCORES"}, 2},
{"WITHPAYLOADS", fields{"key1"}, args{"ab", withpayloads,}, redis.Args{"key1", "ab", "MAX", 5, "WITHPAYLOADS"}, 2},
{"all", fields{"key1"}, args{"ab", all,}, redis.Args{"key1", "ab", "MAX", 5, "FUZZY", "WITHSCORES", "WITHPAYLOADS"}, 3},
{"default options", fields{"key1"}, args{"ab", DefaultSuggestOptions}, redis.Args{"key1", "ab", "MAX", 5}, 1},
{"FUZZY", fields{"key1"}, args{"ab", fuzzy}, redis.Args{"key1", "ab", "MAX", 5, "FUZZY"}, 1},
{"WITHSCORES", fields{"key1"}, args{"ab", withscores}, redis.Args{"key1", "ab", "MAX", 5, "WITHSCORES"}, 2},
{"WITHPAYLOADS", fields{"key1"}, args{"ab", withpayloads}, redis.Args{"key1", "ab", "MAX", 5, "WITHPAYLOADS"}, 2},
{"all", fields{"key1"}, args{"ab", all}, redis.Args{"key1", "ab", "MAX", 5, "FUZZY", "WITHSCORES", "WITHPAYLOADS"}, 3},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions redisearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package redisearch

import (
"errors"
"github.com/gomodule/redigo/redis"
"log"
"reflect"
"strconv"
"strings"
"github.com/gomodule/redigo/redis"
)

// Client is an interface to redisearch's redis commands
Expand Down Expand Up @@ -65,7 +65,7 @@ func (i *Client) CreateIndex(s *Schema) (err error) {
func (i *Client) AddField(f Field) error {
args := redis.Args{i.name}
args = append(args, "SCHEMA", "ADD")
args,err := serializeField(f,args)
args, err := serializeField(f, args)
if err != nil {
return err
}
Expand Down Expand Up @@ -613,4 +613,4 @@ func (i *Client) AddHash(docId string, score float32, language string, replace b
args = args.Add("REPLACE")
}
return redis.String(conn.Do("FT.ADDHASH", args...))
}
}
6 changes: 3 additions & 3 deletions redisearch/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestClient_DictAdd(t *testing.T) {
}{
{"empty-error", fields{pool: c.pool, name: c.name}, args{"dict1", []string{}}, 0, true},
{"1-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"}}, 1, false},
{"2nd-time-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1","term1"}}, 1, false},
{"2nd-time-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1", "term1"}}, 1, false},
{"multi-term", fields{pool: c.pool, name: c.name}, args{"dict-multi-term", []string{"t1", "t2", "t3", "t4", "t5"}}, 5, false},
}
for _, tt := range tests {
Expand Down Expand Up @@ -551,7 +551,7 @@ func TestClient_AddField(t *testing.T) {
assert.Nil(t, err)
err = c.AddField(NewNumericField("age"))
assert.Nil(t, err)
err = c.Index(NewDocument("doc-n1",1.0).Set("age",15 ))
err = c.Index(NewDocument("doc-n1", 1.0).Set("age", 15))
assert.Nil(t, err)
}

Expand Down Expand Up @@ -582,4 +582,4 @@ func TestClient_CreateIndex(t *testing.T) {
}
})
}
}
}
18 changes: 8 additions & 10 deletions redisearch/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ type Document struct {
Properties map[string]interface{}
}


// IndexingOptions represent the options for indexing a single document
type IndexingOptions struct {

// If set, we use a stemmer for the supplied language during indexing. If set to "", we Default to English.
Language string
Language string

// If set to true, we will not save the actual document in the database and only index it.
NoSave bool
NoSave bool

// If set, we will do an UPSERT style insertion - and delete an older version of the document if it exists.
Replace bool
Replace bool

// (only applicable with Replace): If set, you do not have to specify all fields for reindexing.
Partial bool
Partial bool

// Applicable only in conjunction with Replace and optionally Partial
// Update the document only if a boolean expression applies to the document before the update
Expand Down Expand Up @@ -79,9 +78,9 @@ func (d Document) Set(name string, value interface{}) Document {
// to signify an actual backslash, so the actual text in redis-cli for example, will be entered as `hello\\-world`.
// Underscores (`_`) are not used as separators in either document or query.
// So the text `hello_world` will remain as is after tokenization.
func EscapeTextFileString(value string) (string) {
func EscapeTextFileString(value string) string {
for _, char := range field_tokenization {
value = strings.Replace(value, string(char), ("\\"+string(char)), -1 )
value = strings.Replace(value, string(char), ("\\" + string(char)), -1)
}
return value
}
Expand Down Expand Up @@ -111,9 +110,8 @@ func loadDocument(arr []interface{}, idIdx, scoreIdx, payloadIdx, fieldsIdx int)
return doc, nil
}


// SetPayload Sets the document payload
func (d *Document) loadFields(lst []interface{}) *Document{
func (d *Document) loadFields(lst []interface{}) *Document {
for i := 0; i < len(lst); i += 2 {
var prop string
switch lst[i].(type) {
Expand All @@ -130,7 +128,7 @@ func (d *Document) loadFields(lst []interface{}) *Document{
default:
val = v
}
*d = d.Set(prop,val)
*d = d.Set(prop, val)
}
return d
}
Expand Down
22 changes: 11 additions & 11 deletions redisearch/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func TestEscapeTextFileString(t *testing.T) {
want string
}{
{
"url", args{"https://en.wikipedia.org/wiki",}, "https\\://en\\.wikipedia\\.org/wiki",
"url", args{"https://en.wikipedia.org/wiki"}, "https\\://en\\.wikipedia\\.org/wiki",
},
{
"hello_world", args{"hello_world",}, "hello_world",
"hello_world", args{"hello_world"}, "hello_world",
},
}
for _, tt := range tests {
Expand All @@ -43,13 +43,13 @@ func TestDocument_EstimateSize(t *testing.T) {
wantSz int
}{
{
"only-id", fields{"doc1", 1.0, []byte{}, map[string]interface{}{},}, len("doc1"),
"only-id", fields{"doc1", 1.0, []byte{}, map[string]interface{}{}}, len("doc1"),
},
{
"id-payload", fields{"doc1", 1.0, []byte("payload"), map[string]interface{}{},}, len("doc1") + len([]byte("payload")),
"id-payload", fields{"doc1", 1.0, []byte("payload"), map[string]interface{}{}}, len("doc1") + len([]byte("payload")),
},
{
"id-payload-fields", fields{"doc1", 1.0, []byte("payload"), map[string]interface{}{"text1": []byte("text1")},}, len("doc1") + len([]byte("payload")) + 2*len([]byte("text1")),
"id-payload-fields", fields{"doc1", 1.0, []byte("payload"), map[string]interface{}{"text1": []byte("text1")}}, len("doc1") + len([]byte("payload")) + 2*len([]byte("text1")),
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -78,14 +78,14 @@ func TestDocument_SetPayload(t *testing.T) {
payload []byte
}
tests := []struct {
name string
fields fields
args args
name string
fields fields
args args
wantPayload []byte
}{
{"empty-payload", fields{"doc1", 1.0, []byte{}, map[string]interface{}{},}, args{[]byte{}}, []byte{}},
{"simple-set", fields{"doc1", 1.0, []byte{}, map[string]interface{}{},}, args{[]byte("payload")},[]byte("payload")},
{"set-with-previous-payload", fields{"doc1", 1.0, []byte("previous_payload"), map[string]interface{}{},}, args{[]byte("payload")},[]byte("payload")},
{"empty-payload", fields{"doc1", 1.0, []byte{}, map[string]interface{}{}}, args{[]byte{}}, []byte{}},
{"simple-set", fields{"doc1", 1.0, []byte{}, map[string]interface{}{}}, args{[]byte("payload")}, []byte("payload")},
{"set-with-previous-payload", fields{"doc1", 1.0, []byte("previous_payload"), map[string]interface{}{}}, args{[]byte("payload")}, []byte("payload")},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions redisearch/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func TestNewMultiHostPool(t *testing.T) {
name string
args args
}{
{"multi-host single address", args{[]string{host,},},},
{"multi-host several addresses", args{[]string{host, host,},},},
{"multi-host single address", args{[]string{host}}},
{"multi-host several addresses", args{[]string{host, host}}},
}
if password == "" {
for _, tt := range tests {
Expand All @@ -37,14 +37,14 @@ func TestMultiHostPool_Close(t *testing.T) {
host, password := getTestConnectionDetails()
// Test a simple flow
if password == "" {
oneMulti := NewMultiHostPool([]string{host,})
oneMulti := NewMultiHostPool([]string{host})
conn := oneMulti.Get()
assert.NotNil(t, conn)
err := oneMulti.Close()
assert.Nil(t, err)
err = oneMulti.Close()
assert.NotNil(t, conn)
severalMulti := NewMultiHostPool([]string{host, host,})
severalMulti := NewMultiHostPool([]string{host, host})
connMulti := severalMulti.Get()
assert.NotNil(t, connMulti)
err = severalMulti.Close()
Expand All @@ -70,9 +70,9 @@ func TestMultiHostPool_Close(t *testing.T) {
fields fields
wantErr bool
}{
{"empty", fields{map[string]*redis.Pool{}, []string{}}, false,},
{"normal", fields{map[string]*redis.Pool{"hostpool1": pool1}, []string{"hostpool1"}}, false,},
{"pool3-already-close", fields{map[string]*redis.Pool{"hostpool2": pool2, "hostpool3": pool3, "hostpool4": pool4,}, []string{"hostpool2", "hostpool3", "hostpool3"}}, false,},
{"empty", fields{map[string]*redis.Pool{}, []string{}}, false},
{"normal", fields{map[string]*redis.Pool{"hostpool1": pool1}, []string{"hostpool1"}}, false},
{"pool3-already-close", fields{map[string]*redis.Pool{"hostpool2": pool2, "hostpool3": pool3, "hostpool4": pool4}, []string{"hostpool2", "hostpool3", "hostpool3"}}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions redisearch/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ func Test_appendNumArgs(t *testing.T) {
args args
want redis.Args
}{
{"1 arg", args{ 1.0,false,redis.Args{} }, redis.Args{1.0} },
{"1 excluded arg", args{ 1.0,true,redis.Args{} }, redis.Args{"(",1.0} },
{"+inf", args{ math.Inf(1),false,redis.Args{} }, redis.Args{"+inf"} },
{"+inf", args{ math.Inf(-1),false,redis.Args{} }, redis.Args{"-inf"} },
{"1 arg", args{1.0, false, redis.Args{}}, redis.Args{1.0}},
{"1 excluded arg", args{1.0, true, redis.Args{}}, redis.Args{"(", 1.0}},
{"+inf", args{math.Inf(1), false, redis.Args{}}, redis.Args{"+inf"}},
{"+inf", args{math.Inf(-1), false, redis.Args{}}, redis.Args{"-inf"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion redisearch/redisearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func createClient(indexName string) *Client {
}
}


func createAutocompleter(dictName string) *Autocompleter {
host, password := getTestConnectionDetails()
if password != "" {
Expand Down
2 changes: 1 addition & 1 deletion redisearch/reducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewReducer(name GroupByReducers, args []string) *Reducer {
}

// NewReducer creates a new Reducer object
func NewReducerAlias(name GroupByReducers, args []string, alias string ) *Reducer {
func NewReducerAlias(name GroupByReducers, args []string, alias string) *Reducer {
return &Reducer{
Name: name,
Alias: alias,
Expand Down
2 changes: 1 addition & 1 deletion redisearch/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func SerializeSchema(s *Schema, args redis.Args) (argsOut redis.Args, err error)
argsOut = append(argsOut, "NOOFFSETS")
}
if s.Options.Temporary {
argsOut = append(argsOut, "TEMPORARY",s.Options.TemporaryPeriod)
argsOut = append(argsOut, "TEMPORARY", s.Options.TemporaryPeriod)
}
if s.Options.NoFieldFlags {
argsOut = append(argsOut, "NOFIELDS")
Expand Down
2 changes: 1 addition & 1 deletion redisearch/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestSerializeSchema(t *testing.T) {

{"default-args", args{NewSchema(DefaultOptions), redis.Args{}}, redis.Args{"SCHEMA"}, false},
{"default-args-with-different-constructor", args{NewSchema(*NewOptions()), redis.Args{}}, redis.Args{"SCHEMA"}, false},
{"temporary", args{NewSchema(*NewOptions().SetTemporaryPeriod(60)), redis.Args{}}, redis.Args{"TEMPORARY",60,"SCHEMA"}, false},
{"temporary", args{NewSchema(*NewOptions().SetTemporaryPeriod(60)), redis.Args{}}, redis.Args{"TEMPORARY", 60, "SCHEMA"}, false},
{"no-frequencies", args{NewSchema(Options{NoFrequencies: true}), redis.Args{}}, redis.Args{"NOFREQS", "SCHEMA"}, false},
{"no-fields", args{NewSchema(Options{NoFieldFlags: true}), redis.Args{}}, redis.Args{"NOFIELDS", "SCHEMA"}, false},
{"custom-stopwords", args{NewSchema(Options{Stopwords: []string{"custom"}}), redis.Args{}}, redis.Args{"STOPWORDS", 1, "custom", "SCHEMA"}, false},
Expand Down

0 comments on commit 3260786

Please sign in to comment.