From bad0a6650a09be66a76472848df4645629e7d177 Mon Sep 17 00:00:00 2001 From: vr009 Date: Fri, 8 Apr 2022 02:10:34 +0300 Subject: [PATCH] code health: fix all places highlighted by linter Relates to #142 --- client_tools.go | 84 +++++++++++++++------- connection.go | 24 +++---- deadline_io.go | 8 ++- example_test.go | 8 +-- request.go | 175 +++++++++++++++++++++++++++++++--------------- response.go | 8 ++- schema.go | 4 +- tarantool_test.go | 56 ++++++++------- 8 files changed, 240 insertions(+), 127 deletions(-) diff --git a/client_tools.go b/client_tools.go index ed76ea258..da9f712cc 100644 --- a/client_tools.go +++ b/client_tools.go @@ -10,9 +10,13 @@ type IntKey struct { I int } -func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error { - enc.EncodeSliceLen(1) - enc.EncodeInt(k.I) +func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeSliceLen(1); err != nil { + return + } + if err = enc.EncodeInt(k.I); err != nil { + return + } return nil } @@ -22,9 +26,13 @@ type UintKey struct { I uint } -func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error { - enc.EncodeSliceLen(1) - enc.EncodeUint(k.I) +func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeSliceLen(1); err != nil { + return + } + if err = enc.EncodeUint(k.I); err != nil { + return + } return nil } @@ -34,9 +42,13 @@ type StringKey struct { S string } -func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error { - enc.EncodeSliceLen(1) - enc.EncodeString(k.S) +func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeSliceLen(1); err != nil { + return + } + if err = enc.EncodeString(k.S); err != nil { + return + } return nil } @@ -46,10 +58,16 @@ type IntIntKey struct { I1, I2 int } -func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error { - enc.EncodeSliceLen(2) - enc.EncodeInt(k.I1) - enc.EncodeInt(k.I2) +func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeSliceLen(2); err != nil { + return + } + if err = enc.EncodeInt(k.I1); err != nil { + return + } + if err = enc.EncodeInt(k.I2); err != nil { + return + } return nil } @@ -60,10 +78,16 @@ type Op struct { Arg interface{} } -func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error { - enc.EncodeSliceLen(3) - enc.EncodeString(o.Op) - enc.EncodeInt(o.Field) +func (o Op) EncodeMsgpack(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeSliceLen(3); err != nil { + return + } + if err = enc.EncodeString(o.Op); err != nil { + return + } + if err = enc.EncodeInt(o.Field); err != nil { + return + } return enc.Encode(o.Arg) } @@ -75,12 +99,24 @@ type OpSplice struct { Replace string } -func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error { - enc.EncodeSliceLen(5) - enc.EncodeString(o.Op) - enc.EncodeInt(o.Field) - enc.EncodeInt(o.Pos) - enc.EncodeInt(o.Len) - enc.EncodeString(o.Replace) +func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeSliceLen(5); err != nil { + return + } + if err = enc.EncodeString(o.Op); err != nil { + return + } + if err = enc.EncodeInt(o.Field); err != nil { + return + } + if err = enc.EncodeInt(o.Pos); err != nil { + return + } + if err = enc.EncodeInt(o.Len); err != nil { + return + } + if err = enc.EncodeString(o.Replace); err != nil { + return + } return nil } diff --git a/connection.go b/connection.go index 102b58d50..2c6eab6bd 100644 --- a/connection.go +++ b/connection.go @@ -145,7 +145,7 @@ type connShard struct { bufmut sync.Mutex buf smallWBuf enc *msgpack.Encoder - _pad [16]uint64 + _pad [16]uint64 //nolint } // Greeting is a message sent by tarantool on connect. @@ -280,7 +280,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) { conn.mutex.Lock() defer conn.mutex.Unlock() if err := conn.createConnection(true); err != nil { - conn.closeConnection(err, true) + _ = conn.closeConnection(err, true) } }(conn) err = nil @@ -297,7 +297,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) { if err = conn.loadSchema(); err != nil { conn.mutex.Lock() defer conn.mutex.Unlock() - conn.closeConnection(err, true) + _ = conn.closeConnection(err, true) return nil, err } } @@ -494,7 +494,7 @@ func (conn *Connection) createConnection(reconnect bool) (err error) { conn.notify(ReconnectFailed) reconnects++ conn.mutex.Unlock() - time.Sleep(now.Add(conn.opts.Reconnect).Sub(time.Now())) + time.Sleep(time.Until(now.Add(conn.opts.Reconnect))) conn.mutex.Lock() } if conn.state == connClosed { @@ -542,13 +542,13 @@ func (conn *Connection) reconnect(neterr error, c net.Conn) { defer conn.mutex.Unlock() if conn.opts.Reconnect > 0 { if c == conn.c { - conn.closeConnection(neterr, false) + _ = conn.closeConnection(neterr, false) if err := conn.createConnection(true); err != nil { - conn.closeConnection(err, true) + _ = conn.closeConnection(err, true) } } } else { - conn.closeConnection(neterr, true) + _ = conn.closeConnection(neterr, true) } } @@ -579,7 +579,7 @@ func (conn *Connection) pinger() { return case <-t.C: } - conn.Ping() + _, _ = conn.Ping() } } @@ -687,7 +687,7 @@ func (conn *Connection) newFuture(requestCode int32) (fut *Future) { *pair.last = fut pair.last = &fut.next if conn.opts.Timeout > 0 { - fut.timeout = time.Now().Sub(epoch) + conn.opts.Timeout + fut.timeout = time.Until(epoch) + conn.opts.Timeout } shard.rmut.Unlock() if conn.rlimit != nil && conn.opts.RLimitAction == RLimitWait { @@ -795,9 +795,9 @@ func (conn *Connection) timeouts() { return case <-t.C: } - minNext := time.Now().Sub(epoch) + timeout + minNext := time.Until(epoch) + timeout for i := range conn.shard { - nowepoch = time.Now().Sub(epoch) + nowepoch = time.Until(epoch) shard := &conn.shard[i] for pos := range shard.requests { shard.rmut.Lock() @@ -824,7 +824,7 @@ func (conn *Connection) timeouts() { shard.rmut.Unlock() } } - nowepoch = time.Now().Sub(epoch) + nowepoch = time.Until(epoch) if nowepoch+time.Microsecond < minNext { t.Reset(minNext - nowepoch) } else { diff --git a/deadline_io.go b/deadline_io.go index 3bda73ac8..b90b97396 100644 --- a/deadline_io.go +++ b/deadline_io.go @@ -12,7 +12,9 @@ type DeadlineIO struct { func (d *DeadlineIO) Write(b []byte) (n int, err error) { if d.to > 0 { - d.c.SetWriteDeadline(time.Now().Add(d.to)) + if err = d.c.SetWriteDeadline(time.Now().Add(d.to)); err != nil { + return + } } n, err = d.c.Write(b) return @@ -20,7 +22,9 @@ func (d *DeadlineIO) Write(b []byte) (n int, err error) { func (d *DeadlineIO) Read(b []byte) (n int, err error) { if d.to > 0 { - d.c.SetReadDeadline(time.Now().Add(d.to)) + if err = d.c.SetReadDeadline(time.Now().Add(d.to)); err != nil { + return + } } n, err = d.c.Read(b) return diff --git a/example_test.go b/example_test.go index 7b81bc28e..f75999171 100644 --- a/example_test.go +++ b/example_test.go @@ -10,7 +10,7 @@ import ( type Tuple struct { /* instruct msgpack to pack this struct as array, * so no custom packer is needed */ - _msgpack struct{} `msgpack:",asArray"` + _msgpack struct{} `msgpack:",asArray"` //nolint Id uint Msg string Name string @@ -99,7 +99,7 @@ func Example() { } client, err := tarantool.Connect(server, opts) if err != nil { - fmt.Errorf("Failed to connect: %s", err.Error()) + fmt.Printf("Failed to connect: %s", err.Error()) return } @@ -109,8 +109,8 @@ func Example() { fmt.Println("Ping Error", err) // delete tuple for cleaning - client.Delete(spaceNo, indexNo, []interface{}{uint(10)}) - client.Delete(spaceNo, indexNo, []interface{}{uint(11)}) + _, _ = client.Delete(spaceNo, indexNo, []interface{}{uint(10)}) + _, _ = client.Delete(spaceNo, indexNo, []interface{}{uint(11)}) // insert new tuple { 10, 1 } resp, err = client.Insert(spaceNo, []interface{}{uint(10), "test", "one"}) diff --git a/request.go b/request.go index ae42eb440..0a3441600 100644 --- a/request.go +++ b/request.go @@ -21,31 +21,47 @@ type Future struct { // Ping sends empty request to Tarantool to check connection. func (conn *Connection) Ping() (resp *Response, err error) { future := conn.newFuture(PingRequest) - return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(0); return nil }).Get() + return future.send(conn, func(enc *msgpack.Encoder) error { return enc.EncodeMapLen(0) }).Get() } -func (req *Future) fillSearch(enc *msgpack.Encoder, spaceNo, indexNo uint32, key interface{}) error { - enc.EncodeUint64(KeySpaceNo) - enc.EncodeUint64(uint64(spaceNo)) - enc.EncodeUint64(KeyIndexNo) - enc.EncodeUint64(uint64(indexNo)) - enc.EncodeUint64(KeyKey) +func (req *Future) fillSearch(enc *msgpack.Encoder, spaceNo, indexNo uint32, key interface{}) (err error) { + if err = enc.EncodeUint64(KeySpaceNo); err != nil { + return + } + if err = enc.EncodeUint64(uint64(spaceNo)); err != nil { + return + } + if err = enc.EncodeUint64(KeyIndexNo); err != nil { + return + } + if err = enc.EncodeUint64(uint64(indexNo)); err != nil { + return + } + if err = enc.EncodeUint64(KeyKey); err != nil { + return + } return enc.Encode(key) } func (req *Future) fillIterator(enc *msgpack.Encoder, offset, limit, iterator uint32) { - enc.EncodeUint64(KeyIterator) - enc.EncodeUint64(uint64(iterator)) - enc.EncodeUint64(KeyOffset) - enc.EncodeUint64(uint64(offset)) - enc.EncodeUint64(KeyLimit) - enc.EncodeUint64(uint64(limit)) -} - -func (req *Future) fillInsert(enc *msgpack.Encoder, spaceNo uint32, tuple interface{}) error { - enc.EncodeUint64(KeySpaceNo) - enc.EncodeUint64(uint64(spaceNo)) - enc.EncodeUint64(KeyTuple) + _ = enc.EncodeUint64(KeyIterator) + _ = enc.EncodeUint64(uint64(iterator)) + _ = enc.EncodeUint64(KeyOffset) + _ = enc.EncodeUint64(uint64(offset)) + _ = enc.EncodeUint64(KeyLimit) + _ = enc.EncodeUint64(uint64(limit)) +} + +func (req *Future) fillInsert(enc *msgpack.Encoder, spaceNo uint32, tuple interface{}) (err error) { + if err = enc.EncodeUint64(KeySpaceNo); err != nil { + return + } + if err = enc.EncodeUint64(uint64(spaceNo)); err != nil { + return + } + if err = enc.EncodeUint64(KeyTuple); err != nil { + return + } return enc.Encode(tuple) } @@ -219,8 +235,10 @@ func (conn *Connection) SelectAsync(space, index interface{}, offset, limit, ite if err != nil { return future.fail(conn, err) } - return future.send(conn, func(enc *msgpack.Encoder) error { - enc.EncodeMapLen(6) + return future.send(conn, func(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeMapLen(6); err != nil { + return + } future.fillIterator(enc, offset, limit, iterator) return future.fillSearch(enc, spaceNo, indexNo, key) }) @@ -234,8 +252,10 @@ func (conn *Connection) InsertAsync(space interface{}, tuple interface{}) *Futur if err != nil { return future.fail(conn, err) } - return future.send(conn, func(enc *msgpack.Encoder) error { - enc.EncodeMapLen(2) + return future.send(conn, func(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeMapLen(2); err != nil { + return + } return future.fillInsert(enc, spaceNo, tuple) }) } @@ -248,8 +268,10 @@ func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Futu if err != nil { return future.fail(conn, err) } - return future.send(conn, func(enc *msgpack.Encoder) error { - enc.EncodeMapLen(2) + return future.send(conn, func(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeMapLen(2); err != nil { + return + } return future.fillInsert(enc, spaceNo, tuple) }) } @@ -262,8 +284,10 @@ func (conn *Connection) DeleteAsync(space, index interface{}, key interface{}) * if err != nil { return future.fail(conn, err) } - return future.send(conn, func(enc *msgpack.Encoder) error { - enc.EncodeMapLen(3) + return future.send(conn, func(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeMapLen(3); err != nil { + return + } return future.fillSearch(enc, spaceNo, indexNo, key) }) } @@ -276,12 +300,16 @@ func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface if err != nil { return future.fail(conn, err) } - return future.send(conn, func(enc *msgpack.Encoder) error { - enc.EncodeMapLen(4) - if err := future.fillSearch(enc, spaceNo, indexNo, key); err != nil { + return future.send(conn, func(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeMapLen(4); err != nil { + return + } + if err = future.fillSearch(enc, spaceNo, indexNo, key); err != nil { return err } - enc.EncodeUint64(KeyTuple) + if err = enc.EncodeUint64(KeyTuple); err != nil { + return + } return enc.Encode(ops) }) } @@ -294,15 +322,25 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in if err != nil { return future.fail(conn, err) } - return future.send(conn, func(enc *msgpack.Encoder) error { - enc.EncodeMapLen(3) - enc.EncodeUint64(KeySpaceNo) - enc.EncodeUint64(uint64(spaceNo)) - enc.EncodeUint64(KeyTuple) - if err := enc.Encode(tuple); err != nil { - return err + return future.send(conn, func(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeMapLen(3); err != nil { + return + } + if err = enc.EncodeUint64(KeySpaceNo); err != nil { + return + } + if err = enc.EncodeUint64(uint64(spaceNo)); err != nil { + return + } + if err = enc.EncodeUint64(KeyTuple); err != nil { + return + } + if err = enc.Encode(tuple); err != nil { + return + } + if err = enc.EncodeUint64(KeyDefTuple); err != nil { + return } - enc.EncodeUint64(KeyDefTuple) return enc.Encode(ops) }) } @@ -311,11 +349,19 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in // It uses request code for tarantool 1.6, so future's result is always array of arrays func (conn *Connection) CallAsync(functionName string, args interface{}) *Future { future := conn.newFuture(CallRequest) - return future.send(conn, func(enc *msgpack.Encoder) error { - enc.EncodeMapLen(2) - enc.EncodeUint64(KeyFunctionName) - enc.EncodeString(functionName) - enc.EncodeUint64(KeyTuple) + return future.send(conn, func(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeMapLen(2); err != nil { + return + } + if err = enc.EncodeUint64(KeyFunctionName); err != nil { + return + } + if err = enc.EncodeString(functionName); err != nil { + return + } + if err = enc.EncodeUint64(KeyTuple); err != nil { + return + } return enc.Encode(args) }) } @@ -325,11 +371,19 @@ func (conn *Connection) CallAsync(functionName string, args interface{}) *Future // (though, keep in mind, result is always array) func (conn *Connection) Call17Async(functionName string, args interface{}) *Future { future := conn.newFuture(Call17Request) - return future.send(conn, func(enc *msgpack.Encoder) error { - enc.EncodeMapLen(2) - enc.EncodeUint64(KeyFunctionName) - enc.EncodeString(functionName) - enc.EncodeUint64(KeyTuple) + return future.send(conn, func(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeMapLen(2); err != nil { + return + } + if err = enc.EncodeUint64(KeyFunctionName); err != nil { + return + } + if err = enc.EncodeString(functionName); err != nil { + return + } + if err = enc.EncodeUint64(KeyTuple); err != nil { + return + } return enc.Encode(args) }) } @@ -337,11 +391,19 @@ func (conn *Connection) Call17Async(functionName string, args interface{}) *Futu // EvalAsync sends a lua expression for evaluation and returns Future. func (conn *Connection) EvalAsync(expr string, args interface{}) *Future { future := conn.newFuture(EvalRequest) - return future.send(conn, func(enc *msgpack.Encoder) error { - enc.EncodeMapLen(2) - enc.EncodeUint64(KeyExpression) - enc.EncodeString(expr) - enc.EncodeUint64(KeyTuple) + return future.send(conn, func(enc *msgpack.Encoder) (err error) { + if err = enc.EncodeMapLen(2); err != nil { + return + } + if err = enc.EncodeUint64(KeyExpression); err != nil { + return + } + if err = enc.EncodeString(expr); err != nil { + return + } + if err = enc.EncodeUint64(KeyTuple); err != nil { + return + } return enc.Encode(args) }) } @@ -353,7 +415,7 @@ func (conn *Connection) EvalAsync(expr string, args interface{}) *Future { func (fut *Future) pack(h *smallWBuf, enc *msgpack.Encoder, body func(*msgpack.Encoder) error) (err error) { rid := fut.requestId hl := h.Len() - h.Write([]byte{ + _, err = h.Write([]byte{ 0xce, 0, 0, 0, 0, // length 0x82, // 2 element map KeyCode, byte(fut.requestCode), // request code @@ -361,6 +423,9 @@ func (fut *Future) pack(h *smallWBuf, enc *msgpack.Encoder, body func(*msgpack.E byte(rid >> 24), byte(rid >> 16), byte(rid >> 8), byte(rid), }) + if err != nil { + return + } if err = body(enc); err != nil { return diff --git a/response.go b/response.go index 6363a4fe4..6341142cd 100644 --- a/response.go +++ b/response.go @@ -15,7 +15,7 @@ type Response struct { buf smallBuf } -func (resp *Response) fill(b []byte) { +func (resp *Response) fill(b []byte) { //nolint resp.buf.b = b } @@ -27,13 +27,15 @@ func (resp *Response) smallInt(d *msgpack.Decoder) (i int, err error) { if b <= 127 { return int(b), nil } - resp.buf.UnreadByte() + _ = resp.buf.UnreadByte() return d.DecodeInt() } func (resp *Response) decodeHeader(d *msgpack.Decoder) (err error) { var l int - d.Reset(&resp.buf) + if err = d.Reset(&resp.buf); err != nil { + return + } if l, err = d.DecodeMapLen(); err != nil { return } diff --git a/schema.go b/schema.go index 9b2dfae75..f10c9539e 100644 --- a/schema.go +++ b/schema.go @@ -51,9 +51,9 @@ type IndexField struct { const ( maxSchemas = 10000 - spaceSpId = 280 + spaceSpId = 280 //nolint vspaceSpId = 281 - indexSpId = 288 + indexSpId = 288 //nolint vindexSpId = 289 ) diff --git a/tarantool_test.go b/tarantool_test.go index 41bdfe830..e4066b1ea 100644 --- a/tarantool_test.go +++ b/tarantool_test.go @@ -27,9 +27,9 @@ type Tuple2 struct { } func (m *Member) EncodeMsgpack(e *msgpack.Encoder) error { - e.EncodeSliceLen(2) - e.EncodeString(m.Name) - e.EncodeUint(m.Val) + _ = e.EncodeSliceLen(2) + _ = e.EncodeString(m.Name) + _ = e.EncodeUint(m.Val) return nil } @@ -52,10 +52,10 @@ func (m *Member) DecodeMsgpack(d *msgpack.Decoder) error { } func (c *Tuple2) EncodeMsgpack(e *msgpack.Encoder) error { - e.EncodeSliceLen(3) - e.EncodeUint(c.Cid) - e.EncodeString(c.Orig) - e.Encode(c.Members) + _ = e.EncodeSliceLen(3) + _ = e.EncodeUint(c.Cid) + _ = e.EncodeString(c.Orig) + _ = e.Encode(c.Members) return nil } @@ -79,7 +79,7 @@ func (c *Tuple2) DecodeMsgpack(d *msgpack.Decoder) error { } c.Members = make([]Member, l) for i := 0; i < l; i++ { - d.Decode(&c.Members[i]) + _ = d.Decode(&c.Members[i]) } return nil } @@ -418,7 +418,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Insert: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Insert") + t.Fatalf("Response is nil after Insert") } if len(resp.Data) != 1 { t.Errorf("Response Body len != 1") @@ -451,7 +451,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Delete: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Delete") + t.Fatalf("Response is nil after Delete") } if len(resp.Data) != 1 { t.Errorf("Response Body len != 1") @@ -474,7 +474,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Delete: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Delete") + t.Fatalf("Response is nil after Delete") } if len(resp.Data) != 0 { t.Errorf("Response Data len != 0") @@ -493,7 +493,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Replace (duplicate): %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Replace (duplicate)") + t.Fatalf("Response is nil after Replace (duplicate)") } if len(resp.Data) != 1 { t.Errorf("Response Data len != 1") @@ -518,7 +518,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Update: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Update") + t.Fatalf("Response is nil after Update") } if len(resp.Data) != 1 { t.Errorf("Response Data len != 1") @@ -557,7 +557,7 @@ func TestClient(t *testing.T) { // Select for i := 10; i < 20; i++ { - resp, err = conn.Replace(spaceNo, []interface{}{uint(i), fmt.Sprintf("val %d", i), "bla"}) + _, err = conn.Replace(spaceNo, []interface{}{uint(i), fmt.Sprintf("val %d", i), "bla"}) if err != nil { t.Errorf("Failed to Replace: %s", err.Error()) } @@ -567,7 +567,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Select: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Select") + t.Fatalf("Response is nil after Select") } if len(resp.Data) != 1 { t.Errorf("Response Data len != 1") @@ -589,7 +589,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Select: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Select") + t.Fatalf("Response is nil after Select") } if len(resp.Data) != 0 { t.Errorf("Response Data len != 0") @@ -659,7 +659,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Call: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Call") + t.Fatalf("Response is nil after Call") } if len(resp.Data) < 1 { t.Errorf("Response.Data is empty after Eval") @@ -667,11 +667,17 @@ func TestClient(t *testing.T) { // Call vs Call17 resp, err = conn.Call("simple_incr", []interface{}{1}) + if err != nil { + t.Errorf("Error is not nil: %v", err) + } if resp.Data[0].([]interface{})[0].(uint64) != 2 { t.Errorf("result is not {{1}} : %v", resp.Data) } resp, err = conn.Call17("simple_incr", []interface{}{1}) + if err != nil { + t.Errorf("Error is not nil: %v", err) + } if resp.Data[0].(uint64) != 2 { t.Errorf("result is not {{1}} : %v", resp.Data) } @@ -682,7 +688,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Eval: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Eval") + t.Fatalf("Response is nil after Eval") } if len(resp.Data) < 1 { t.Errorf("Response.Data is empty after Eval") @@ -840,7 +846,7 @@ func TestSchema(t *testing.T) { ifield1 := index3.Fields[0] ifield2 := index3.Fields[1] if ifield1 == nil || ifield2 == nil { - t.Errorf("index field is nil") + t.Fatalf("index field is nil") } if ifield1.Id != 1 || ifield2.Id != 2 { t.Errorf("index field has incorrect Id") @@ -854,7 +860,7 @@ func TestSchema(t *testing.T) { if err != nil || rSpaceNo != 514 || rIndexNo != 3 { t.Errorf("numeric space and index params not resolved as-is") } - rSpaceNo, rIndexNo, err = schema.ResolveSpaceIndex(514, nil) + rSpaceNo, _, err = schema.ResolveSpaceIndex(514, nil) if err != nil || rSpaceNo != 514 { t.Errorf("numeric space param not resolved as-is") } @@ -862,15 +868,15 @@ func TestSchema(t *testing.T) { if err != nil || rSpaceNo != 514 || rIndexNo != 3 { t.Errorf("symbolic space and index params not resolved") } - rSpaceNo, rIndexNo, err = schema.ResolveSpaceIndex("schematest", nil) + rSpaceNo, _, err = schema.ResolveSpaceIndex("schematest", nil) if err != nil || rSpaceNo != 514 { t.Errorf("symbolic space param not resolved") } - rSpaceNo, rIndexNo, err = schema.ResolveSpaceIndex("schematest22", "secondary") + _, _, err = schema.ResolveSpaceIndex("schematest22", "secondary") if err == nil { t.Errorf("resolveSpaceIndex didn't returned error with not existing space name") } - rSpaceNo, rIndexNo, err = schema.ResolveSpaceIndex("schematest", "secondary22") + _, _, err = schema.ResolveSpaceIndex("schematest", "secondary22") if err == nil { t.Errorf("resolveSpaceIndex didn't returned error with not existing index name") } @@ -893,7 +899,7 @@ func TestClientNamed(t *testing.T) { defer conn.Close() // Insert - resp, err = conn.Insert(spaceName, []interface{}{uint(1001), "hello2", "world2"}) + _, err = conn.Insert(spaceName, []interface{}{uint(1001), "hello2", "world2"}) if err != nil { t.Errorf("Failed to Insert: %s", err.Error()) } @@ -945,7 +951,7 @@ func TestClientNamed(t *testing.T) { // Select for i := 1010; i < 1020; i++ { - resp, err = conn.Replace(spaceName, []interface{}{uint(i), fmt.Sprintf("val %d", i), "bla"}) + _, err = conn.Replace(spaceName, []interface{}{uint(i), fmt.Sprintf("val %d", i), "bla"}) if err != nil { t.Errorf("Failed to Replace: %s", err.Error()) }