From 3873c5907067605134887dcd3e78a962fdf56ed0 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Fri, 1 Dec 2017 17:11:06 +0000 Subject: [PATCH 01/13] improving connection work --- connection.go | 276 ++++++++++++++++++++++++++----------------- connection_helper.go | 13 +- cursor.go | 2 - errors.go | 8 ++ session.go | 2 +- 5 files changed, 181 insertions(+), 120 deletions(-) diff --git a/connection.go b/connection.go index e8adc25e..5c61289e 100644 --- a/connection.go +++ b/connection.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "net" - "sync" "sync/atomic" "time" @@ -17,6 +16,9 @@ import ( const ( respHeaderLen = 12 defaultKeepAlivePeriod = time.Second * 30 + + notBad = 0 + bad = 1 ) // Response represents the raw response from a query, most of the time you @@ -39,21 +41,38 @@ type Connection struct { address string opts *ConnectOpts - _ [4]byte - mu sync.Mutex + _ [4]byte + token int64 + cursors map[int64]*Cursor + bad int32 // 0 - not bad, 1 - bad + closed bool + stopReadChan chan bool + readRequestsChan chan tokenAndPromise +} + +type responseAndCursor struct { + response *Response + cursor *Cursor + err error +} + +type tokenAndPromise struct { + ctx context.Context token int64 - cursors map[int64]*Cursor - bad bool - closed bool + query *Query + promise chan responseAndCursor } // NewConnection creates a new connection to the database server func NewConnection(address string, opts *ConnectOpts) (*Connection, error) { var err error c := &Connection{ - address: address, - opts: opts, - cursors: make(map[int64]*Cursor), + address: address, + opts: opts, + cursors: make(map[int64]*Cursor), + stopReadChan: make(chan bool, 1), + bad: notBad, + readRequestsChan: make(chan tokenAndPromise, 16), } keepAlivePeriod := defaultKeepAlivePeriod @@ -82,20 +101,20 @@ func NewConnection(address string, opts *ConnectOpts) (*Connection, error) { return nil, err } + go c.processResponses() + return c, nil } // Close closes the underlying net.Conn func (c *Connection) Close() error { - c.mu.Lock() - defer c.mu.Unlock() - var err error if !c.closed { - err = c.Conn.Close() + c.stopReadChan <- true c.closed = true - c.cursors = make(map[int64]*Cursor) + err = c.Conn.Close() + c.cursors = nil } return err @@ -113,10 +132,8 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er if c == nil { return nil, nil, ErrConnectionClosed } - c.mu.Lock() if c.Conn == nil { - c.bad = true - c.mu.Unlock() + c.setBad() return nil, nil, ErrConnectionClosed } @@ -129,52 +146,32 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er var err error q.Opts["db"], err = DB(c.opts.Database).Build() if err != nil { - c.mu.Unlock() return nil, nil, RQLDriverError{rqlError(err.Error())} } } } - c.mu.Unlock() - var response *Response - var cursor *Cursor - var errchan chan error = make(chan error, 1) - go func() { - err := c.sendQuery(q) - if err != nil { - errchan <- err - return - } + err := c.sendQuery(q) + if err != nil { + return nil, nil, err + } - if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) { - errchan <- nil - return - } + if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) { + return nil, nil, nil + } - for { - response, err := c.readResponse() - if err != nil { - errchan <- err - return - } + promise := make(chan responseAndCursor, 1) - if response.Token == q.Token { - // If this was the requested response process and return - response, cursor, err = c.processResponse(ctx, q, response) - errchan <- err - return - } else if _, ok := c.cursors[response.Token]; ok { - // If the token is in the cursor cache then process the response - c.processResponse(ctx, q, response) - } else { - putResponse(response) - } - } - }() + c.readRequestsChan <- tokenAndPromise{ + ctx: ctx, + token: q.Token, + query: &q, + promise: promise, + } select { - case err := <-errchan: - return response, cursor, err + case future := <-promise: + return future.response, future.cursor, future.err case <-ctx.Done(): if q.Type != p.Query_STOP { stopQuery := newStopQuery(q.Token) @@ -184,6 +181,51 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er } } +func (c *Connection) processResponses() { + readRequests := make(map[int64]tokenAndPromise, 16) + for { + response, err := c.readResponse() + if err != nil { + if len(readRequests) > 0 { + // return error to all queries + // because it's socket or protocol error, no more queries can be processed + for _, rr := range readRequests { + rr.promise <- responseAndCursor{err: err} + delete(readRequests, rr.token) + } + } + if c.closed { + return + } + continue + } + + stop := false + for !stop { + select { + case readRequest := <-c.readRequestsChan: + readRequests[readRequest.token] = readRequest + case <-c.stopReadChan: + return + default: + stop = true // stop when both chans are empty + } + } + + rr, ok := readRequests[response.Token] + if ok { + response, cursor, err := c.processInitialResponse(rr.ctx, *rr.query, response) + rr.promise <- responseAndCursor{response: response, cursor: cursor, err: err} + delete(readRequests, rr.token) + } else { + err := c.processSubsequentResponse(response) + if err != nil { + Log.Errorf("Failed to fill cached cursor: %v", err) + } + } + } +} + type ServerResponse struct { ID string `gorethink:"id"` Name string `gorethink:"name"` @@ -228,7 +270,7 @@ func (c *Connection) sendQuery(q Query) error { // Send the JSON encoding of the query itself. if err = c.writeQuery(q.Token, b); err != nil { - c.bad = true + c.setBad() return RQLConnectionError{rqlError(err.Error())} } @@ -254,8 +296,8 @@ func (c *Connection) readResponse() (*Response, error) { // Read response header (token+length) headerBuf := [respHeaderLen]byte{} - if _, err := c.read(headerBuf[:], respHeaderLen); err != nil { - c.bad = true + if _, err := c.read(headerBuf[:]); err != nil { + c.setBad() return nil, RQLConnectionError{rqlError(err.Error())} } @@ -265,15 +307,15 @@ func (c *Connection) readResponse() (*Response, error) { // Read the JSON encoding of the Response itself. b := make([]byte, int(messageLength)) - if _, err := c.read(b, int(messageLength)); err != nil { - c.bad = true + if _, err := c.read(b); err != nil { + c.setBad() return nil, RQLConnectionError{rqlError(err.Error())} } // Decode the response - var response = newCachedResponse() + var response = new(Response) if err := json.Unmarshal(b, response); err != nil { - c.bad = true + c.setBad() return nil, RQLDriverError{rqlError(err.Error())} } response.Token = responseToken @@ -281,49 +323,74 @@ func (c *Connection) readResponse() (*Response, error) { return response, nil } -func (c *Connection) processResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { +// Called to fill response for the query +func (c *Connection) processInitialResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { switch response.Type { case p.Response_CLIENT_ERROR: - return c.processErrorResponse(q, response, RQLClientError{rqlServerError{response, q.Term}}) + c.processErrorResponse(response) + return response, nil, createClientError(response, q.Term) case p.Response_COMPILE_ERROR: - return c.processErrorResponse(q, response, RQLCompileError{rqlServerError{response, q.Term}}) + c.processErrorResponse(response) + return response, nil, createCompileError(response, q.Term) case p.Response_RUNTIME_ERROR: - return c.processErrorResponse(q, response, createRuntimeError(response.ErrorType, response, q.Term)) + c.processErrorResponse(response) + return response, nil, createRuntimeError(response.ErrorType, response, q.Term) case p.Response_SUCCESS_ATOM, p.Response_SERVER_INFO: return c.processAtomResponse(ctx, q, response) case p.Response_SUCCESS_PARTIAL: - return c.processPartialResponse(ctx, q, response) + return c.processInitialPartialResponse(ctx, q, response) case p.Response_SUCCESS_SEQUENCE: - return c.processSequenceResponse(ctx, q, response) + return c.processInitialSequenceResponse(ctx, q, response) case p.Response_WAIT_COMPLETE: - return c.processWaitResponse(q, response) + return c.processWaitResponse(response), nil, nil default: - putResponse(response) return nil, nil, RQLDriverError{rqlError("Unexpected response type")} } } -func (c *Connection) processErrorResponse(q Query, response *Response, err error) (*Response, *Cursor, error) { - c.mu.Lock() - cursor := c.cursors[response.Token] +// Called to fill cursor in background +func (c *Connection) processSubsequentResponse(response *Response) error { + switch response.Type { + case p.Response_CLIENT_ERROR, p.Response_COMPILE_ERROR, p.Response_RUNTIME_ERROR: + cursor := c.processErrorResponse(response) + if cursor == nil { + return RQLDriverError{rqlError("Internal error: no cached cursor in a streaming response")} + } + switch response.Type { + case p.Response_CLIENT_ERROR: + return createClientError(response, cursor.term) + case p.Response_COMPILE_ERROR: + return createCompileError(response, cursor.term) + default: // case p.Response_RUNTIME_ERROR: + return createRuntimeError(response.ErrorType, response, cursor.term) + } + case p.Response_SUCCESS_PARTIAL: + return c.processSubsequentPartialResponse(response) + case p.Response_SUCCESS_SEQUENCE: + return c.processSubsequentSequenceResponse(response) + case p.Response_WAIT_COMPLETE: + c.processWaitResponse(response) + return nil + default: + return RQLDriverError{rqlError("Unexpected response type")} + } +} +func (c *Connection) processErrorResponse(response *Response) *Cursor { + cursor := c.cursors[response.Token] delete(c.cursors, response.Token) - c.mu.Unlock() - - return response, cursor, err + return cursor } func (c *Connection) processAtomResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { - // Create cursor cursor := newCursor(ctx, c, "Cursor", response.Token, q.Term, q.Opts) cursor.profile = response.Profile - cursor.extend(response) return response, cursor, nil } -func (c *Connection) processPartialResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { +func (c *Connection) processInitialPartialResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { cursorType := "Cursor" if len(response.Notes) > 0 { switch response.Notes[0] { @@ -340,7 +407,6 @@ func (c *Connection) processPartialResponse(ctx context.Context, q Query, respon } } - c.mu.Lock() cursor, ok := c.cursors[response.Token] if !ok { // Create a new cursor if needed @@ -349,60 +415,56 @@ func (c *Connection) processPartialResponse(ctx context.Context, q Query, respon c.cursors[response.Token] = cursor } - c.mu.Unlock() cursor.extend(response) return response, cursor, nil } -func (c *Connection) processSequenceResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { - c.mu.Lock() +func (c *Connection) processSubsequentPartialResponse(response *Response) error { + cursor, ok := c.cursors[response.Token] + if !ok { + return RQLDriverError{rqlError("Internal error: no cached cursor in a streaming response")} + } + + cursor.extend(response) + return nil +} + +func (c *Connection) processInitialSequenceResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { cursor, ok := c.cursors[response.Token] if !ok { // Create a new cursor if needed cursor = newCursor(ctx, c, "Cursor", response.Token, q.Term, q.Opts) cursor.profile = response.Profile } - delete(c.cursors, response.Token) - c.mu.Unlock() cursor.extend(response) return response, cursor, nil } -func (c *Connection) processWaitResponse(q Query, response *Response) (*Response, *Cursor, error) { - c.mu.Lock() +func (c *Connection) processSubsequentSequenceResponse(response *Response) error { + cursor, ok := c.cursors[response.Token] delete(c.cursors, response.Token) - c.mu.Unlock() + if !ok { + return RQLDriverError{rqlError("Internal error: no cached cursor in a streaming response")} + } - return response, nil, nil + cursor.extend(response) + return nil } -func (c *Connection) isBad() bool { - c.mu.Lock() - defer c.mu.Unlock() - - return c.bad +func (c *Connection) processWaitResponse(response *Response) *Response { + delete(c.cursors, response.Token) + return response } -var responseCache = make(chan *Response, 16) - -func newCachedResponse() *Response { - select { - case r := <-responseCache: - return r - default: - return new(Response) - } +func (c *Connection) setBad() { + atomic.StoreInt32(&c.bad, bad) } -func putResponse(r *Response) { - *r = Response{} // zero it - select { - case responseCache <- r: - default: - } +func (c *Connection) isBad() bool { + return atomic.LoadInt32(&c.bad) == bad } diff --git a/connection_helper.go b/connection_helper.go index ba4ff52b..7ed7e3d6 100644 --- a/connection_helper.go +++ b/connection_helper.go @@ -3,6 +3,7 @@ package gorethink import ( "encoding/binary" "golang.org/x/net/context" + "io" ) // Write 'data' to conn @@ -12,16 +13,8 @@ func (c *Connection) writeData(data []byte) error { return err } -func (c *Connection) read(buf []byte, length int) (total int, err error) { - var n int - for total < length { - if n, err = c.Conn.Read(buf[total:length]); err != nil { - break - } - total += n - } - - return total, err +func (c *Connection) read(buf []byte) (total int, err error) { + return io.ReadFull(c.Conn, buf) } func (c *Connection) writeQuery(token int64, q []byte) error { diff --git a/cursor.go b/cursor.go index fe670951..83306f34 100644 --- a/cursor.go +++ b/cursor.go @@ -583,8 +583,6 @@ func (c *Cursor) extendLocked(response *Response) { c.finished = response.Type != p.Response_SUCCESS_PARTIAL c.fetching = false c.isAtom = response.Type == p.Response_SUCCESS_ATOM - - putResponse(response) } // seekCursor takes care of loading more data if needed and applying pending skips diff --git a/errors.go b/errors.go index c5d60f94..bd803e2b 100644 --- a/errors.go +++ b/errors.go @@ -138,6 +138,14 @@ type RQLConnectionError struct { rqlError } +func createClientError(response *Response, term *Term) error { + return RQLClientError{rqlServerError{response, term}} +} + +func createCompileError(response *Response, term *Term) error { + return RQLCompileError{rqlServerError{response, term}} +} + func createRuntimeError(errorType p.Response_ErrorType, response *Response, term *Term) error { serverErr := rqlServerError{response, term} diff --git a/session.go b/session.go index dbdb14a9..1ca78f04 100644 --- a/session.go +++ b/session.go @@ -219,7 +219,7 @@ func (s *Session) Close(optArgs ...CloseOpts) error { } if s.cluster != nil { - s.cluster.Close() + return s.cluster.Close() } s.cluster = nil s.closed = true From 84c1270ea51f55386bc2cd0a0b88997f564c0b03 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Mon, 4 Dec 2017 17:20:16 +0000 Subject: [PATCH 02/13] connection refactor --- connection.go | 202 ++++++++++++++++++++++++++------------------------ gorethink.go | 4 +- 2 files changed, 109 insertions(+), 97 deletions(-) diff --git a/connection.go b/connection.go index 5c61289e..f0425914 100644 --- a/connection.go +++ b/connection.go @@ -19,6 +19,9 @@ const ( notBad = 0 bad = 1 + + working = 0 + closed = 1 ) // Response represents the raw response from a query, most of the time you @@ -45,21 +48,27 @@ type Connection struct { token int64 cursors map[int64]*Cursor bad int32 // 0 - not bad, 1 - bad - closed bool + closed int32 // 0 - working, 1 - closed stopReadChan chan bool readRequestsChan chan tokenAndPromise + responseChan chan responseAndError +} + +type responseAndError struct { + response *Response + err error } type responseAndCursor struct { response *Response cursor *Cursor - err error + err error } type tokenAndPromise struct { - ctx context.Context + ctx context.Context token int64 - query *Query + query *Query promise chan responseAndCursor } @@ -72,7 +81,9 @@ func NewConnection(address string, opts *ConnectOpts) (*Connection, error) { cursors: make(map[int64]*Cursor), stopReadChan: make(chan bool, 1), bad: notBad, + closed: working, readRequestsChan: make(chan tokenAndPromise, 16), + responseChan: make(chan responseAndError, 16), } keepAlivePeriod := defaultKeepAlivePeriod @@ -101,6 +112,7 @@ func NewConnection(address string, opts *ConnectOpts) (*Connection, error) { return nil, err } + go c.readSocket() go c.processResponses() return c, nil @@ -110,9 +122,9 @@ func NewConnection(address string, opts *ConnectOpts) (*Connection, error) { func (c *Connection) Close() error { var err error - if !c.closed { - c.stopReadChan <- true - c.closed = true + if !c.isClosed() { + close(c.stopReadChan) + c.setClosed() err = c.Conn.Close() c.cursors = nil } @@ -132,7 +144,7 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er if c == nil { return nil, nil, ErrConnectionClosed } - if c.Conn == nil { + if c.Conn == nil || c.isClosed() { c.setBad() return nil, nil, ErrConnectionClosed } @@ -156,16 +168,22 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er return nil, nil, err } + Log.Printf("%v/%p New query %v", q.Token, c, q.Type) + if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) { + c.readRequestsChan <- tokenAndPromise{ + ctx: ctx, + token: q.Token, + query: &q, + } return nil, nil, nil } promise := make(chan responseAndCursor, 1) - c.readRequestsChan <- tokenAndPromise{ - ctx: ctx, - token: q.Token, - query: &q, + ctx: ctx, + token: q.Token, + query: &q, promise: promise, } @@ -181,47 +199,78 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er } } +func (c *Connection) readSocket() { + for { + response, err := c.readResponse() + c.responseChan <- responseAndError{ + response: response, + err: err, + } + + if c.isClosed() { + close(c.responseChan) + return + } + } +} + func (c *Connection) processResponses() { readRequests := make(map[int64]tokenAndPromise, 16) + responses := make(map[int64]responseAndError, 16) for { - response, err := c.readResponse() - if err != nil { - if len(readRequests) > 0 { - // return error to all queries - // because it's socket or protocol error, no more queries can be processed + var respPair responseAndError + var readRequest tokenAndPromise + var ok bool + + select { + case respPair = <-c.responseChan: + if respPair.err != nil { + // Transport socket error, can't continue to work + // Don't know return to who - return to all for _, rr := range readRequests { - rr.promise <- responseAndCursor{err: err} - delete(readRequests, rr.token) + if rr.promise != nil { + rr.promise <- responseAndCursor{err: respPair.err} + close(rr.promise) + } } - } - if c.closed { return } - continue - } - stop := false - for !stop { - select { - case readRequest := <-c.readRequestsChan: + readRequest, ok = readRequests[respPair.response.Token] + if !ok { + Log.Printf("%v/%p: got response without pair", respPair.response.Token, c) + responses[respPair.response.Token] = respPair + continue + } + Log.Printf("%v/%p: got response, has pair", respPair.response.Token, c) + delete(readRequests, respPair.response.Token) + case readRequest = <-c.readRequestsChan: + if c.isClosed() && readRequest.promise != nil { + close(readRequest.promise) + continue + } + + respPair, ok = responses[readRequest.token] + if !ok { + Log.Printf("%v/%p: got request without pair", readRequest.token, c) readRequests[readRequest.token] = readRequest - case <-c.stopReadChan: - return - default: - stop = true // stop when both chans are empty + continue } + Log.Printf("%v/%p: got request, has pair", readRequest.token, c) + delete(responses, readRequest.token) + case <-c.stopReadChan: + for _, rr := range readRequests { + if rr.promise != nil { + close(rr.promise) + } + } + return } - rr, ok := readRequests[response.Token] - if ok { - response, cursor, err := c.processInitialResponse(rr.ctx, *rr.query, response) - rr.promise <- responseAndCursor{response: response, cursor: cursor, err: err} - delete(readRequests, rr.token) - } else { - err := c.processSubsequentResponse(response) - if err != nil { - Log.Errorf("Failed to fill cached cursor: %v", err) - } + response, cursor, err := c.processResponse(readRequest.ctx, *readRequest.query, respPair.response) + if readRequest.promise != nil { + readRequest.promise <- responseAndCursor{response: response, cursor: cursor, err: err} + close(readRequest.promise) } } } @@ -324,7 +373,9 @@ func (c *Connection) readResponse() (*Response, error) { } // Called to fill response for the query -func (c *Connection) processInitialResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { +func (c *Connection) processResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { + Log.Printf("%v/%p, Processing response %v", response.Token, c, response.Type) + switch response.Type { case p.Response_CLIENT_ERROR: c.processErrorResponse(response) @@ -338,41 +389,13 @@ func (c *Connection) processInitialResponse(ctx context.Context, q Query, respon case p.Response_SUCCESS_ATOM, p.Response_SERVER_INFO: return c.processAtomResponse(ctx, q, response) case p.Response_SUCCESS_PARTIAL: - return c.processInitialPartialResponse(ctx, q, response) + return c.processPartialResponse(ctx, q, response) case p.Response_SUCCESS_SEQUENCE: - return c.processInitialSequenceResponse(ctx, q, response) + return c.processSequenceResponse(ctx, q, response) case p.Response_WAIT_COMPLETE: return c.processWaitResponse(response), nil, nil default: - return nil, nil, RQLDriverError{rqlError("Unexpected response type")} - } -} - -// Called to fill cursor in background -func (c *Connection) processSubsequentResponse(response *Response) error { - switch response.Type { - case p.Response_CLIENT_ERROR, p.Response_COMPILE_ERROR, p.Response_RUNTIME_ERROR: - cursor := c.processErrorResponse(response) - if cursor == nil { - return RQLDriverError{rqlError("Internal error: no cached cursor in a streaming response")} - } - switch response.Type { - case p.Response_CLIENT_ERROR: - return createClientError(response, cursor.term) - case p.Response_COMPILE_ERROR: - return createCompileError(response, cursor.term) - default: // case p.Response_RUNTIME_ERROR: - return createRuntimeError(response.ErrorType, response, cursor.term) - } - case p.Response_SUCCESS_PARTIAL: - return c.processSubsequentPartialResponse(response) - case p.Response_SUCCESS_SEQUENCE: - return c.processSubsequentSequenceResponse(response) - case p.Response_WAIT_COMPLETE: - c.processWaitResponse(response) - return nil - default: - return RQLDriverError{rqlError("Unexpected response type")} + return nil, nil, RQLDriverError{rqlError("Unexpected response type: %v")} } } @@ -390,7 +413,7 @@ func (c *Connection) processAtomResponse(ctx context.Context, q Query, response return response, cursor, nil } -func (c *Connection) processInitialPartialResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { +func (c *Connection) processPartialResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { cursorType := "Cursor" if len(response.Notes) > 0 { switch response.Notes[0] { @@ -421,17 +444,7 @@ func (c *Connection) processInitialPartialResponse(ctx context.Context, q Query, return response, cursor, nil } -func (c *Connection) processSubsequentPartialResponse(response *Response) error { - cursor, ok := c.cursors[response.Token] - if !ok { - return RQLDriverError{rqlError("Internal error: no cached cursor in a streaming response")} - } - - cursor.extend(response) - return nil -} - -func (c *Connection) processInitialSequenceResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { +func (c *Connection) processSequenceResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { cursor, ok := c.cursors[response.Token] if !ok { // Create a new cursor if needed @@ -445,17 +458,6 @@ func (c *Connection) processInitialSequenceResponse(ctx context.Context, q Query return response, cursor, nil } -func (c *Connection) processSubsequentSequenceResponse(response *Response) error { - cursor, ok := c.cursors[response.Token] - delete(c.cursors, response.Token) - if !ok { - return RQLDriverError{rqlError("Internal error: no cached cursor in a streaming response")} - } - - cursor.extend(response) - return nil -} - func (c *Connection) processWaitResponse(response *Response) *Response { delete(c.cursors, response.Token) return response @@ -468,3 +470,11 @@ func (c *Connection) setBad() { func (c *Connection) isBad() bool { return atomic.LoadInt32(&c.bad) == bad } + +func (c *Connection) setClosed() { + atomic.StoreInt32(&c.closed, closed) +} + +func (c *Connection) isClosed() bool { + return atomic.LoadInt32(&c.closed) == closed +} diff --git a/gorethink.go b/gorethink.go index 22614eab..55df3bcc 100644 --- a/gorethink.go +++ b/gorethink.go @@ -1,12 +1,12 @@ package gorethink import ( - "io/ioutil" "reflect" "github.com/sirupsen/logrus" "gopkg.in/gorethink/gorethink.v3/encoding" + "io/ioutil" ) var ( @@ -35,6 +35,8 @@ func init() { encoding.IgnoreType(reflect.TypeOf(Term{})) Log = logrus.New() + //f, _ := os.Create("/root/log") + //Log.Out = f Log.Out = ioutil.Discard // By default don't log anything } From d0f65260f5649455ae442a3c6dd59d50481fb196 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Tue, 5 Dec 2017 13:49:03 +0000 Subject: [PATCH 03/13] fix connection bug --- connection.go | 92 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 31 deletions(-) diff --git a/connection.go b/connection.go index f0425914..d2aaa57d 100644 --- a/connection.go +++ b/connection.go @@ -126,7 +126,6 @@ func (c *Connection) Close() error { close(c.stopReadChan) c.setClosed() err = c.Conn.Close() - c.cursors = nil } return err @@ -168,8 +167,6 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er return nil, nil, err } - Log.Printf("%v/%p New query %v", q.Token, c, q.Type) - if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) { c.readRequestsChan <- tokenAndPromise{ ctx: ctx, @@ -215,59 +212,59 @@ func (c *Connection) readSocket() { } func (c *Connection) processResponses() { - readRequests := make(map[int64]tokenAndPromise, 16) - responses := make(map[int64]responseAndError, 16) + readRequests := make([]tokenAndPromise, 0, 16) + responses := make([]*Response, 0, 16) for { - var respPair responseAndError + var response *Response var readRequest tokenAndPromise var ok bool select { - case respPair = <-c.responseChan: + case respPair := <-c.responseChan: if respPair.err != nil { // Transport socket error, can't continue to work // Don't know return to who - return to all for _, rr := range readRequests { - if rr.promise != nil { - rr.promise <- responseAndCursor{err: respPair.err} - close(rr.promise) - } + if rr.promise != nil { + rr.promise <- responseAndCursor{err: respPair.err} + close(rr.promise) + } } + c.cursors = nil return } + response = respPair.response - readRequest, ok = readRequests[respPair.response.Token] + token := respPair.response.Token + readRequest, ok = getReadRequest(readRequests, token) if !ok { - Log.Printf("%v/%p: got response without pair", respPair.response.Token, c) - responses[respPair.response.Token] = respPair + responses = append(responses, respPair.response) continue } - Log.Printf("%v/%p: got response, has pair", respPair.response.Token, c) - delete(readRequests, respPair.response.Token) + readRequests = removeReadRequest(readRequests, respPair.response.Token) case readRequest = <-c.readRequestsChan: if c.isClosed() && readRequest.promise != nil { close(readRequest.promise) continue } - respPair, ok = responses[readRequest.token] + response, ok = getResponse(responses, readRequest.token) if !ok { - Log.Printf("%v/%p: got request without pair", readRequest.token, c) - readRequests[readRequest.token] = readRequest + readRequests = append(readRequests, readRequest) continue } - Log.Printf("%v/%p: got request, has pair", readRequest.token, c) - delete(responses, readRequest.token) + responses = removeResponse(responses, readRequest.token) case <-c.stopReadChan: for _, rr := range readRequests { if rr.promise != nil { close(rr.promise) } } + c.cursors = nil return } - response, cursor, err := c.processResponse(readRequest.ctx, *readRequest.query, respPair.response) + response, cursor, err := c.processResponse(readRequest.ctx, *readRequest.query, response) if readRequest.promise != nil { readRequest.promise <- responseAndCursor{response: response, cursor: cursor, err: err} close(readRequest.promise) @@ -374,18 +371,15 @@ func (c *Connection) readResponse() (*Response, error) { // Called to fill response for the query func (c *Connection) processResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { - Log.Printf("%v/%p, Processing response %v", response.Token, c, response.Type) - switch response.Type { case p.Response_CLIENT_ERROR: - c.processErrorResponse(response) - return response, nil, createClientError(response, q.Term) + return response, c.processErrorResponse(response), createClientError(response, q.Term) case p.Response_COMPILE_ERROR: c.processErrorResponse(response) - return response, nil, createCompileError(response, q.Term) + return response, c.processErrorResponse(response), createCompileError(response, q.Term) case p.Response_RUNTIME_ERROR: c.processErrorResponse(response) - return response, nil, createRuntimeError(response.ErrorType, response, q.Term) + return response, c.processErrorResponse(response), createRuntimeError(response.ErrorType, response, q.Term) case p.Response_SUCCESS_ATOM, p.Response_SERVER_INFO: return c.processAtomResponse(ctx, q, response) case p.Response_SUCCESS_PARTIAL: @@ -393,7 +387,7 @@ func (c *Connection) processResponse(ctx context.Context, q Query, response *Res case p.Response_SUCCESS_SEQUENCE: return c.processSequenceResponse(ctx, q, response) case p.Response_WAIT_COMPLETE: - return c.processWaitResponse(response), nil, nil + return c.processWaitResponse(response) default: return nil, nil, RQLDriverError{rqlError("Unexpected response type: %v")} } @@ -458,9 +452,9 @@ func (c *Connection) processSequenceResponse(ctx context.Context, q Query, respo return response, cursor, nil } -func (c *Connection) processWaitResponse(response *Response) *Response { +func (c *Connection) processWaitResponse(response *Response) (*Response, *Cursor, error) { delete(c.cursors, response.Token) - return response + return response, nil, nil } func (c *Connection) setBad() { @@ -478,3 +472,39 @@ func (c *Connection) setClosed() { func (c *Connection) isClosed() bool { return atomic.LoadInt32(&c.closed) == closed } + +func getReadRequest(list []tokenAndPromise, token int64) (tokenAndPromise, bool) { + for _, e := range list { + if e.token == token { + return e, true + } + } + return tokenAndPromise{}, false +} + +func getResponse(list []*Response, token int64) (*Response, bool) { + for _, e := range list { + if e.Token == token { + return e, true + } + } + return nil, false +} + +func removeReadRequest(list []tokenAndPromise, token int64) []tokenAndPromise { + for i := range list { + if list[i].token == token { + return append(list[:i], list[i+1:]...) + } + } + return list +} + +func removeResponse(list []*Response, token int64) []*Response { + for i := range list { + if list[i].Token == token { + return append(list[:i], list[i+1:]...) + } + } + return list +} From 661bc6ba0342b54730c4b8c025ccc38ab205da65 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Tue, 5 Dec 2017 13:59:45 +0000 Subject: [PATCH 04/13] fix build --- cluster_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cluster_test.go b/cluster_test.go index d7f334f8..38c6d34e 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -31,13 +31,13 @@ func (s *RethinkSuite) TestClusterMultipleQueries(c *test.C) { c.Assert(err, test.IsNil) for i := 0; i < 1000; i++ { - row, err := Expr(fmt.Sprintf("Hello World", i)).Run(session) + row, err := Expr(fmt.Sprintf("Hello World %v", i)).Run(session) c.Assert(err, test.IsNil) var response string err = row.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, test.Equals, fmt.Sprintf("Hello World", i)) + c.Assert(response, test.Equals, fmt.Sprintf("Hello World %v", i)) } } From 365f717e76c721aea4c9a2958b9eaf6982b47829 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Tue, 5 Dec 2017 15:48:05 +0000 Subject: [PATCH 05/13] fix close deadlock --- connection.go | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/connection.go b/connection.go index d2aaa57d..9bdf5187 100644 --- a/connection.go +++ b/connection.go @@ -11,6 +11,7 @@ import ( "golang.org/x/net/context" p "gopkg.in/gorethink/gorethink.v3/ql2" + "sync" ) const ( @@ -52,6 +53,7 @@ type Connection struct { stopReadChan chan bool readRequestsChan chan tokenAndPromise responseChan chan responseAndError + mu sync.Mutex } type responseAndError struct { @@ -122,9 +124,12 @@ func NewConnection(address string, opts *ConnectOpts) (*Connection, error) { func (c *Connection) Close() error { var err error + c.mu.Lock() + defer c.mu.Unlock() + if !c.isClosed() { - close(c.stopReadChan) c.setClosed() + close(c.stopReadChan) err = c.Conn.Close() } @@ -199,12 +204,15 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er func (c *Connection) readSocket() { for { response, err := c.readResponse() - c.responseChan <- responseAndError{ + + respPair := responseAndError{ response: response, err: err, } - if c.isClosed() { + select { + case c.responseChan <- respPair: + case <-c.stopReadChan: close(c.responseChan) return } @@ -225,35 +233,35 @@ func (c *Connection) processResponses() { // Transport socket error, can't continue to work // Don't know return to who - return to all for _, rr := range readRequests { - if rr.promise != nil { - rr.promise <- responseAndCursor{err: respPair.err} - close(rr.promise) - } + if rr.promise != nil { + rr.promise <- responseAndCursor{err: respPair.err} + close(rr.promise) + } } - c.cursors = nil - return + c.Close() + continue + } + if respPair.response == nil && respPair.err == nil { // responseChan is closed + continue } + response = respPair.response - token := respPair.response.Token - readRequest, ok = getReadRequest(readRequests, token) + readRequest, ok = getReadRequest(readRequests, respPair.response.Token) if !ok { responses = append(responses, respPair.response) continue } readRequests = removeReadRequest(readRequests, respPair.response.Token) - case readRequest = <-c.readRequestsChan: - if c.isClosed() && readRequest.promise != nil { - close(readRequest.promise) - continue - } + case readRequest = <-c.readRequestsChan: response, ok = getResponse(responses, readRequest.token) if !ok { readRequests = append(readRequests, readRequest) continue } responses = removeResponse(responses, readRequest.token) + case <-c.stopReadChan: for _, rr := range readRequests { if rr.promise != nil { @@ -308,9 +316,7 @@ func (c *Connection) sendQuery(q Query) error { } // Set timeout - if c.opts.WriteTimeout == 0 { - c.Conn.SetWriteDeadline(time.Time{}) - } else { + if c.opts.WriteTimeout != 0 { c.Conn.SetWriteDeadline(time.Now().Add(c.opts.WriteTimeout)) } @@ -334,9 +340,7 @@ func (c *Connection) nextToken() int64 { // could be read then an error is returned. func (c *Connection) readResponse() (*Response, error) { // Set timeout - if c.opts.ReadTimeout == 0 { - c.Conn.SetReadDeadline(time.Time{}) - } else { + if c.opts.ReadTimeout != 0 { c.Conn.SetReadDeadline(time.Now().Add(c.opts.ReadTimeout)) } From 94989f2e884359aee325f4e110c7e4f2bb24c95b Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Wed, 6 Dec 2017 16:51:13 +0000 Subject: [PATCH 06/13] opentracing --- .travis.yml | 1 + connection.go | 102 +++++++++++++++++++++++++++++++++++++------------- cursor.go | 5 +++ gorethink.go | 2 - session.go | 5 +++ 5 files changed, 87 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 22199ec0..d53857a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: go go: - 1.7.5 - 1.8.1 + - 1.9.2 - tip cache: apt diff --git a/connection.go b/connection.go index 9bdf5187..fb64ca02 100644 --- a/connection.go +++ b/connection.go @@ -12,6 +12,9 @@ import ( "golang.org/x/net/context" p "gopkg.in/gorethink/gorethink.v3/ql2" "sync" + "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go/ext" + "github.com/opentracing/opentracing-go/log" ) const ( @@ -69,9 +72,9 @@ type responseAndCursor struct { type tokenAndPromise struct { ctx context.Context - token int64 query *Query promise chan responseAndCursor + span opentracing.Span } // NewConnection creates a new connection to the database server @@ -141,10 +144,6 @@ func (c *Connection) Close() error { // // This function is used internally by Run which should be used for most queries. func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, error) { - if ctx == nil { - ctx = c.contextFromConnectionOpts() - } - if c == nil { return nil, nil, ErrConnectionClosed } @@ -152,6 +151,9 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er c.setBad() return nil, nil, ErrConnectionClosed } + if ctx == nil { + ctx = c.contextFromConnectionOpts() + } // Add token if query is a START/NOREPLY_WAIT if q.Type == p.Query_START || q.Type == p.Query_NOREPLY_WAIT || q.Type == p.Query_SERVER_INFO { @@ -167,38 +169,76 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er } } + var fetchingSpan opentracing.Span + if c.opts.UseOpentracing { + parentSpan := opentracing.SpanFromContext(ctx) + if parentSpan != nil { + if q.Type == p.Query_START { + querySpan := c.startTracingSpan(parentSpan, &q) // will be Finished when cursor closed + parentSpan = querySpan + ctx = opentracing.ContextWithSpan(ctx, querySpan) + } + + fetchingSpan = c.startTracingSpan(parentSpan, &q) // will be Finished when response arrived + } + } + err := c.sendQuery(q) if err != nil { + if fetchingSpan != nil { + ext.Error.Set(fetchingSpan, true) + fetchingSpan.LogFields(log.Error(err)) + fetchingSpan.Finish() + } return nil, nil, err } if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) { - c.readRequestsChan <- tokenAndPromise{ - ctx: ctx, - token: q.Token, - query: &q, + select { + case c.readRequestsChan <- tokenAndPromise{ctx: ctx, query: &q, span: fetchingSpan}: + return nil, nil, nil + case <-ctx.Done(): + return c.stopQuery(&q) } - return nil, nil, nil } promise := make(chan responseAndCursor, 1) - c.readRequestsChan <- tokenAndPromise{ - ctx: ctx, - token: q.Token, - query: &q, - promise: promise, + select { + case c.readRequestsChan <- tokenAndPromise{ctx: ctx, query: &q, span: fetchingSpan, promise: promise}: + case <-ctx.Done(): + return c.stopQuery(&q) } select { case future := <-promise: return future.response, future.cursor, future.err case <-ctx.Done(): - if q.Type != p.Query_STOP { - stopQuery := newStopQuery(q.Token) - c.Query(c.contextFromConnectionOpts(), stopQuery) - } - return nil, nil, ErrQueryTimeout + return c.stopQuery(&q) + } +} + +func (c *Connection) stopQuery(q *Query) (*Response, *Cursor, error) { + if q.Type != p.Query_STOP { + stopQuery := newStopQuery(q.Token) + c.Query(c.contextFromConnectionOpts(), stopQuery) } + return nil, nil, ErrQueryTimeout +} + +func (c* Connection) startTracingSpan(parentSpan opentracing.Span, q *Query) opentracing.Span { + span := parentSpan.Tracer().StartSpan( + "Query_"+q.Type.String(), + opentracing.ChildOf(parentSpan.Context()), + ext.SpanKindRPCClient) + + ext.PeerAddress.Set(span, c.address) + ext.Component.Set(span, "gorethink") + + if q.Type == p.Query_START { + span.LogFields(log.String("query", q.Term.String())) + } + + return span } func (c *Connection) readSocket() { @@ -255,12 +295,12 @@ func (c *Connection) processResponses() { readRequests = removeReadRequest(readRequests, respPair.response.Token) case readRequest = <-c.readRequestsChan: - response, ok = getResponse(responses, readRequest.token) + response, ok = getResponse(responses, readRequest.query.Token) if !ok { readRequests = append(readRequests, readRequest) continue } - responses = removeResponse(responses, readRequest.token) + responses = removeResponse(responses, readRequest.query.Token) case <-c.stopReadChan: for _, rr := range readRequests { @@ -272,7 +312,7 @@ func (c *Connection) processResponses() { return } - response, cursor, err := c.processResponse(readRequest.ctx, *readRequest.query, response) + response, cursor, err := c.processResponse(readRequest.ctx, *readRequest.query, response, readRequest.span) if readRequest.promise != nil { readRequest.promise <- responseAndCursor{response: response, cursor: cursor, err: err} close(readRequest.promise) @@ -374,7 +414,17 @@ func (c *Connection) readResponse() (*Response, error) { } // Called to fill response for the query -func (c *Connection) processResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { +func (c *Connection) processResponse(ctx context.Context, q Query, response *Response, span opentracing.Span) (r *Response, cur *Cursor, err error) { + if span != nil { + defer func(){ + if err != nil { + ext.Error.Set(span, true) + span.LogFields(log.Error(err)) + } + span.Finish() + }() + } + switch response.Type { case p.Response_CLIENT_ERROR: return response, c.processErrorResponse(response), createClientError(response, q.Term) @@ -479,7 +529,7 @@ func (c *Connection) isClosed() bool { func getReadRequest(list []tokenAndPromise, token int64) (tokenAndPromise, bool) { for _, e := range list { - if e.token == token { + if e.query.Token == token { return e, true } } @@ -497,7 +547,7 @@ func getResponse(list []*Response, token int64) (*Response, bool) { func removeReadRequest(list []tokenAndPromise, token int64) []tokenAndPromise { for i := range list { - if list[i].token == token { + if list[i].query.Token == token { return append(list[:i], list[i+1:]...) } } diff --git a/cursor.go b/cursor.go index 83306f34..8dad0ef4 100644 --- a/cursor.go +++ b/cursor.go @@ -10,6 +10,7 @@ import ( "golang.org/x/net/context" "gopkg.in/gorethink/gorethink.v3/encoding" p "gopkg.in/gorethink/gorethink.v3/ql2" + "github.com/opentracing/opentracing-go" ) var ( @@ -157,6 +158,10 @@ func (c *Cursor) Close() error { } } + if span := opentracing.SpanFromContext(c.ctx); span != nil { + span.Finish() + } + c.closed = true c.conn = nil c.buffer = nil diff --git a/gorethink.go b/gorethink.go index 55df3bcc..b7d1daa8 100644 --- a/gorethink.go +++ b/gorethink.go @@ -35,8 +35,6 @@ func init() { encoding.IgnoreType(reflect.TypeOf(Term{})) Log = logrus.New() - //f, _ := os.Create("/root/log") - //Log.Out = f Log.Out = ioutil.Discard // By default don't log anything } diff --git a/session.go b/session.go index 1ca78f04..c508f4c5 100644 --- a/session.go +++ b/session.go @@ -93,6 +93,11 @@ type ConnectOpts struct { // score when selecting a host. By default a value of 5 minutes is used. HostDecayDuration time.Duration + // UseOpentracing is used to enable creating opentracing-go spans for queries. + // Each span is created as child of span from the context in `RunOpts`. + // This span lasts from point the query created to the point when cursor closed. + UseOpentracing bool + // Deprecated: This function is no longer used due to changes in the // way hosts are selected. NodeRefreshInterval time.Duration `gorethink:"node_refresh_interval,omitempty"` From 0f15c79ff2eb284b34b503add00f82843265de06 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Thu, 7 Dec 2017 17:15:15 +0000 Subject: [PATCH 07/13] unit test starting --- connection.go | 58 ++-- connection_helper.go | 20 -- connection_test.go | 78 ++++++ .../{ => integration}/reql_tests/common.go | 0 .../reql_tests/gorethink_test.go | 0 .../reql_tests/reql_aggregation_test.go | 0 .../reql_tests/reql_changefeeds_edge_test.go | 0 .../reql_changefeeds_idxcopy_test.go | 0 .../reql_changefeeds_include_states_test.go | 0 .../reql_tests/reql_changefeeds_point_test.go | 0 .../reql_tests/reql_changefeeds_table_test.go | 0 .../reql_tests/reql_control_test.go | 0 .../reql_tests/reql_datum_array_test.go | 0 .../reql_tests/reql_datum_binary_test.go | 0 .../reql_tests/reql_datum_bool_test.go | 0 .../reql_tests/reql_datum_null_test.go | 0 .../reql_tests/reql_datum_number_test.go | 0 .../reql_tests/reql_datum_object_test.go | 0 .../reql_tests/reql_datum_string_test.go | 0 .../reql_tests/reql_datum_typeof_test.go | 0 .../reql_tests/reql_datum_uuid_test.go | 0 .../reql_tests/reql_default_test.go | 0 .../reql_tests/reql_geo_constructors_test.go | 0 .../reql_tests/reql_geo_geojson_test.go | 0 .../reql_tests/reql_geo_indexing_test.go | 0 .../reql_geo_intersection_inclusion_test.go | 0 .../reql_tests/reql_geo_operations_test.go | 0 .../reql_tests/reql_geo_primitives_test.go | 0 .../reql_tests/reql_joins_test.go | 0 .../reql_tests/reql_json_test.go | 0 .../reql_tests/reql_match_test.go | 0 .../reql_tests/reql_math_logic_add_test.go | 0 .../reql_math_logic_aliases_test.go | 0 .../reql_math_logic_comparison_test.go | 0 .../reql_tests/reql_math_logic_div_test.go | 0 .../reql_math_logic_floor_ceil_round_test.go | 0 .../reql_tests/reql_math_logic_logic_test.go | 0 .../reql_tests/reql_math_logic_math_test.go | 0 .../reql_tests/reql_math_logic_mod_test.go | 0 .../reql_tests/reql_math_logic_mul_test.go | 0 .../reql_tests/reql_math_logic_sub_test.go | 0 .../reql_tests/reql_meta_composite_test.go | 0 .../reql_tests/reql_meta_dbs_test.go | 0 .../reql_tests/reql_meta_table_test.go | 0 .../reql_mutation_atomic_get_set_test.go | 0 .../reql_tests/reql_mutation_delete_test.go | 0 .../reql_tests/reql_mutation_insert_test.go | 0 .../reql_tests/reql_mutation_replace_test.go | 0 .../reql_tests/reql_mutation_sync_test.go | 0 .../reql_tests/reql_mutation_update_test.go | 0 .../reql_tests/reql_polymorphism_test.go | 0 .../reql_tests/reql_random_test.go | 0 .../reql_tests/reql_range_test.go | 0 .../reql_tests/reql_selection_test.go | 0 .../reql_tests/reql_sindex_api_test.go | 0 .../reql_sindex_nullsinstrings_test.go | 0 .../reql_tests/reql_sindex_status_test.go | 0 .../reql_tests/reql_timeout_test.go | 0 .../reql_tests/reql_times_api_test.go | 0 .../reql_times_constructors_test.go | 0 .../reql_tests/reql_times_index_test.go | 0 .../reql_tests/reql_times_portions_test.go | 0 .../reql_tests/reql_times_shim_test.go | 0 .../reql_tests/reql_times_time_arith_test.go | 0 .../reql_tests/reql_times_timezones_test.go | 0 .../reql_tests/reql_transform_array_test.go | 0 .../reql_tests/reql_transform_fold_test.go | 0 .../reql_tests/reql_transform_map_test.go | 0 .../reql_tests/reql_transform_object_test.go | 0 .../reql_tests/reql_transform_table_test.go | 0 .../reql_transform_unordered_map_test.go | 0 .../reql_tests/reql_transformation_test.go | 0 .../reql_tests/template.go.tpl | 0 .../integration/tests/benchmarks_test.go | 59 ++-- .../integration/tests/checkers.go | 8 +- .../tests/cluster_integration_test.go | 2 +- .../integration/tests/cluster_test.go | 2 +- .../integration/tests/cursor_test.go | 115 ++++---- .../integration/tests/example_connect_test.go | 24 +- .../tests/example_query_aggregation_test.go | 21 +- .../tests/example_query_control_test.go | 31 ++- .../tests/example_query_db_test.go | 13 +- .../tests/example_query_manipulation_test.go | 5 +- .../tests/example_query_select_test.go | 21 +- .../tests/example_query_table_test.go | 25 +- .../example_query_transformation_test.go | 25 +- .../tests/example_query_write_test.go | 33 +-- .../integration/tests/example_test.go | 2 +- .../integration/tests/gorethink_test.go | 69 ++--- .../integration/tests/query_test.go | 257 +++++++++--------- .../integration/tests/session_test.go | 49 ++-- .../integration/tests/testdata_test.go | 58 ++-- mock_test.go | 61 +++-- mocks_test.go | 55 ++++ 94 files changed, 624 insertions(+), 467 deletions(-) create mode 100644 connection_test.go rename internal/{ => integration}/reql_tests/common.go (100%) rename internal/{ => integration}/reql_tests/gorethink_test.go (100%) rename internal/{ => integration}/reql_tests/reql_aggregation_test.go (100%) rename internal/{ => integration}/reql_tests/reql_changefeeds_edge_test.go (100%) rename internal/{ => integration}/reql_tests/reql_changefeeds_idxcopy_test.go (100%) rename internal/{ => integration}/reql_tests/reql_changefeeds_include_states_test.go (100%) rename internal/{ => integration}/reql_tests/reql_changefeeds_point_test.go (100%) rename internal/{ => integration}/reql_tests/reql_changefeeds_table_test.go (100%) rename internal/{ => integration}/reql_tests/reql_control_test.go (100%) rename internal/{ => integration}/reql_tests/reql_datum_array_test.go (100%) rename internal/{ => integration}/reql_tests/reql_datum_binary_test.go (100%) rename internal/{ => integration}/reql_tests/reql_datum_bool_test.go (100%) rename internal/{ => integration}/reql_tests/reql_datum_null_test.go (100%) rename internal/{ => integration}/reql_tests/reql_datum_number_test.go (100%) rename internal/{ => integration}/reql_tests/reql_datum_object_test.go (100%) rename internal/{ => integration}/reql_tests/reql_datum_string_test.go (100%) rename internal/{ => integration}/reql_tests/reql_datum_typeof_test.go (100%) rename internal/{ => integration}/reql_tests/reql_datum_uuid_test.go (100%) rename internal/{ => integration}/reql_tests/reql_default_test.go (100%) rename internal/{ => integration}/reql_tests/reql_geo_constructors_test.go (100%) rename internal/{ => integration}/reql_tests/reql_geo_geojson_test.go (100%) rename internal/{ => integration}/reql_tests/reql_geo_indexing_test.go (100%) rename internal/{ => integration}/reql_tests/reql_geo_intersection_inclusion_test.go (100%) rename internal/{ => integration}/reql_tests/reql_geo_operations_test.go (100%) rename internal/{ => integration}/reql_tests/reql_geo_primitives_test.go (100%) rename internal/{ => integration}/reql_tests/reql_joins_test.go (100%) rename internal/{ => integration}/reql_tests/reql_json_test.go (100%) rename internal/{ => integration}/reql_tests/reql_match_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_add_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_aliases_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_comparison_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_div_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_floor_ceil_round_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_logic_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_math_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_mod_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_mul_test.go (100%) rename internal/{ => integration}/reql_tests/reql_math_logic_sub_test.go (100%) rename internal/{ => integration}/reql_tests/reql_meta_composite_test.go (100%) rename internal/{ => integration}/reql_tests/reql_meta_dbs_test.go (100%) rename internal/{ => integration}/reql_tests/reql_meta_table_test.go (100%) rename internal/{ => integration}/reql_tests/reql_mutation_atomic_get_set_test.go (100%) rename internal/{ => integration}/reql_tests/reql_mutation_delete_test.go (100%) rename internal/{ => integration}/reql_tests/reql_mutation_insert_test.go (100%) rename internal/{ => integration}/reql_tests/reql_mutation_replace_test.go (100%) rename internal/{ => integration}/reql_tests/reql_mutation_sync_test.go (100%) rename internal/{ => integration}/reql_tests/reql_mutation_update_test.go (100%) rename internal/{ => integration}/reql_tests/reql_polymorphism_test.go (100%) rename internal/{ => integration}/reql_tests/reql_random_test.go (100%) rename internal/{ => integration}/reql_tests/reql_range_test.go (100%) rename internal/{ => integration}/reql_tests/reql_selection_test.go (100%) rename internal/{ => integration}/reql_tests/reql_sindex_api_test.go (100%) rename internal/{ => integration}/reql_tests/reql_sindex_nullsinstrings_test.go (100%) rename internal/{ => integration}/reql_tests/reql_sindex_status_test.go (100%) rename internal/{ => integration}/reql_tests/reql_timeout_test.go (100%) rename internal/{ => integration}/reql_tests/reql_times_api_test.go (100%) rename internal/{ => integration}/reql_tests/reql_times_constructors_test.go (100%) rename internal/{ => integration}/reql_tests/reql_times_index_test.go (100%) rename internal/{ => integration}/reql_tests/reql_times_portions_test.go (100%) rename internal/{ => integration}/reql_tests/reql_times_shim_test.go (100%) rename internal/{ => integration}/reql_tests/reql_times_time_arith_test.go (100%) rename internal/{ => integration}/reql_tests/reql_times_timezones_test.go (100%) rename internal/{ => integration}/reql_tests/reql_transform_array_test.go (100%) rename internal/{ => integration}/reql_tests/reql_transform_fold_test.go (100%) rename internal/{ => integration}/reql_tests/reql_transform_map_test.go (100%) rename internal/{ => integration}/reql_tests/reql_transform_object_test.go (100%) rename internal/{ => integration}/reql_tests/reql_transform_table_test.go (100%) rename internal/{ => integration}/reql_tests/reql_transform_unordered_map_test.go (100%) rename internal/{ => integration}/reql_tests/reql_transformation_test.go (100%) rename internal/{ => integration}/reql_tests/template.go.tpl (100%) rename benchmarks_test.go => internal/integration/tests/benchmarks_test.go (72%) rename checkers_test.go => internal/integration/tests/checkers.go (96%) rename cluster_integration_test.go => internal/integration/tests/cluster_integration_test.go (99%) rename cluster_test.go => internal/integration/tests/cluster_test.go (98%) rename cursor_test.go => internal/integration/tests/cursor_test.go (76%) rename example_connect_test.go => internal/integration/tests/example_connect_test.go (61%) rename example_query_aggregation_test.go => internal/integration/tests/example_query_aggregation_test.go (74%) rename example_query_control_test.go => internal/integration/tests/example_query_control_test.go (80%) rename example_query_db_test.go => internal/integration/tests/example_query_db_test.go (59%) rename example_query_manipulation_test.go => internal/integration/tests/example_query_manipulation_test.go (62%) rename example_query_select_test.go => internal/integration/tests/example_query_select_test.go (83%) rename example_query_table_test.go => internal/integration/tests/example_query_table_test.go (52%) rename example_query_transformation_test.go => internal/integration/tests/example_query_transformation_test.go (78%) rename example_query_write_test.go => internal/integration/tests/example_query_write_test.go (78%) rename example_test.go => internal/integration/tests/example_test.go (94%) rename gorethink_test.go => internal/integration/tests/gorethink_test.go (80%) rename query_test.go => internal/integration/tests/query_test.go (63%) rename session_test.go => internal/integration/tests/session_test.go (71%) rename testdata_test.go => internal/integration/tests/testdata_test.go (59%) create mode 100644 mocks_test.go diff --git a/connection.go b/connection.go index fb64ca02..51069e47 100644 --- a/connection.go +++ b/connection.go @@ -15,6 +15,7 @@ import ( "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/log" + "bytes" ) const ( @@ -79,34 +80,26 @@ type tokenAndPromise struct { // NewConnection creates a new connection to the database server func NewConnection(address string, opts *ConnectOpts) (*Connection, error) { - var err error - c := &Connection{ - address: address, - opts: opts, - cursors: make(map[int64]*Cursor), - stopReadChan: make(chan bool, 1), - bad: notBad, - closed: working, - readRequestsChan: make(chan tokenAndPromise, 16), - responseChan: make(chan responseAndError, 16), - } - keepAlivePeriod := defaultKeepAlivePeriod if opts.KeepAlivePeriod > 0 { keepAlivePeriod = opts.KeepAlivePeriod } // Connect to Server - nd := net.Dialer{Timeout: c.opts.Timeout, KeepAlive: keepAlivePeriod} - if c.opts.TLSConfig == nil { - c.Conn, err = nd.Dial("tcp", address) + var err error + var conn net.Conn + nd := net.Dialer{Timeout: opts.Timeout, KeepAlive: keepAlivePeriod} + if opts.TLSConfig == nil { + conn, err = nd.Dial("tcp", address) } else { - c.Conn, err = tls.DialWithDialer(&nd, "tcp", address, c.opts.TLSConfig) + conn, err = tls.DialWithDialer(&nd, "tcp", address, opts.TLSConfig) } if err != nil { return nil, RQLConnectionError{rqlError(err.Error())} } + c := newConnection(conn, address, opts) + // Send handshake handshake, err := c.handshake(opts.HandshakeVersion) if err != nil { @@ -117,10 +110,26 @@ func NewConnection(address string, opts *ConnectOpts) (*Connection, error) { return nil, err } + return c, nil +} + +func newConnection(conn net.Conn, address string, opts *ConnectOpts) *Connection { + c := &Connection{ + Conn: conn, + address: address, + opts: opts, + cursors: make(map[int64]*Cursor), + stopReadChan: make(chan bool, 1), + bad: notBad, + closed: working, + readRequestsChan: make(chan tokenAndPromise, 16), + responseChan: make(chan responseAndError, 16), + } + go c.readSocket() go c.processResponses() - return c, nil + return c } // Close closes the underlying net.Conn @@ -349,19 +358,30 @@ func (c *Connection) Server() (ServerResponse, error) { // sendQuery marshals the Query and sends the JSON to the server. func (c *Connection) sendQuery(q Query) error { + buf := &bytes.Buffer{} + buf.Grow(respHeaderLen) + buf.Write(buf.Bytes()[:respHeaderLen]) // reserve for header + enc := json.NewEncoder(buf) + // Build query - b, err := json.Marshal(q.Build()) + err := enc.Encode(q.Build()) if err != nil { return RQLDriverError{rqlError(fmt.Sprintf("Error building query: %s", err.Error()))} } + b := buf.Bytes() + + // Write header + binary.LittleEndian.PutUint64(b, uint64(q.Token)) + binary.LittleEndian.PutUint32(b[8:], uint32(len(b)-respHeaderLen)) + // Set timeout if c.opts.WriteTimeout != 0 { c.Conn.SetWriteDeadline(time.Now().Add(c.opts.WriteTimeout)) } // Send the JSON encoding of the query itself. - if err = c.writeQuery(q.Token, b); err != nil { + if err = c.writeData(b); err != nil { c.setBad() return RQLConnectionError{rqlError(err.Error())} } diff --git a/connection_helper.go b/connection_helper.go index 7ed7e3d6..4684225e 100644 --- a/connection_helper.go +++ b/connection_helper.go @@ -1,7 +1,6 @@ package gorethink import ( - "encoding/binary" "golang.org/x/net/context" "io" ) @@ -17,25 +16,6 @@ func (c *Connection) read(buf []byte) (total int, err error) { return io.ReadFull(c.Conn, buf) } -func (c *Connection) writeQuery(token int64, q []byte) error { - pos := 0 - dataLen := 8 + 4 + len(q) - data := make([]byte, dataLen) - - // Send the protocol version to the server as a 4-byte little-endian-encoded integer - binary.LittleEndian.PutUint64(data[pos:], uint64(token)) - pos += 8 - - // Send the length of the auth key to the server as a 4-byte little-endian-encoded integer - binary.LittleEndian.PutUint32(data[pos:], uint32(len(q))) - pos += 4 - - // Send the auth key as an ASCII string - pos += copy(data[pos:], q) - - return c.writeData(data) -} - func (c *Connection) contextFromConnectionOpts() context.Context { sum := c.opts.ReadTimeout + c.opts.WriteTimeout if c.opts.ReadTimeout == 0 || c.opts.WriteTimeout == 0 { diff --git a/connection_test.go b/connection_test.go new file mode 100644 index 00000000..85eaf537 --- /dev/null +++ b/connection_test.go @@ -0,0 +1,78 @@ +package gorethink + +import ( + test "gopkg.in/check.v1" + p "gopkg.in/gorethink/gorethink.v3/ql2" + "golang.org/x/net/context" + "encoding/binary" + "encoding/json" + "gopkg.in/gorethink/gorethink.v3/internal/integration/tests" +) + +type ConnectionSuite struct{} + +var _ = test.Suite(&ConnectionSuite{}) + +func (s *ConnectionSuite) TestConnection_Query_Ok(c *test.C) { + ctx := context.Background() + token := int64(1) + q := testQuery() + writeData := serializeQuery(token, q) + respData := serializeAtomResponse() + header := respHeader(token, respData) + + conn := &connMock{} + conn.On("Write", writeData).Return(len(writeData), nil) + conn.On("Read", respHeaderLen).Return(header, respHeaderLen, nil) + conn.On("Read", len(respData)).Return(respData, len(respData), nil) + + connection := newConnection(conn, "addr", &ConnectOpts{}) + response, cursor, err := connection.Query(ctx, q) + + c.Assert(response, test.NotNil) + c.Assert(response.Token, test.Equals, token) + c.Assert(response.Type, test.Equals, p.Response_SUCCESS_ATOM) + c.Assert(response.Responses, test.HasLen, 1) + c.Assert(response.Responses[0], tests.JsonEquals, "response") + c.Assert(cursor, test.NotNil) + c.Assert(cursor.token, test.Equals, token) + c.Assert(cursor.conn, test.Equals, connection) + c.Assert(cursor.ctx, test.Equals, ctx) + c.Assert(cursor.responses, test.DeepEquals, response.Responses) + c.Assert(err, test.IsNil) + conn.AssertExpectations(c) +} + +func testQuery() Query { + q, _ := newQuery( + DB("db").Table("table").Get("id"), + map[string]interface{}{}, + &ConnectOpts{}, + ) + return q +} + +func respHeader(token int64, msg []byte) []byte { + header := [respHeaderLen]byte{} + binary.LittleEndian.PutUint64(header[:], uint64(token)) + binary.LittleEndian.PutUint32(header[8:], uint32(len(msg))) + return header[:] +} + +func serializeQuery(token int64, q Query) []byte { + b, _ := json.Marshal(q.Build()) + msg := make([]byte, len(b)+respHeaderLen+1) + binary.LittleEndian.PutUint64(msg, uint64(token)) + binary.LittleEndian.PutUint32(msg[8:], uint32(len(b)+1)) + copy(msg[respHeaderLen:], b) + msg[len(msg)-1] = '\n' // encoder.Marshal do this, json.Marshal doesn't + return msg +} + +func serializeAtomResponse() []byte { + b, _ := json.Marshal(map[string]interface{}{ + "t": p.Response_SUCCESS_ATOM, + "r": []interface{}{"response"}, + }) + return b +} diff --git a/internal/reql_tests/common.go b/internal/integration/reql_tests/common.go similarity index 100% rename from internal/reql_tests/common.go rename to internal/integration/reql_tests/common.go diff --git a/internal/reql_tests/gorethink_test.go b/internal/integration/reql_tests/gorethink_test.go similarity index 100% rename from internal/reql_tests/gorethink_test.go rename to internal/integration/reql_tests/gorethink_test.go diff --git a/internal/reql_tests/reql_aggregation_test.go b/internal/integration/reql_tests/reql_aggregation_test.go similarity index 100% rename from internal/reql_tests/reql_aggregation_test.go rename to internal/integration/reql_tests/reql_aggregation_test.go diff --git a/internal/reql_tests/reql_changefeeds_edge_test.go b/internal/integration/reql_tests/reql_changefeeds_edge_test.go similarity index 100% rename from internal/reql_tests/reql_changefeeds_edge_test.go rename to internal/integration/reql_tests/reql_changefeeds_edge_test.go diff --git a/internal/reql_tests/reql_changefeeds_idxcopy_test.go b/internal/integration/reql_tests/reql_changefeeds_idxcopy_test.go similarity index 100% rename from internal/reql_tests/reql_changefeeds_idxcopy_test.go rename to internal/integration/reql_tests/reql_changefeeds_idxcopy_test.go diff --git a/internal/reql_tests/reql_changefeeds_include_states_test.go b/internal/integration/reql_tests/reql_changefeeds_include_states_test.go similarity index 100% rename from internal/reql_tests/reql_changefeeds_include_states_test.go rename to internal/integration/reql_tests/reql_changefeeds_include_states_test.go diff --git a/internal/reql_tests/reql_changefeeds_point_test.go b/internal/integration/reql_tests/reql_changefeeds_point_test.go similarity index 100% rename from internal/reql_tests/reql_changefeeds_point_test.go rename to internal/integration/reql_tests/reql_changefeeds_point_test.go diff --git a/internal/reql_tests/reql_changefeeds_table_test.go b/internal/integration/reql_tests/reql_changefeeds_table_test.go similarity index 100% rename from internal/reql_tests/reql_changefeeds_table_test.go rename to internal/integration/reql_tests/reql_changefeeds_table_test.go diff --git a/internal/reql_tests/reql_control_test.go b/internal/integration/reql_tests/reql_control_test.go similarity index 100% rename from internal/reql_tests/reql_control_test.go rename to internal/integration/reql_tests/reql_control_test.go diff --git a/internal/reql_tests/reql_datum_array_test.go b/internal/integration/reql_tests/reql_datum_array_test.go similarity index 100% rename from internal/reql_tests/reql_datum_array_test.go rename to internal/integration/reql_tests/reql_datum_array_test.go diff --git a/internal/reql_tests/reql_datum_binary_test.go b/internal/integration/reql_tests/reql_datum_binary_test.go similarity index 100% rename from internal/reql_tests/reql_datum_binary_test.go rename to internal/integration/reql_tests/reql_datum_binary_test.go diff --git a/internal/reql_tests/reql_datum_bool_test.go b/internal/integration/reql_tests/reql_datum_bool_test.go similarity index 100% rename from internal/reql_tests/reql_datum_bool_test.go rename to internal/integration/reql_tests/reql_datum_bool_test.go diff --git a/internal/reql_tests/reql_datum_null_test.go b/internal/integration/reql_tests/reql_datum_null_test.go similarity index 100% rename from internal/reql_tests/reql_datum_null_test.go rename to internal/integration/reql_tests/reql_datum_null_test.go diff --git a/internal/reql_tests/reql_datum_number_test.go b/internal/integration/reql_tests/reql_datum_number_test.go similarity index 100% rename from internal/reql_tests/reql_datum_number_test.go rename to internal/integration/reql_tests/reql_datum_number_test.go diff --git a/internal/reql_tests/reql_datum_object_test.go b/internal/integration/reql_tests/reql_datum_object_test.go similarity index 100% rename from internal/reql_tests/reql_datum_object_test.go rename to internal/integration/reql_tests/reql_datum_object_test.go diff --git a/internal/reql_tests/reql_datum_string_test.go b/internal/integration/reql_tests/reql_datum_string_test.go similarity index 100% rename from internal/reql_tests/reql_datum_string_test.go rename to internal/integration/reql_tests/reql_datum_string_test.go diff --git a/internal/reql_tests/reql_datum_typeof_test.go b/internal/integration/reql_tests/reql_datum_typeof_test.go similarity index 100% rename from internal/reql_tests/reql_datum_typeof_test.go rename to internal/integration/reql_tests/reql_datum_typeof_test.go diff --git a/internal/reql_tests/reql_datum_uuid_test.go b/internal/integration/reql_tests/reql_datum_uuid_test.go similarity index 100% rename from internal/reql_tests/reql_datum_uuid_test.go rename to internal/integration/reql_tests/reql_datum_uuid_test.go diff --git a/internal/reql_tests/reql_default_test.go b/internal/integration/reql_tests/reql_default_test.go similarity index 100% rename from internal/reql_tests/reql_default_test.go rename to internal/integration/reql_tests/reql_default_test.go diff --git a/internal/reql_tests/reql_geo_constructors_test.go b/internal/integration/reql_tests/reql_geo_constructors_test.go similarity index 100% rename from internal/reql_tests/reql_geo_constructors_test.go rename to internal/integration/reql_tests/reql_geo_constructors_test.go diff --git a/internal/reql_tests/reql_geo_geojson_test.go b/internal/integration/reql_tests/reql_geo_geojson_test.go similarity index 100% rename from internal/reql_tests/reql_geo_geojson_test.go rename to internal/integration/reql_tests/reql_geo_geojson_test.go diff --git a/internal/reql_tests/reql_geo_indexing_test.go b/internal/integration/reql_tests/reql_geo_indexing_test.go similarity index 100% rename from internal/reql_tests/reql_geo_indexing_test.go rename to internal/integration/reql_tests/reql_geo_indexing_test.go diff --git a/internal/reql_tests/reql_geo_intersection_inclusion_test.go b/internal/integration/reql_tests/reql_geo_intersection_inclusion_test.go similarity index 100% rename from internal/reql_tests/reql_geo_intersection_inclusion_test.go rename to internal/integration/reql_tests/reql_geo_intersection_inclusion_test.go diff --git a/internal/reql_tests/reql_geo_operations_test.go b/internal/integration/reql_tests/reql_geo_operations_test.go similarity index 100% rename from internal/reql_tests/reql_geo_operations_test.go rename to internal/integration/reql_tests/reql_geo_operations_test.go diff --git a/internal/reql_tests/reql_geo_primitives_test.go b/internal/integration/reql_tests/reql_geo_primitives_test.go similarity index 100% rename from internal/reql_tests/reql_geo_primitives_test.go rename to internal/integration/reql_tests/reql_geo_primitives_test.go diff --git a/internal/reql_tests/reql_joins_test.go b/internal/integration/reql_tests/reql_joins_test.go similarity index 100% rename from internal/reql_tests/reql_joins_test.go rename to internal/integration/reql_tests/reql_joins_test.go diff --git a/internal/reql_tests/reql_json_test.go b/internal/integration/reql_tests/reql_json_test.go similarity index 100% rename from internal/reql_tests/reql_json_test.go rename to internal/integration/reql_tests/reql_json_test.go diff --git a/internal/reql_tests/reql_match_test.go b/internal/integration/reql_tests/reql_match_test.go similarity index 100% rename from internal/reql_tests/reql_match_test.go rename to internal/integration/reql_tests/reql_match_test.go diff --git a/internal/reql_tests/reql_math_logic_add_test.go b/internal/integration/reql_tests/reql_math_logic_add_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_add_test.go rename to internal/integration/reql_tests/reql_math_logic_add_test.go diff --git a/internal/reql_tests/reql_math_logic_aliases_test.go b/internal/integration/reql_tests/reql_math_logic_aliases_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_aliases_test.go rename to internal/integration/reql_tests/reql_math_logic_aliases_test.go diff --git a/internal/reql_tests/reql_math_logic_comparison_test.go b/internal/integration/reql_tests/reql_math_logic_comparison_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_comparison_test.go rename to internal/integration/reql_tests/reql_math_logic_comparison_test.go diff --git a/internal/reql_tests/reql_math_logic_div_test.go b/internal/integration/reql_tests/reql_math_logic_div_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_div_test.go rename to internal/integration/reql_tests/reql_math_logic_div_test.go diff --git a/internal/reql_tests/reql_math_logic_floor_ceil_round_test.go b/internal/integration/reql_tests/reql_math_logic_floor_ceil_round_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_floor_ceil_round_test.go rename to internal/integration/reql_tests/reql_math_logic_floor_ceil_round_test.go diff --git a/internal/reql_tests/reql_math_logic_logic_test.go b/internal/integration/reql_tests/reql_math_logic_logic_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_logic_test.go rename to internal/integration/reql_tests/reql_math_logic_logic_test.go diff --git a/internal/reql_tests/reql_math_logic_math_test.go b/internal/integration/reql_tests/reql_math_logic_math_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_math_test.go rename to internal/integration/reql_tests/reql_math_logic_math_test.go diff --git a/internal/reql_tests/reql_math_logic_mod_test.go b/internal/integration/reql_tests/reql_math_logic_mod_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_mod_test.go rename to internal/integration/reql_tests/reql_math_logic_mod_test.go diff --git a/internal/reql_tests/reql_math_logic_mul_test.go b/internal/integration/reql_tests/reql_math_logic_mul_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_mul_test.go rename to internal/integration/reql_tests/reql_math_logic_mul_test.go diff --git a/internal/reql_tests/reql_math_logic_sub_test.go b/internal/integration/reql_tests/reql_math_logic_sub_test.go similarity index 100% rename from internal/reql_tests/reql_math_logic_sub_test.go rename to internal/integration/reql_tests/reql_math_logic_sub_test.go diff --git a/internal/reql_tests/reql_meta_composite_test.go b/internal/integration/reql_tests/reql_meta_composite_test.go similarity index 100% rename from internal/reql_tests/reql_meta_composite_test.go rename to internal/integration/reql_tests/reql_meta_composite_test.go diff --git a/internal/reql_tests/reql_meta_dbs_test.go b/internal/integration/reql_tests/reql_meta_dbs_test.go similarity index 100% rename from internal/reql_tests/reql_meta_dbs_test.go rename to internal/integration/reql_tests/reql_meta_dbs_test.go diff --git a/internal/reql_tests/reql_meta_table_test.go b/internal/integration/reql_tests/reql_meta_table_test.go similarity index 100% rename from internal/reql_tests/reql_meta_table_test.go rename to internal/integration/reql_tests/reql_meta_table_test.go diff --git a/internal/reql_tests/reql_mutation_atomic_get_set_test.go b/internal/integration/reql_tests/reql_mutation_atomic_get_set_test.go similarity index 100% rename from internal/reql_tests/reql_mutation_atomic_get_set_test.go rename to internal/integration/reql_tests/reql_mutation_atomic_get_set_test.go diff --git a/internal/reql_tests/reql_mutation_delete_test.go b/internal/integration/reql_tests/reql_mutation_delete_test.go similarity index 100% rename from internal/reql_tests/reql_mutation_delete_test.go rename to internal/integration/reql_tests/reql_mutation_delete_test.go diff --git a/internal/reql_tests/reql_mutation_insert_test.go b/internal/integration/reql_tests/reql_mutation_insert_test.go similarity index 100% rename from internal/reql_tests/reql_mutation_insert_test.go rename to internal/integration/reql_tests/reql_mutation_insert_test.go diff --git a/internal/reql_tests/reql_mutation_replace_test.go b/internal/integration/reql_tests/reql_mutation_replace_test.go similarity index 100% rename from internal/reql_tests/reql_mutation_replace_test.go rename to internal/integration/reql_tests/reql_mutation_replace_test.go diff --git a/internal/reql_tests/reql_mutation_sync_test.go b/internal/integration/reql_tests/reql_mutation_sync_test.go similarity index 100% rename from internal/reql_tests/reql_mutation_sync_test.go rename to internal/integration/reql_tests/reql_mutation_sync_test.go diff --git a/internal/reql_tests/reql_mutation_update_test.go b/internal/integration/reql_tests/reql_mutation_update_test.go similarity index 100% rename from internal/reql_tests/reql_mutation_update_test.go rename to internal/integration/reql_tests/reql_mutation_update_test.go diff --git a/internal/reql_tests/reql_polymorphism_test.go b/internal/integration/reql_tests/reql_polymorphism_test.go similarity index 100% rename from internal/reql_tests/reql_polymorphism_test.go rename to internal/integration/reql_tests/reql_polymorphism_test.go diff --git a/internal/reql_tests/reql_random_test.go b/internal/integration/reql_tests/reql_random_test.go similarity index 100% rename from internal/reql_tests/reql_random_test.go rename to internal/integration/reql_tests/reql_random_test.go diff --git a/internal/reql_tests/reql_range_test.go b/internal/integration/reql_tests/reql_range_test.go similarity index 100% rename from internal/reql_tests/reql_range_test.go rename to internal/integration/reql_tests/reql_range_test.go diff --git a/internal/reql_tests/reql_selection_test.go b/internal/integration/reql_tests/reql_selection_test.go similarity index 100% rename from internal/reql_tests/reql_selection_test.go rename to internal/integration/reql_tests/reql_selection_test.go diff --git a/internal/reql_tests/reql_sindex_api_test.go b/internal/integration/reql_tests/reql_sindex_api_test.go similarity index 100% rename from internal/reql_tests/reql_sindex_api_test.go rename to internal/integration/reql_tests/reql_sindex_api_test.go diff --git a/internal/reql_tests/reql_sindex_nullsinstrings_test.go b/internal/integration/reql_tests/reql_sindex_nullsinstrings_test.go similarity index 100% rename from internal/reql_tests/reql_sindex_nullsinstrings_test.go rename to internal/integration/reql_tests/reql_sindex_nullsinstrings_test.go diff --git a/internal/reql_tests/reql_sindex_status_test.go b/internal/integration/reql_tests/reql_sindex_status_test.go similarity index 100% rename from internal/reql_tests/reql_sindex_status_test.go rename to internal/integration/reql_tests/reql_sindex_status_test.go diff --git a/internal/reql_tests/reql_timeout_test.go b/internal/integration/reql_tests/reql_timeout_test.go similarity index 100% rename from internal/reql_tests/reql_timeout_test.go rename to internal/integration/reql_tests/reql_timeout_test.go diff --git a/internal/reql_tests/reql_times_api_test.go b/internal/integration/reql_tests/reql_times_api_test.go similarity index 100% rename from internal/reql_tests/reql_times_api_test.go rename to internal/integration/reql_tests/reql_times_api_test.go diff --git a/internal/reql_tests/reql_times_constructors_test.go b/internal/integration/reql_tests/reql_times_constructors_test.go similarity index 100% rename from internal/reql_tests/reql_times_constructors_test.go rename to internal/integration/reql_tests/reql_times_constructors_test.go diff --git a/internal/reql_tests/reql_times_index_test.go b/internal/integration/reql_tests/reql_times_index_test.go similarity index 100% rename from internal/reql_tests/reql_times_index_test.go rename to internal/integration/reql_tests/reql_times_index_test.go diff --git a/internal/reql_tests/reql_times_portions_test.go b/internal/integration/reql_tests/reql_times_portions_test.go similarity index 100% rename from internal/reql_tests/reql_times_portions_test.go rename to internal/integration/reql_tests/reql_times_portions_test.go diff --git a/internal/reql_tests/reql_times_shim_test.go b/internal/integration/reql_tests/reql_times_shim_test.go similarity index 100% rename from internal/reql_tests/reql_times_shim_test.go rename to internal/integration/reql_tests/reql_times_shim_test.go diff --git a/internal/reql_tests/reql_times_time_arith_test.go b/internal/integration/reql_tests/reql_times_time_arith_test.go similarity index 100% rename from internal/reql_tests/reql_times_time_arith_test.go rename to internal/integration/reql_tests/reql_times_time_arith_test.go diff --git a/internal/reql_tests/reql_times_timezones_test.go b/internal/integration/reql_tests/reql_times_timezones_test.go similarity index 100% rename from internal/reql_tests/reql_times_timezones_test.go rename to internal/integration/reql_tests/reql_times_timezones_test.go diff --git a/internal/reql_tests/reql_transform_array_test.go b/internal/integration/reql_tests/reql_transform_array_test.go similarity index 100% rename from internal/reql_tests/reql_transform_array_test.go rename to internal/integration/reql_tests/reql_transform_array_test.go diff --git a/internal/reql_tests/reql_transform_fold_test.go b/internal/integration/reql_tests/reql_transform_fold_test.go similarity index 100% rename from internal/reql_tests/reql_transform_fold_test.go rename to internal/integration/reql_tests/reql_transform_fold_test.go diff --git a/internal/reql_tests/reql_transform_map_test.go b/internal/integration/reql_tests/reql_transform_map_test.go similarity index 100% rename from internal/reql_tests/reql_transform_map_test.go rename to internal/integration/reql_tests/reql_transform_map_test.go diff --git a/internal/reql_tests/reql_transform_object_test.go b/internal/integration/reql_tests/reql_transform_object_test.go similarity index 100% rename from internal/reql_tests/reql_transform_object_test.go rename to internal/integration/reql_tests/reql_transform_object_test.go diff --git a/internal/reql_tests/reql_transform_table_test.go b/internal/integration/reql_tests/reql_transform_table_test.go similarity index 100% rename from internal/reql_tests/reql_transform_table_test.go rename to internal/integration/reql_tests/reql_transform_table_test.go diff --git a/internal/reql_tests/reql_transform_unordered_map_test.go b/internal/integration/reql_tests/reql_transform_unordered_map_test.go similarity index 100% rename from internal/reql_tests/reql_transform_unordered_map_test.go rename to internal/integration/reql_tests/reql_transform_unordered_map_test.go diff --git a/internal/reql_tests/reql_transformation_test.go b/internal/integration/reql_tests/reql_transformation_test.go similarity index 100% rename from internal/reql_tests/reql_transformation_test.go rename to internal/integration/reql_tests/reql_transformation_test.go diff --git a/internal/reql_tests/template.go.tpl b/internal/integration/reql_tests/template.go.tpl similarity index 100% rename from internal/reql_tests/template.go.tpl rename to internal/integration/reql_tests/template.go.tpl diff --git a/benchmarks_test.go b/internal/integration/tests/benchmarks_test.go similarity index 72% rename from benchmarks_test.go rename to internal/integration/tests/benchmarks_test.go index e01ba0d0..90549165 100644 --- a/benchmarks_test.go +++ b/internal/integration/tests/benchmarks_test.go @@ -1,4 +1,4 @@ -package gorethink +package tests import ( "math/rand" @@ -6,11 +6,12 @@ import ( "sync" "testing" "time" + r "gopkg.in/gorethink/gorethink.v3" ) func BenchmarkBatch200RandomWrites(b *testing.B) { - var term Term + var term r.Term var data []map[string]interface{} for i := 0; i < b.N; i++ { @@ -24,10 +25,10 @@ func BenchmarkBatch200RandomWrites(b *testing.B) { } // Insert the new item into the database - term = DB("benchmarks").Table("benchmarks").Insert(data) + term = r.DB("benchmarks").Table("benchmarks").Insert(data) // Insert the new item into the database - _, err := term.RunWrite(session, RunOpts{ + _, err := term.RunWrite(session, r.RunOpts{ MinBatchRows: 200, MaxBatchRows: 200, }) @@ -40,7 +41,7 @@ func BenchmarkBatch200RandomWrites(b *testing.B) { func BenchmarkBatch200RandomWritesParallel10(b *testing.B) { - var term Term + var term r.Term var data []map[string]interface{} b.SetParallelism(10) @@ -57,10 +58,10 @@ func BenchmarkBatch200RandomWritesParallel10(b *testing.B) { } // Insert the new item into the database - term = DB("benchmarks").Table("benchmarks").Insert(data) + term = r.DB("benchmarks").Table("benchmarks").Insert(data) // Insert the new item into the database - _, err := term.RunWrite(session, RunOpts{ + _, err := term.RunWrite(session, r.RunOpts{ MinBatchRows: 200, MaxBatchRows: 200, }) @@ -74,7 +75,7 @@ func BenchmarkBatch200RandomWritesParallel10(b *testing.B) { func BenchmarkBatch200SoftRandomWritesParallel10(b *testing.B) { - var term Term + var term r.Term var data []map[string]interface{} b.SetParallelism(10) @@ -83,7 +84,7 @@ func BenchmarkBatch200SoftRandomWritesParallel10(b *testing.B) { for pb.Next() { - opts := InsertOpts{Durability: "soft"} + opts := r.InsertOpts{Durability: "soft"} for is := 0; is < 200; is++ { r := rand.New(rand.NewSource(time.Now().UnixNano())) @@ -94,10 +95,10 @@ func BenchmarkBatch200SoftRandomWritesParallel10(b *testing.B) { } // Insert the new item into the database - term = DB("benchmarks").Table("benchmarks").Insert(data, opts) + term = r.DB("benchmarks").Table("benchmarks").Insert(data, opts) // Insert the new item into the database - _, err := term.RunWrite(session, RunOpts{ + _, err := term.RunWrite(session, r.RunOpts{ MinBatchRows: 200, MaxBatchRows: 200, }) @@ -112,12 +113,12 @@ func BenchmarkBatch200SoftRandomWritesParallel10(b *testing.B) { func BenchmarkRandomWrites(b *testing.B) { for i := 0; i < b.N; i++ { - r := rand.New(rand.NewSource(time.Now().UnixNano())) + ra := rand.New(rand.NewSource(time.Now().UnixNano())) data := map[string]interface{}{ - "customer_id": strconv.FormatInt(r.Int63(), 10), + "customer_id": strconv.FormatInt(ra.Int63(), 10), } // Insert the new item into the database - _, err := DB("benchmarks").Table("benchmarks").Insert(data).RunWrite(session) + _, err := r.DB("benchmarks").Table("benchmarks").Insert(data).RunWrite(session) if err != nil { b.Errorf("insert failed [%s] ", err) } @@ -132,12 +133,12 @@ func BenchmarkRandomWritesParallel10(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { - r := rand.New(rand.NewSource(time.Now().UnixNano())) + ra := rand.New(rand.NewSource(time.Now().UnixNano())) data := map[string]interface{}{ - "customer_id": strconv.FormatInt(r.Int63(), 10), + "customer_id": strconv.FormatInt(ra.Int63(), 10), } // Insert the new item into the database - _, err := DB("benchmarks").Table("benchmarks").Insert(data).RunWrite(session) + _, err := r.DB("benchmarks").Table("benchmarks").Insert(data).RunWrite(session) if err != nil { b.Errorf("insert failed [%s] ", err) } @@ -153,8 +154,8 @@ func BenchmarkRandomSoftWrites(b *testing.B) { "customer_id": strconv.FormatInt(rand.Int63(), 10), } // Insert the new item into the database - opts := InsertOpts{Durability: "soft"} - _, err := DB("benchmarks").Table("benchmarks").Insert(data, opts).RunWrite(session) + opts := r.InsertOpts{Durability: "soft"} + _, err := r.DB("benchmarks").Table("benchmarks").Insert(data, opts).RunWrite(session) if err != nil { b.Errorf("insert failed [%s] ", err) } @@ -169,14 +170,14 @@ func BenchmarkRandomSoftWritesParallel10(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { - r := rand.New(rand.NewSource(time.Now().UnixNano())) + ra := rand.New(rand.NewSource(time.Now().UnixNano())) data := map[string]interface{}{ - "customer_id": strconv.FormatInt(r.Int63(), 10), + "customer_id": strconv.FormatInt(ra.Int63(), 10), } // Insert the new item into the database - opts := InsertOpts{Durability: "soft"} - _, err := DB("benchmarks").Table("benchmarks").Insert(data, opts).RunWrite(session) + opts := r.InsertOpts{Durability: "soft"} + _, err := r.DB("benchmarks").Table("benchmarks").Insert(data, opts).RunWrite(session) if err != nil { b.Errorf("insert failed [%s] ", err) } @@ -195,7 +196,7 @@ func BenchmarkSequentialWrites(b *testing.B) { } // Insert the new item into the database - _, err := DB("benchmarks").Table("benchmarks").Insert(data).RunWrite(session) + _, err := r.DB("benchmarks").Table("benchmarks").Insert(data).RunWrite(session) if err != nil { b.Errorf("insert failed [%s] ", err) return @@ -222,7 +223,7 @@ func BenchmarkSequentialWritesParallel10(b *testing.B) { } // Insert the new item into the database - _, err := DB("benchmarks").Table("benchmarks").Insert(data).RunWrite(session) + _, err := r.DB("benchmarks").Table("benchmarks").Insert(data).RunWrite(session) if err != nil { b.Errorf("insert failed [%s] ", err) return @@ -234,7 +235,7 @@ func BenchmarkSequentialWritesParallel10(b *testing.B) { func BenchmarkSequentialSoftWrites(b *testing.B) { - opts := InsertOpts{Durability: "soft"} + opts := r.InsertOpts{Durability: "soft"} si := 0 for i := 0; i < b.N; i++ { @@ -244,7 +245,7 @@ func BenchmarkSequentialSoftWrites(b *testing.B) { } // Insert the new item into the database - _, err := Table("benchmarks").Insert(data, opts).RunWrite(session) + _, err := r.Table("benchmarks").Insert(data, opts).RunWrite(session) if err != nil { b.Errorf("insert failed [%s] ", err) return @@ -270,10 +271,10 @@ func BenchmarkSequentialSoftWritesParallel10(b *testing.B) { "customer_id": si, } - opts := InsertOpts{Durability: "soft"} + opts := r.InsertOpts{Durability: "soft"} // Insert the new item into the database - _, err := Table("benchmarks").Insert(data, opts).RunWrite(session) + _, err := r.Table("benchmarks").Insert(data, opts).RunWrite(session) if err != nil { b.Errorf("insert failed [%s] ", err) return diff --git a/checkers_test.go b/internal/integration/tests/checkers.go similarity index 96% rename from checkers_test.go rename to internal/integration/tests/checkers.go index baca1b1a..4d56cac1 100644 --- a/checkers_test.go +++ b/internal/integration/tests/checkers.go @@ -1,4 +1,4 @@ -package gorethink +package tests import ( "encoding/json" @@ -25,10 +25,10 @@ func (j jsonChecker) Check(params []interface{}, names []string) (result bool, e return test.DeepEquals.Check(jsonParams, names) } -// jsonEquals compares two interface{} objects by converting them to JSON and +// JsonEquals compares two interface{} objects by converting them to JSON and // seeing if the strings match -var jsonEquals = &jsonChecker{ - &test.CheckerInfo{Name: "jsonEquals", Params: []string{"obtained", "expected"}}, +var JsonEquals = &jsonChecker{ + &test.CheckerInfo{Name: "JsonEquals", Params: []string{"obtained", "expected"}}, } type geometryChecker struct { diff --git a/cluster_integration_test.go b/internal/integration/tests/cluster_integration_test.go similarity index 99% rename from cluster_integration_test.go rename to internal/integration/tests/cluster_integration_test.go index 929a235b..93b1ddb6 100644 --- a/cluster_integration_test.go +++ b/internal/integration/tests/cluster_integration_test.go @@ -1,7 +1,7 @@ // +build cluster // +build integration -package gorethink +package tests import ( "time" diff --git a/cluster_test.go b/internal/integration/tests/cluster_test.go similarity index 98% rename from cluster_test.go rename to internal/integration/tests/cluster_test.go index 38c6d34e..a9a39805 100644 --- a/cluster_test.go +++ b/internal/integration/tests/cluster_test.go @@ -1,6 +1,6 @@ // +build cluster -package gorethink +package tests import ( "fmt" diff --git a/cursor_test.go b/internal/integration/tests/cursor_test.go similarity index 76% rename from cursor_test.go rename to internal/integration/tests/cursor_test.go index a9f3e2b7..ba59cb81 100644 --- a/cursor_test.go +++ b/internal/integration/tests/cursor_test.go @@ -1,10 +1,11 @@ -package gorethink +package tests import ( "fmt" "time" test "gopkg.in/check.v1" + r "gopkg.in/gorethink/gorethink.v3" ) type object struct { @@ -19,29 +20,29 @@ type attr struct { } func (s *RethinkSuite) TestCursorLiteral(c *test.C) { - res, err := Expr(5).Run(session) + res, err := r.Expr(5).Run(session) c.Assert(err, test.IsNil) c.Assert(res.Type(), test.Equals, "Cursor") var response interface{} err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, 5) + c.Assert(response, JsonEquals, 5) } func (s *RethinkSuite) TestCursorSlice(c *test.C) { - res, err := Expr([]interface{}{1, 2, 3, 4, 5}).Run(session) + res, err := r.Expr([]interface{}{1, 2, 3, 4, 5}).Run(session) c.Assert(err, test.IsNil) c.Assert(res.Type(), test.Equals, "Cursor") var response []interface{} err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []interface{}{1, 2, 3, 4, 5}) + c.Assert(response, JsonEquals, []interface{}{1, 2, 3, 4, 5}) } func (s *RethinkSuite) TestCursorPartiallyNilSlice(c *test.C) { - res, err := Expr(map[string]interface{}{ + res, err := r.Expr(map[string]interface{}{ "item": []interface{}{ map[string]interface{}{"num": 1}, nil, @@ -53,7 +54,7 @@ func (s *RethinkSuite) TestCursorPartiallyNilSlice(c *test.C) { var response map[string]interface{} err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{ + c.Assert(response, JsonEquals, map[string]interface{}{ "item": []interface{}{ map[string]interface{}{"num": 1}, nil, @@ -62,7 +63,7 @@ func (s *RethinkSuite) TestCursorPartiallyNilSlice(c *test.C) { } func (s *RethinkSuite) TestCursorMap(c *test.C) { - res, err := Expr(map[string]interface{}{ + res, err := r.Expr(map[string]interface{}{ "id": 2, "name": "Object 1", }).Run(session) @@ -72,14 +73,14 @@ func (s *RethinkSuite) TestCursorMap(c *test.C) { var response map[string]interface{} err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{ + c.Assert(response, JsonEquals, map[string]interface{}{ "id": 2, "name": "Object 1", }) } func (s *RethinkSuite) TestCursorMapIntoInterface(c *test.C) { - res, err := Expr(map[string]interface{}{ + res, err := r.Expr(map[string]interface{}{ "id": 2, "name": "Object 1", }).Run(session) @@ -89,14 +90,14 @@ func (s *RethinkSuite) TestCursorMapIntoInterface(c *test.C) { var response interface{} err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{ + c.Assert(response, JsonEquals, map[string]interface{}{ "id": 2, "name": "Object 1", }) } func (s *RethinkSuite) TestCursorMapNested(c *test.C) { - res, err := Expr(map[string]interface{}{ + res, err := r.Expr(map[string]interface{}{ "id": 2, "name": "Object 1", "attr": []interface{}{map[string]interface{}{ @@ -110,7 +111,7 @@ func (s *RethinkSuite) TestCursorMapNested(c *test.C) { var response interface{} err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{ + c.Assert(response, JsonEquals, map[string]interface{}{ "id": 2, "name": "Object 1", "attr": []interface{}{map[string]interface{}{ @@ -121,7 +122,7 @@ func (s *RethinkSuite) TestCursorMapNested(c *test.C) { } func (s *RethinkSuite) TestCursorStruct(c *test.C) { - res, err := Expr(map[string]interface{}{ + res, err := r.Expr(map[string]interface{}{ "id": 2, "name": "Object 1", "Attrs": []interface{}{map[string]interface{}{ @@ -149,7 +150,7 @@ func (s *RethinkSuite) TestCursorStructPseudoTypes(c *test.C) { var zeroTime time.Time t := time.Now() - res, err := Expr(map[string]interface{}{ + res, err := r.Expr(map[string]interface{}{ "T": time.Unix(t.Unix(), 0).In(time.UTC), "Z": zeroTime, "B": []byte("hello"), @@ -163,11 +164,11 @@ func (s *RethinkSuite) TestCursorStructPseudoTypes(c *test.C) { c.Assert(response.T.Equal(time.Unix(t.Unix(), 0)), test.Equals, true) c.Assert(response.Z.Equal(zeroTime), test.Equals, true) - c.Assert(response.B, jsonEquals, []byte("hello")) + c.Assert(response.B, JsonEquals, []byte("hello")) } func (s *RethinkSuite) TestCursorAtomString(c *test.C) { - res, err := Expr("a").Run(session) + res, err := r.Expr("a").Run(session) c.Assert(err, test.IsNil) c.Assert(res.Type(), test.Equals, "Cursor") @@ -178,7 +179,7 @@ func (s *RethinkSuite) TestCursorAtomString(c *test.C) { } func (s *RethinkSuite) TestCursorAtomArray(c *test.C) { - res, err := Expr([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}).Run(session) + res, err := r.Expr([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}).Run(session) c.Assert(err, test.IsNil) c.Assert(res.Type(), test.Equals, "Cursor") @@ -189,40 +190,40 @@ func (s *RethinkSuite) TestCursorAtomArray(c *test.C) { } func (s *RethinkSuite) TestEmptyResults(c *test.C) { - DBCreate("test").Exec(session) - DB("test").TableCreate("test").Exec(session) - res, err := DB("test").Table("test").Get("missing value").Run(session) + r.DBCreate("test").Exec(session) + r.DB("test").TableCreate("test").Exec(session) + res, err := r.DB("test").Table("test").Get("missing value").Run(session) c.Assert(err, test.IsNil) c.Assert(res.IsNil(), test.Equals, true) - res, err = DB("test").Table("test").Get("missing value").Run(session) + res, err = r.DB("test").Table("test").Get("missing value").Run(session) c.Assert(err, test.IsNil) var response interface{} err = res.One(&response) - c.Assert(err, test.Equals, ErrEmptyResult) + c.Assert(err, test.Equals, r.ErrEmptyResult) c.Assert(res.IsNil(), test.Equals, true) - res, err = Expr(nil).Run(session) + res, err = r.Expr(nil).Run(session) c.Assert(err, test.IsNil) c.Assert(res.IsNil(), test.Equals, true) - res, err = DB("test").Table("test").Get("missing value").Run(session) + res, err = r.DB("test").Table("test").Get("missing value").Run(session) c.Assert(err, test.IsNil) c.Assert(res.IsNil(), test.Equals, true) - res, err = DB("test").Table("test").GetAll("missing value", "another missing value").Run(session) + res, err = r.DB("test").Table("test").GetAll("missing value", "another missing value").Run(session) c.Assert(err, test.IsNil) c.Assert(res.Next(&response), test.Equals, false) var obj object obj.Name = "missing value" - res, err = DB("test").Table("test").Filter(obj).Run(session) + res, err = r.DB("test").Table("test").Filter(obj).Run(session) c.Assert(err, test.IsNil) c.Assert(res.IsNil(), test.Equals, true) var objP *object - res, err = DB("test").Table("test").Get("missing value").Run(session) + res, err = r.DB("test").Table("test").Get("missing value").Run(session) res.Next(&objP) c.Assert(err, test.IsNil) c.Assert(objP, test.IsNil) @@ -230,14 +231,14 @@ func (s *RethinkSuite) TestEmptyResults(c *test.C) { func (s *RethinkSuite) TestCursorAll(c *test.C) { // Ensure table + database exist - DBCreate("test").Exec(session) - DB("test").TableDrop("Table3").Exec(session) - DB("test").TableCreate("Table3").Exec(session) - DB("test").Table("Table3").IndexCreate("num").Exec(session) - DB("test").Table("Table3").IndexWait().Exec(session) + r.DBCreate("test").Exec(session) + r.DB("test").TableDrop("Table3").Exec(session) + r.DB("test").TableCreate("Table3").Exec(session) + r.DB("test").Table("Table3").IndexCreate("num").Exec(session) + r.DB("test").Table("Table3").IndexWait().Exec(session) // Insert rows - DB("test").Table("Table3").Insert([]interface{}{ + r.DB("test").Table("Table3").Insert([]interface{}{ map[string]interface{}{ "id": 2, "name": "Object 1", @@ -257,7 +258,7 @@ func (s *RethinkSuite) TestCursorAll(c *test.C) { }).Exec(session) // Test query - query := DB("test").Table("Table3").OrderBy("id") + query := r.DB("test").Table("Table3").OrderBy("id") res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -287,15 +288,15 @@ func (s *RethinkSuite) TestCursorAll(c *test.C) { func (s *RethinkSuite) TestCursorListen(c *test.C) { // Ensure table + database exist - DBCreate("test").Exec(session) - DB("test").TableDrop("Table3").Exec(session) - DB("test").TableCreate("Table3").Exec(session) - DB("test").Table("Table3").Wait().Exec(session) - DB("test").Table("Table3").IndexCreate("num").Exec(session) - DB("test").Table("Table3").IndexWait().Exec(session) + r.DBCreate("test").Exec(session) + r.DB("test").TableDrop("Table3").Exec(session) + r.DB("test").TableCreate("Table3").Exec(session) + r.DB("test").Table("Table3").Wait().Exec(session) + r.DB("test").Table("Table3").IndexCreate("num").Exec(session) + r.DB("test").Table("Table3").IndexWait().Exec(session) // Insert rows - DB("test").Table("Table3").Insert([]interface{}{ + r.DB("test").Table("Table3").Insert([]interface{}{ map[string]interface{}{ "id": 2, "name": "Object 1", @@ -315,7 +316,7 @@ func (s *RethinkSuite) TestCursorListen(c *test.C) { }).Exec(session) // Test query - query := DB("test").Table("Table3").OrderBy("id") + query := r.DB("test").Table("Table3").OrderBy("id") res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -349,13 +350,13 @@ func (s *RethinkSuite) TestCursorListen(c *test.C) { func (s *RethinkSuite) TestCursorChangesClose(c *test.C) { // Ensure table + database exist - DBCreate("test").Exec(session) - DB("test").TableDrop("Table3").Exec(session) - DB("test").TableCreate("Table3").Exec(session) + r.DBCreate("test").Exec(session) + r.DB("test").TableDrop("Table3").Exec(session) + r.DB("test").TableCreate("Table3").Exec(session) // Test query // res, err := DB("test").Table("Table3").Changes().Run(session) - res, err := DB("test").Table("Table3").Changes().Run(session) + res, err := r.DB("test").Table("Table3").Changes().Run(session) c.Assert(err, test.IsNil) c.Assert(res, test.NotNil) @@ -366,7 +367,7 @@ func (s *RethinkSuite) TestCursorChangesClose(c *test.C) { func (s *RethinkSuite) TestCursorReuseResult(c *test.C) { // Test query - query := Expr([]interface{}{ + query := r.Expr([]interface{}{ map[string]interface{}{ "A": "a", }, @@ -426,27 +427,27 @@ func (s *RethinkSuite) TestCursorReuseResult(c *test.C) { } func (s *RethinkSuite) TestCursorNextResponse(c *test.C) { - res, err := Expr(5).Run(session) + res, err := r.Expr(5).Run(session) c.Assert(err, test.IsNil) c.Assert(res.Type(), test.Equals, "Cursor") b, ok := res.NextResponse() c.Assert(ok, test.Equals, true) - c.Assert(b, jsonEquals, []byte(`5`)) + c.Assert(b, JsonEquals, []byte(`5`)) } func (s *RethinkSuite) TestCursorNextResponse_object(c *test.C) { - res, err := Expr(map[string]string{"foo": "bar"}).Run(session) + res, err := r.Expr(map[string]string{"foo": "bar"}).Run(session) c.Assert(err, test.IsNil) c.Assert(res.Type(), test.Equals, "Cursor") b, ok := res.NextResponse() c.Assert(ok, test.Equals, true) - c.Assert(b, jsonEquals, []byte(`{"foo":"bar"}`)) + c.Assert(b, JsonEquals, []byte(`{"foo":"bar"}`)) } func (s *RethinkSuite) TestCursorPeek_idempotency(c *test.C) { - res, err := Expr([]int{1, 2, 3}).Run(session) + res, err := r.Expr([]int{1, 2, 3}).Run(session) c.Assert(err, test.IsNil) var result int @@ -462,7 +463,7 @@ func (s *RethinkSuite) TestCursorPeek_idempotency(c *test.C) { } func (s *RethinkSuite) TestCursorPeek_wrong_type(c *test.C) { - res, err := Expr([]int{1, 2, 3}).Run(session) + res, err := r.Expr([]int{1, 2, 3}).Run(session) c.Assert(err, test.IsNil) // Test that wrongType doesn't break the cursor @@ -478,7 +479,7 @@ func (s *RethinkSuite) TestCursorPeek_wrong_type(c *test.C) { } func (s *RethinkSuite) TestCursorPeek_usage(c *test.C) { - res, err := Expr([]int{1, 2, 3}).Run(session) + res, err := r.Expr([]int{1, 2, 3}).Run(session) c.Assert(err, test.IsNil) var result int @@ -497,7 +498,7 @@ func (s *RethinkSuite) TestCursorPeek_usage(c *test.C) { } func (s *RethinkSuite) TestCursorSkip(c *test.C) { - res, err := Expr([]int{1, 2, 3}).Run(session) + res, err := r.Expr([]int{1, 2, 3}).Run(session) c.Assert(err, test.IsNil) res.Skip() @@ -509,7 +510,7 @@ func (s *RethinkSuite) TestCursorSkip(c *test.C) { } func ExampleCursor_Peek() { - res, err := Expr([]int{1, 2, 3}).Run(session) + res, err := r.Expr([]int{1, 2, 3}).Run(session) if err != nil { fmt.Print(err) return diff --git a/example_connect_test.go b/internal/integration/tests/example_connect_test.go similarity index 61% rename from example_connect_test.go rename to internal/integration/tests/example_connect_test.go index 18ce3050..5f83f281 100644 --- a/example_connect_test.go +++ b/internal/integration/tests/example_connect_test.go @@ -1,4 +1,4 @@ -package gorethink_test +package tests import ( "log" @@ -7,22 +7,22 @@ import ( r "gopkg.in/gorethink/gorethink.v3" ) -var session *r.Session -var url string +var sessionEx *r.Session +var urlEx string func init() { // If the test is being run by wercker look for the rethink url - url = os.Getenv("RETHINKDB_URL") - if url == "" { - url = "localhost:28015" + urlEx = os.Getenv("RETHINKDB_URL") + if urlEx == "" { + urlEx = "localhost:28015" } } func ExampleConnect() { var err error - session, err = r.Connect(r.ConnectOpts{ - Address: url, + sessionEx, err = r.Connect(r.ConnectOpts{ + Address: urlEx, }) if err != nil { log.Fatalln(err.Error()) @@ -32,8 +32,8 @@ func ExampleConnect() { func ExampleConnect_connectionPool() { var err error - session, err = r.Connect(r.ConnectOpts{ - Address: url, + sessionEx, err = r.Connect(r.ConnectOpts{ + Address: urlEx, InitialCap: 10, MaxOpen: 10, }) @@ -45,8 +45,8 @@ func ExampleConnect_connectionPool() { func ExampleConnect_cluster() { var err error - session, err = r.Connect(r.ConnectOpts{ - Addresses: []string{url}, + sessionEx, err = r.Connect(r.ConnectOpts{ + Addresses: []string{urlEx}, // Addresses: []string{url1, url2, url3, ...}, }) if err != nil { diff --git a/example_query_aggregation_test.go b/internal/integration/tests/example_query_aggregation_test.go similarity index 74% rename from example_query_aggregation_test.go rename to internal/integration/tests/example_query_aggregation_test.go index 1e616c7a..2d6082b1 100644 --- a/example_query_aggregation_test.go +++ b/internal/integration/tests/example_query_aggregation_test.go @@ -1,12 +1,13 @@ -package gorethink +package tests import ( "fmt" + r "gopkg.in/gorethink/gorethink.v3" ) // Group games by player. func ExampleTerm_Group() { - cur, err := DB("examples").Table("games").Group("player").Run(session) + cur, err := r.DB("examples").Table("games").Group("player").Run(session) if err != nil { fmt.Print(err) return @@ -24,7 +25,7 @@ func ExampleTerm_Group() { // Group games by the index type. func ExampleTerm_GroupByIndex() { - cur, err := DB("examples").Table("games").GroupByIndex("type").Run(session) + cur, err := r.DB("examples").Table("games").GroupByIndex("type").Run(session) if err != nil { fmt.Print(err) return @@ -49,7 +50,7 @@ func ExampleTerm_GroupByIndex() { // ] // Using MultiGroup we can group data by match A, B or C. func ExampleTerm_MultiGroup() { - cur, err := DB("examples").Table("games2").MultiGroup(Row.Field("matches").Keys()).Run(session) + cur, err := r.DB("examples").Table("games2").MultiGroup(r.Row.Field("matches").Keys()).Run(session) if err != nil { fmt.Print(err) return @@ -67,7 +68,7 @@ func ExampleTerm_MultiGroup() { // Ungrouping grouped data. func ExampleTerm_Ungroup() { - cur, err := DB("examples").Table("games"). + cur, err := r.DB("examples").Table("games"). Group("player"). Max("points").Field("points"). Ungroup(). @@ -89,11 +90,11 @@ func ExampleTerm_Ungroup() { // Return the number of documents in the table posts. func ExampleTerm_Reduce() { - cur, err := DB("examples").Table("posts"). - Map(func(doc Term) interface{} { + cur, err := r.DB("examples").Table("posts"). + Map(func(doc r.Term) interface{} { return 1 }). - Reduce(func(left, right Term) interface{} { + Reduce(func(left, right r.Term) interface{} { return left.Add(right) }). Run(session) @@ -114,8 +115,8 @@ func ExampleTerm_Reduce() { // Concatenate words from a list. func ExampleTerm_Fold() { - cur, err := Expr([]string{"a", "b", "c"}).Fold("", func(acc, word Term) Term { - return acc.Add(Branch(acc.Eq(""), "", ", ")).Add(word) + cur, err := r.Expr([]string{"a", "b", "c"}).Fold("", func(acc, word r.Term) r.Term { + return acc.Add(r.Branch(acc.Eq(""), "", ", ")).Add(word) }).Run(session) if err != nil { fmt.Print(err) diff --git a/example_query_control_test.go b/internal/integration/tests/example_query_control_test.go similarity index 80% rename from example_query_control_test.go rename to internal/integration/tests/example_query_control_test.go index b927ef77..963cf5d1 100644 --- a/example_query_control_test.go +++ b/internal/integration/tests/example_query_control_test.go @@ -1,15 +1,16 @@ -package gorethink +package tests import ( "fmt" + r "gopkg.in/gorethink/gorethink.v3" ) // Return heroes and superheroes. func ExampleBranch() { - cur, err := DB("examples").Table("marvel").OrderBy("name").Map(Branch( - Row.Field("victories").Gt(100), - Row.Field("name").Add(" is a superhero"), - Row.Field("name").Add(" is a hero"), + cur, err := r.DB("examples").Table("marvel").OrderBy("name").Map(r.Branch( + r.Row.Field("victories").Gt(100), + r.Row.Field("name").Add(" is a superhero"), + r.Row.Field("name").Add(" is a hero"), )).Run(session) if err != nil { fmt.Print(err) @@ -34,7 +35,7 @@ func ExampleBranch() { // Return an error func ExampleError() { - err := Error("this is a runtime error").Exec(session) + err := r.Error("this is a runtime error").Exec(session) fmt.Println(err) } @@ -42,9 +43,9 @@ func ExampleError() { // case where the author field is missing or null, we want to retrieve the // string "Anonymous". func ExampleTerm_Default() { - cur, err := DB("examples").Table("posts").Map(map[string]interface{}{ - "title": Row.Field("title"), - "author": Row.Field("author").Default("Anonymous"), + cur, err := r.DB("examples").Table("posts").Map(map[string]interface{}{ + "title": r.Row.Field("title"), + "author": r.Row.Field("author").Default("Anonymous"), }).Run(session) if err != nil { fmt.Print(err) @@ -63,7 +64,7 @@ func ExampleTerm_Default() { // Convert a Go integer to a ReQL object func ExampleExpr_int() { - cur, err := Expr(1).Run(session) + cur, err := r.Expr(1).Run(session) if err != nil { fmt.Print(err) return @@ -83,7 +84,7 @@ func ExampleExpr_int() { // Convert a Go slice to a ReQL object func ExampleExpr_slice() { - cur, err := Expr([]int{1, 2, 3}).Run(session) + cur, err := r.Expr([]int{1, 2, 3}).Run(session) if err != nil { fmt.Print(err) return @@ -108,7 +109,7 @@ func ExampleExpr_slice() { // Convert a Go slice to a ReQL object func ExampleExpr_map() { - cur, err := Expr(map[string]interface{}{ + cur, err := r.Expr(map[string]interface{}{ "a": 1, "b": "b", }).Run(session) @@ -151,7 +152,7 @@ func ExampleExpr_struct() { Nested ExampleTypeNested } - cur, err := Expr(ExampleTypeA{ + cur, err := r.Expr(ExampleTypeA{ A: 1, B: "b", ExampleTypeEmbed: ExampleTypeEmbed{ @@ -194,7 +195,7 @@ func ExampleExpr_structTags() { B string `gorethink:"field_b"` } - cur, err := Expr(ExampleType{ + cur, err := r.Expr(ExampleType{ A: 1, B: "b", }).Run(session) @@ -221,7 +222,7 @@ func ExampleExpr_structTags() { // Execute a raw JSON query func ExampleRawQuery() { - cur, err := RawQuery([]byte(`"hello world"`)).Run(session) + cur, err := r.RawQuery([]byte(`"hello world"`)).Run(session) if err != nil { fmt.Print(err) return diff --git a/example_query_db_test.go b/internal/integration/tests/example_query_db_test.go similarity index 59% rename from example_query_db_test.go rename to internal/integration/tests/example_query_db_test.go index afe0382a..ec1798eb 100644 --- a/example_query_db_test.go +++ b/internal/integration/tests/example_query_db_test.go @@ -1,12 +1,13 @@ -package gorethink +package tests import ( "fmt" + r "gopkg.in/gorethink/gorethink.v3" ) // Create a database named ’superheroes’. func ExampleDBCreate() { - resp, err := DBCreate("superheroes").RunWrite(session) + resp, err := r.DBCreate("superheroes").RunWrite(session) if err != nil { fmt.Print(err) } @@ -19,11 +20,11 @@ func ExampleDBCreate() { // Drop a database named ‘superheroes’. func ExampleDBDrop() { // Setup database + tables - DBCreate("superheroes").Exec(session) - DB("superheroes").TableCreate("superheroes").Exec(session) - DB("superheroes").TableCreate("battles").Exec(session) + r.DBCreate("superheroes").Exec(session) + r.DB("superheroes").TableCreate("superheroes").Exec(session) + r.DB("superheroes").TableCreate("battles").Exec(session) - resp, err := DBDrop("superheroes").RunWrite(session) + resp, err := r.DBDrop("superheroes").RunWrite(session) if err != nil { fmt.Print(err) } diff --git a/example_query_manipulation_test.go b/internal/integration/tests/example_query_manipulation_test.go similarity index 62% rename from example_query_manipulation_test.go rename to internal/integration/tests/example_query_manipulation_test.go index 51616c9b..0496169e 100644 --- a/example_query_manipulation_test.go +++ b/internal/integration/tests/example_query_manipulation_test.go @@ -1,12 +1,13 @@ -package gorethink +package tests import ( "fmt" + r "gopkg.in/gorethink/gorethink.v3" ) // Get john's age func ExampleTerm_Field() { - cur, err := DB("examples").Table("users").Get("john").Field("age").Run(session) + cur, err := r.DB("examples").Table("users").Get("john").Field("age").Run(session) if err != nil { fmt.Print(err) return diff --git a/example_query_select_test.go b/internal/integration/tests/example_query_select_test.go similarity index 83% rename from example_query_select_test.go rename to internal/integration/tests/example_query_select_test.go index 8e3a6f75..11acc0f5 100644 --- a/example_query_select_test.go +++ b/internal/integration/tests/example_query_select_test.go @@ -1,13 +1,14 @@ -package gorethink +package tests import ( "fmt" + r "gopkg.in/gorethink/gorethink.v3" ) // Find a document by ID. func ExampleTerm_Get() { // Fetch the row from the database - res, err := DB("examples").Table("heroes").Get(2).Run(session) + res, err := r.DB("examples").Table("heroes").Get(2).Run(session) if err != nil { fmt.Print(err) return @@ -33,7 +34,7 @@ func ExampleTerm_Get() { // Find a document by ID. func ExampleTerm_GetAll() { // Fetch the row from the database - res, err := DB("examples").Table("heroes").GetAll(2).Run(session) + res, err := r.DB("examples").Table("heroes").GetAll(2).Run(session) if err != nil { fmt.Print(err) return @@ -59,7 +60,7 @@ func ExampleTerm_GetAll() { // Find a document by ID. func ExampleTerm_GetAll_multiple() { // Fetch the row from the database - res, err := DB("examples").Table("heroes").GetAll(1, 2).Run(session) + res, err := r.DB("examples").Table("heroes").GetAll(1, 2).Run(session) if err != nil { fmt.Print(err) return @@ -80,7 +81,7 @@ func ExampleTerm_GetAll_multiple() { // Find all document with an indexed value. func ExampleTerm_GetAll_optArgs() { // Fetch the row from the database - res, err := DB("examples").Table("heroes").GetAll("man_of_steel").OptArgs(GetAllOpts{ + res, err := r.DB("examples").Table("heroes").GetAll("man_of_steel").OptArgs(r.GetAllOpts{ Index: "code_name", }).Run(session) if err != nil { @@ -108,7 +109,7 @@ func ExampleTerm_GetAll_optArgs() { // Find all document with an indexed value. func ExampleTerm_GetAllByIndex() { // Fetch the row from the database - res, err := DB("examples").Table("heroes").GetAllByIndex("code_name", "man_of_steel").Run(session) + res, err := r.DB("examples").Table("heroes").GetAllByIndex("code_name", "man_of_steel").Run(session) if err != nil { fmt.Print(err) return @@ -134,7 +135,7 @@ func ExampleTerm_GetAllByIndex() { // Find a document and merge another document with it. func ExampleTerm_Get_merge() { // Fetch the row from the database - res, err := DB("examples").Table("heroes").Get(4).Merge(map[string]interface{}{ + res, err := r.DB("examples").Table("heroes").Get(4).Merge(map[string]interface{}{ "powers": []string{"speed"}, }).Run(session) if err != nil { @@ -162,7 +163,7 @@ func ExampleTerm_Get_merge() { // Get all users who are 30 years old. func ExampleTerm_Filter() { // Fetch the row from the database - res, err := DB("examples").Table("users").Filter(map[string]interface{}{ + res, err := r.DB("examples").Table("users").Filter(map[string]interface{}{ "age": 30, }).Run(session) if err != nil { @@ -186,7 +187,7 @@ func ExampleTerm_Filter() { // Get all users who are more than 25 years old. func ExampleTerm_Filter_row() { // Fetch the row from the database - res, err := DB("examples").Table("users").Filter(Row.Field("age").Gt(25)).Run(session) + res, err := r.DB("examples").Table("users").Filter(r.Row.Field("age").Gt(25)).Run(session) if err != nil { fmt.Print(err) return @@ -208,7 +209,7 @@ func ExampleTerm_Filter_row() { // Retrieve all users who have a gmail account (whose field email ends with @gmail.com). func ExampleTerm_Filter_function() { // Fetch the row from the database - res, err := DB("examples").Table("users").Filter(func(user Term) Term { + res, err := r.DB("examples").Table("users").Filter(func(user r.Term) r.Term { return user.Field("email").Match("@gmail.com$") }).Run(session) if err != nil { diff --git a/example_query_table_test.go b/internal/integration/tests/example_query_table_test.go similarity index 52% rename from example_query_table_test.go rename to internal/integration/tests/example_query_table_test.go index 8c1457d4..3667c947 100644 --- a/example_query_table_test.go +++ b/internal/integration/tests/example_query_table_test.go @@ -1,17 +1,18 @@ -package gorethink +package tests import ( "fmt" + r "gopkg.in/gorethink/gorethink.v3" ) // Create a table named "table" with the default settings. func ExampleTerm_TableCreate() { // Setup database - DB("examples").TableDrop("table").Run(session) + r.DB("examples").TableDrop("table").Run(session) - response, err := DB("examples").TableCreate("table").RunWrite(session) + response, err := r.DB("examples").TableCreate("table").RunWrite(session) if err != nil { - Log.Fatalf("Error creating table: %s", err) + r.Log.Fatalf("Error creating table: %s", err) } fmt.Printf("%d table created", response.TablesCreated) @@ -23,12 +24,12 @@ func ExampleTerm_TableCreate() { // Create a simple index based on the field name. func ExampleTerm_IndexCreate() { // Setup database - DB("examples").TableDrop("table").Run(session) - DB("examples").TableCreate("table").Run(session) + r.DB("examples").TableDrop("table").Run(session) + r.DB("examples").TableCreate("table").Run(session) - response, err := DB("examples").Table("table").IndexCreate("name").RunWrite(session) + response, err := r.DB("examples").Table("table").IndexCreate("name").RunWrite(session) if err != nil { - Log.Fatalf("Error creating index: %s", err) + r.Log.Fatalf("Error creating index: %s", err) } fmt.Printf("%d index created", response.Created) @@ -40,14 +41,14 @@ func ExampleTerm_IndexCreate() { // Create a compound index based on the fields first_name and last_name. func ExampleTerm_IndexCreate_compound() { // Setup database - DB("examples").TableDrop("table").Run(session) - DB("examples").TableCreate("table").Run(session) + r.DB("examples").TableDrop("table").Run(session) + r.DB("examples").TableCreate("table").Run(session) - response, err := DB("examples").Table("table").IndexCreateFunc("full_name", func(row Term) interface{} { + response, err := r.DB("examples").Table("table").IndexCreateFunc("full_name", func(row r.Term) interface{} { return []interface{}{row.Field("first_name"), row.Field("last_name")} }).RunWrite(session) if err != nil { - Log.Fatalf("Error creating index: %s", err) + r.Log.Fatalf("Error creating index: %s", err) } fmt.Printf("%d index created", response.Created) diff --git a/example_query_transformation_test.go b/internal/integration/tests/example_query_transformation_test.go similarity index 78% rename from example_query_transformation_test.go rename to internal/integration/tests/example_query_transformation_test.go index 6ec80ee2..33cdc985 100644 --- a/example_query_transformation_test.go +++ b/internal/integration/tests/example_query_transformation_test.go @@ -1,12 +1,13 @@ -package gorethink +package tests import ( "fmt" + r "gopkg.in/gorethink/gorethink.v3" ) // Return the first five squares. func ExampleTerm_Map() { - cur, err := Expr([]int{1, 2, 3, 4, 5}).Map(func(val Term) Term { + cur, err := r.Expr([]int{1, 2, 3, 4, 5}).Map(func(val r.Term) r.Term { return val.Mul(val) }).Run(session) if err != nil { @@ -33,7 +34,7 @@ func ExampleMap_multipleSequences() { var sequence2 = []int{10, 20, 30, 40} var sequence3 = []int{1, 2, 3, 4} - cur, err := Map(sequence1, sequence2, sequence3, func(val1, val2, val3 Term) Term { + cur, err := r.Map(sequence1, sequence2, sequence3, func(val1, val2, val3 r.Term) r.Term { return val1.Add(val2).Add(val3) }).Run(session) if err != nil { @@ -56,7 +57,7 @@ func ExampleMap_multipleSequences() { // Order all the posts using the index date. func ExampleTerm_OrderBy_index() { - cur, err := DB("examples").Table("posts").OrderBy(OrderByOpts{ + cur, err := r.DB("examples").Table("posts").OrderBy(r.OrderByOpts{ Index: "date", }).Run(session) if err != nil { @@ -76,8 +77,8 @@ func ExampleTerm_OrderBy_index() { // Order all the posts using the index date in descending order. func ExampleTerm_OrderBy_indexDesc() { - cur, err := DB("examples").Table("posts").OrderBy(OrderByOpts{ - Index: Desc("date"), + cur, err := r.DB("examples").Table("posts").OrderBy(r.OrderByOpts{ + Index: r.Desc("date"), }).Run(session) if err != nil { fmt.Print(err) @@ -97,8 +98,8 @@ func ExampleTerm_OrderBy_indexDesc() { // You can efficiently order using multiple fields by using a compound index. // For example order by date and title. func ExampleTerm_OrderBy_compound() { - cur, err := DB("examples").Table("posts").OrderBy(OrderByOpts{ - Index: Desc("dateAndTitle"), + cur, err := r.DB("examples").Table("posts").OrderBy(r.OrderByOpts{ + Index: r.Desc("dateAndTitle"), }).Run(session) if err != nil { fmt.Print(err) @@ -118,9 +119,9 @@ func ExampleTerm_OrderBy_compound() { // If you have a sequence with fewer documents than the arrayLimit, you can order // it by multiple fields without an index. func ExampleTerm_OrderBy_multiple() { - cur, err := DB("examples").Table("posts").OrderBy( + cur, err := r.DB("examples").Table("posts").OrderBy( "title", - OrderByOpts{Index: Desc("date")}, + r.OrderByOpts{Index: r.Desc("date")}, ).Run(session) if err != nil { fmt.Print(err) @@ -141,9 +142,9 @@ func ExampleTerm_OrderBy_multiple() { // query orders posts by date, and if multiple posts were published on the same // date, they will be ordered by title. func ExampleTerm_OrderBy_multipleWithIndex() { - cur, err := DB("examples").Table("posts").OrderBy( + cur, err := r.DB("examples").Table("posts").OrderBy( "title", - OrderByOpts{Index: Desc("date")}, + r.OrderByOpts{Index: r.Desc("date")}, ).Run(session) if err != nil { fmt.Print(err) diff --git a/example_query_write_test.go b/internal/integration/tests/example_query_write_test.go similarity index 78% rename from example_query_write_test.go rename to internal/integration/tests/example_query_write_test.go index 4fb3c56a..b3104519 100644 --- a/example_query_write_test.go +++ b/internal/integration/tests/example_query_write_test.go @@ -1,7 +1,8 @@ -package gorethink +package tests import ( "fmt" + r "gopkg.in/gorethink/gorethink.v3" ) // Insert a document into the table posts using a struct. @@ -12,7 +13,7 @@ func ExampleTerm_Insert_struct() { Content string `gorethink:"content"` } - resp, err := DB("examples").Table("posts").Insert(Post{ + resp, err := r.DB("examples").Table("posts").Insert(Post{ ID: 1, Title: "Lorem ipsum", Content: "Dolor sit amet", @@ -36,7 +37,7 @@ func ExampleTerm_Insert_generatedKey() { Content string `gorethink:"content"` } - resp, err := DB("examples").Table("posts").Insert(map[string]interface{}{ + resp, err := r.DB("examples").Table("posts").Insert(map[string]interface{}{ "title": "Lorem ipsum", "content": "Dolor sit amet", }).RunWrite(session) @@ -53,7 +54,7 @@ func ExampleTerm_Insert_generatedKey() { // Insert a document into the table posts using a map. func ExampleTerm_Insert_map() { - resp, err := DB("examples").Table("posts").Insert(map[string]interface{}{ + resp, err := r.DB("examples").Table("posts").Insert(map[string]interface{}{ "id": 2, "title": "Lorem ipsum", "content": "Dolor sit amet", @@ -71,7 +72,7 @@ func ExampleTerm_Insert_map() { // Insert multiple documents into the table posts. func ExampleTerm_Insert_multiple() { - resp, err := DB("examples").Table("posts").Insert([]interface{}{ + resp, err := r.DB("examples").Table("posts").Insert([]interface{}{ map[string]interface{}{ "title": "Lorem ipsum", "content": "Dolor sit amet", @@ -95,10 +96,10 @@ func ExampleTerm_Insert_multiple() { // Insert a document into the table posts, replacing the document if it already // exists. func ExampleTerm_Insert_upsert() { - resp, err := DB("examples").Table("posts").Insert(map[string]interface{}{ + resp, err := r.DB("examples").Table("posts").Insert(map[string]interface{}{ "id": 1, "title": "Lorem ipsum 2", - }, InsertOpts{ + }, r.InsertOpts{ Conflict: "replace", }).RunWrite(session) if err != nil { @@ -114,7 +115,7 @@ func ExampleTerm_Insert_upsert() { // Update the status of the post with id of 1 to published. func ExampleTerm_Update() { - resp, err := DB("examples").Table("posts").Get(2).Update(map[string]interface{}{ + resp, err := r.DB("examples").Table("posts").Get(2).Update(map[string]interface{}{ "status": "published", }).RunWrite(session) if err != nil { @@ -130,7 +131,7 @@ func ExampleTerm_Update() { // Update bob's cell phone number. func ExampleTerm_Update_nested() { - resp, err := DB("examples").Table("users").Get("bob").Update(map[string]interface{}{ + resp, err := r.DB("examples").Table("users").Get("bob").Update(map[string]interface{}{ "contact": map[string]interface{}{ "phone": "408-555-4242", }, @@ -148,7 +149,7 @@ func ExampleTerm_Update_nested() { // Update the status of all posts to published. func ExampleTerm_Update_all() { - resp, err := DB("examples").Table("posts").Update(map[string]interface{}{ + resp, err := r.DB("examples").Table("posts").Update(map[string]interface{}{ "status": "published", }).RunWrite(session) if err != nil { @@ -165,8 +166,8 @@ func ExampleTerm_Update_all() { // Increment the field view of the post with id of 1. If the field views does not // exist, it will be set to 0. func ExampleTerm_Update_increment() { - resp, err := DB("examples").Table("posts").Get(1).Update(map[string]interface{}{ - "views": Row.Field("views").Add(1).Default(0), + resp, err := r.DB("examples").Table("posts").Get(1).Update(map[string]interface{}{ + "views": r.Row.Field("views").Add(1).Default(0), }).RunWrite(session) if err != nil { fmt.Print(err) @@ -181,9 +182,9 @@ func ExampleTerm_Update_increment() { // Update the status of the post with id of 1 using soft durability. func ExampleTerm_Update_softDurability() { - resp, err := DB("examples").Table("posts").Get(2).Update(map[string]interface{}{ + resp, err := r.DB("examples").Table("posts").Get(2).Update(map[string]interface{}{ "status": "draft", - }, UpdateOpts{ + }, r.UpdateOpts{ Durability: "soft", }).RunWrite(session) if err != nil { @@ -199,7 +200,7 @@ func ExampleTerm_Update_softDurability() { // Delete a single document from the table posts. func ExampleTerm_Delete() { - resp, err := DB("examples").Table("posts").Get(2).Delete().RunWrite(session) + resp, err := r.DB("examples").Table("posts").Get(2).Delete().RunWrite(session) if err != nil { fmt.Print(err) return @@ -213,7 +214,7 @@ func ExampleTerm_Delete() { // Delete all comments where the field status is published func ExampleTerm_Delete_many() { - resp, err := DB("examples").Table("posts").Filter(map[string]interface{}{ + resp, err := r.DB("examples").Table("posts").Filter(map[string]interface{}{ "status": "published", }).Delete().RunWrite(session) if err != nil { diff --git a/example_test.go b/internal/integration/tests/example_test.go similarity index 94% rename from example_test.go rename to internal/integration/tests/example_test.go index 83743826..369add16 100644 --- a/example_test.go +++ b/internal/integration/tests/example_test.go @@ -1,4 +1,4 @@ -package gorethink_test +package tests import ( "fmt" diff --git a/gorethink_test.go b/internal/integration/tests/gorethink_test.go similarity index 80% rename from gorethink_test.go rename to internal/integration/tests/gorethink_test.go index 3fffd28f..58d91e33 100644 --- a/gorethink_test.go +++ b/internal/integration/tests/gorethink_test.go @@ -1,4 +1,4 @@ -package gorethink +package tests import ( "encoding/json" @@ -10,15 +10,16 @@ import ( "time" test "gopkg.in/check.v1" + r "gopkg.in/gorethink/gorethink.v3" ) -var session *Session +var session *r.Session var testdata = flag.Bool("gorethink.testdata", true, "create test data") var url, url1, url2, url3, db, authKey string func init() { flag.Parse() - SetVerbose(true) + r.SetVerbose(true) // If the test is being run by wercker look for the rethink url url = os.Getenv("RETHINKDB_URL") @@ -52,11 +53,11 @@ func init() { // func testSetup(m *testing.M) { var err error - session, err = Connect(ConnectOpts{ + session, err = r.Connect(r.ConnectOpts{ Address: url, }) if err != nil { - Log.Fatalln(err.Error()) + r.Log.Fatalln(err.Error()) } setupTestData() @@ -66,15 +67,15 @@ func testTeardown(m *testing.M) { } func testBenchmarkSetup() { - DBDrop("benchmarks").Exec(session) - DBCreate("benchmarks").Exec(session) + r.DBDrop("benchmarks").Exec(session) + r.DBCreate("benchmarks").Exec(session) - DB("benchmarks").TableDrop("benchmarks").Run(session) - DB("benchmarks").TableCreate("benchmarks").Run(session) + r.DB("benchmarks").TableDrop("benchmarks").Run(session) + r.DB("benchmarks").TableCreate("benchmarks").Run(session) } func testBenchmarkTeardown() { - DBDrop("benchmarks").Run(session) + r.DBDrop("benchmarks").Run(session) } func TestMain(m *testing.M) { @@ -240,7 +241,7 @@ type TagsTest struct { func (s *RethinkSuite) BenchmarkExpr(c *test.C) { for i := 0; i < c.N; i++ { // Test query - query := Expr(true) + query := r.Expr(true) err := query.Exec(session) c.Assert(err, test.IsNil) } @@ -249,17 +250,17 @@ func (s *RethinkSuite) BenchmarkExpr(c *test.C) { func (s *RethinkSuite) BenchmarkNoReplyExpr(c *test.C) { for i := 0; i < c.N; i++ { // Test query - query := Expr(true) - err := query.Exec(session, ExecOpts{NoReply: true}) + query := r.Expr(true) + err := query.Exec(session, r.ExecOpts{NoReply: true}) c.Assert(err, test.IsNil) } } func (s *RethinkSuite) BenchmarkGet(c *test.C) { // Ensure table + database exist - DBCreate("test").RunWrite(session) - DB("test").TableCreate("TestMany").RunWrite(session) - DB("test").Table("TestMany").Delete().RunWrite(session) + r.DBCreate("test").RunWrite(session) + r.DB("test").TableCreate("TestMany").RunWrite(session) + r.DB("test").Table("TestMany").Delete().RunWrite(session) // Insert rows data := []interface{}{} @@ -268,29 +269,29 @@ func (s *RethinkSuite) BenchmarkGet(c *test.C) { "id": i, }) } - DB("test").Table("TestMany").Insert(data).Run(session) + r.DB("test").Table("TestMany").Insert(data).Run(session) for i := 0; i < c.N; i++ { n := rand.Intn(100) // Test query var response interface{} - query := DB("test").Table("TestMany").Get(n) + query := r.DB("test").Table("TestMany").Get(n) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{"id": n}) + c.Assert(response, JsonEquals, map[string]interface{}{"id": n}) } } func (s *RethinkSuite) BenchmarkGetStruct(c *test.C) { // Ensure table + database exist - DBCreate("test").RunWrite(session) - DB("test").TableCreate("TestMany").RunWrite(session) - DB("test").Table("TestMany").Delete().RunWrite(session) + r.DBCreate("test").RunWrite(session) + r.DB("test").TableCreate("TestMany").RunWrite(session) + r.DB("test").Table("TestMany").Delete().RunWrite(session) // Insert rows data := []interface{}{} @@ -304,14 +305,14 @@ func (s *RethinkSuite) BenchmarkGetStruct(c *test.C) { }}, }) } - DB("test").Table("TestMany").Insert(data).Run(session) + r.DB("test").Table("TestMany").Insert(data).Run(session) for i := 0; i < c.N; i++ { n := rand.Intn(100) // Test query var resObj object - query := DB("test").Table("TestMany").Get(n) + query := r.DB("test").Table("TestMany").Get(n) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -323,9 +324,9 @@ func (s *RethinkSuite) BenchmarkGetStruct(c *test.C) { func (s *RethinkSuite) BenchmarkSelectMany(c *test.C) { // Ensure table + database exist - DBCreate("test").RunWrite(session) - DB("test").TableCreate("TestMany").RunWrite(session) - DB("test").Table("TestMany").Delete().RunWrite(session) + r.DBCreate("test").RunWrite(session) + r.DB("test").TableCreate("TestMany").RunWrite(session) + r.DB("test").Table("TestMany").Delete().RunWrite(session) // Insert rows data := []interface{}{} @@ -334,11 +335,11 @@ func (s *RethinkSuite) BenchmarkSelectMany(c *test.C) { "id": i, }) } - DB("test").Table("TestMany").Insert(data).Run(session) + r.DB("test").Table("TestMany").Insert(data).Run(session) for i := 0; i < c.N; i++ { // Test query - res, err := DB("test").Table("TestMany").Run(session) + res, err := r.DB("test").Table("TestMany").Run(session) c.Assert(err, test.IsNil) var response []map[string]interface{} @@ -351,9 +352,9 @@ func (s *RethinkSuite) BenchmarkSelectMany(c *test.C) { func (s *RethinkSuite) BenchmarkSelectManyStruct(c *test.C) { // Ensure table + database exist - DBCreate("test").RunWrite(session) - DB("test").TableCreate("TestMany").RunWrite(session) - DB("test").Table("TestMany").Delete().RunWrite(session) + r.DBCreate("test").RunWrite(session) + r.DB("test").TableCreate("TestMany").RunWrite(session) + r.DB("test").Table("TestMany").Delete().RunWrite(session) // Insert rows data := []interface{}{} @@ -367,11 +368,11 @@ func (s *RethinkSuite) BenchmarkSelectManyStruct(c *test.C) { }}, }) } - DB("test").Table("TestMany").Insert(data).Run(session) + r.DB("test").Table("TestMany").Insert(data).Run(session) for i := 0; i < c.N; i++ { // Test query - res, err := DB("test").Table("TestMany").Run(session) + res, err := r.DB("test").Table("TestMany").Run(session) c.Assert(err, test.IsNil) var response []object diff --git a/query_test.go b/internal/integration/tests/query_test.go similarity index 63% rename from query_test.go rename to internal/integration/tests/query_test.go index 330de21e..6e3dac26 100644 --- a/query_test.go +++ b/internal/integration/tests/query_test.go @@ -1,4 +1,4 @@ -package gorethink +package tests import ( "bytes" @@ -8,12 +8,13 @@ import ( "time" test "gopkg.in/check.v1" + r "gopkg.in/gorethink/gorethink.v3" ) func (s *RethinkSuite) TestQueryRun(c *test.C) { var response string - res, err := Expr("Test").Run(session) + res, err := r.Expr("Test").Run(session) c.Assert(err, test.IsNil) err = res.One(&response) @@ -25,7 +26,7 @@ func (s *RethinkSuite) TestQueryRun(c *test.C) { func (s *RethinkSuite) TestQueryReadOne(c *test.C) { var response string - err := Expr("Test").ReadOne(&response, session) + err := r.Expr("Test").ReadOne(&response, session) c.Assert(err, test.IsNil) c.Assert(response, test.Equals, "Test") } @@ -33,22 +34,22 @@ func (s *RethinkSuite) TestQueryReadOne(c *test.C) { func (s *RethinkSuite) TestQueryReadAll(c *test.C) { var response []int - err := Expr([]int{1, 2, 3}).ReadAll(&response, session) + err := r.Expr([]int{1, 2, 3}).ReadAll(&response, session) c.Assert(err, test.IsNil) c.Assert(response, test.HasLen, 3) c.Assert(response, test.DeepEquals, []int{1, 2, 3}) } func (s *RethinkSuite) TestQueryExec(c *test.C) { - err := Expr("Test").Exec(session) + err := r.Expr("Test").Exec(session) c.Assert(err, test.IsNil) } func (s *RethinkSuite) TestQueryRunWrite(c *test.C) { - query := DB("test").Table("test").Insert([]interface{}{ + query := r.DB("test").Table("test").Insert([]interface{}{ map[string]interface{}{"num": 1}, map[string]interface{}{"num": 2}, - }, InsertOpts{ReturnChanges: true}) + }, r.InsertOpts{ReturnChanges: true}) res, err := query.RunWrite(session) c.Assert(err, test.IsNil) c.Assert(res.Inserted, test.Equals, 2) @@ -58,7 +59,7 @@ func (s *RethinkSuite) TestQueryRunWrite(c *test.C) { func (s *RethinkSuite) TestQueryProfile(c *test.C) { var response string - res, err := Expr("Test").Run(session, RunOpts{ + res, err := r.Expr("Test").Run(session, r.RunOpts{ Profile: true, }) c.Assert(err, test.IsNil) @@ -73,7 +74,7 @@ func (s *RethinkSuite) TestQueryProfile(c *test.C) { func (s *RethinkSuite) TestQueryRunRawTime(c *test.C) { var response map[string]interface{} - res, err := Now().Run(session, RunOpts{ + res, err := r.Now().Run(session, r.RunOpts{ TimeFormat: "raw", }) c.Assert(err, test.IsNil) @@ -86,34 +87,34 @@ func (s *RethinkSuite) TestQueryRunRawTime(c *test.C) { } func (s *RethinkSuite) TestQueryRunNil(c *test.C) { - res, err := Expr("Test").Run(nil) + res, err := r.Expr("Test").Run(nil) c.Assert(res, test.IsNil) c.Assert(err, test.NotNil) - c.Assert(err, test.Equals, ErrConnectionClosed) + c.Assert(err, test.Equals, r.ErrConnectionClosed) } func (s *RethinkSuite) TestQueryRunNotConnected(c *test.C) { - res, err := Expr("Test").Run(&Session{}) + res, err := r.Expr("Test").Run(&r.Session{}) c.Assert(res, test.IsNil) c.Assert(err, test.NotNil) - c.Assert(err, test.Equals, ErrConnectionClosed) + c.Assert(err, test.Equals, r.ErrConnectionClosed) } func (s *RethinkSuite) TestControlExprNil(c *test.C) { var response interface{} - query := Expr(nil) + query := r.Expr(nil) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.One(&response) - c.Assert(err, test.Equals, ErrEmptyResult) + c.Assert(err, test.Equals, r.ErrEmptyResult) c.Assert(response, test.Equals, nil) } func (s *RethinkSuite) TestControlExprSimple(c *test.C) { var response int - query := Expr(1) + query := r.Expr(1) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -125,14 +126,14 @@ func (s *RethinkSuite) TestControlExprSimple(c *test.C) { func (s *RethinkSuite) TestControlExprList(c *test.C) { var response []interface{} - query := Expr(narr) + query := r.Expr(narr) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []interface{}{ + c.Assert(response, JsonEquals, []interface{}{ 1, 2, 3, 4, 5, 6, []interface{}{ 7.1, 7.2, 7.3, }, @@ -141,14 +142,14 @@ func (s *RethinkSuite) TestControlExprList(c *test.C) { func (s *RethinkSuite) TestControlExprObj(c *test.C) { var response map[string]interface{} - query := Expr(nobj) + query := r.Expr(nobj) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{ + c.Assert(response, JsonEquals, map[string]interface{}{ "A": 1, "B": 2, "C": map[string]interface{}{ @@ -160,14 +161,14 @@ func (s *RethinkSuite) TestControlExprObj(c *test.C) { func (s *RethinkSuite) TestControlStruct(c *test.C) { var response map[string]interface{} - query := Expr(str) + query := r.Expr(str) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{ + c.Assert(response, JsonEquals, map[string]interface{}{ "id": "A", "B": 1, "D": map[string]interface{}{"D2": "2", "D1": 1}, @@ -197,18 +198,18 @@ func (s *RethinkSuite) TestControlStruct(c *test.C) { } func (s *RethinkSuite) TestControlStructTags(c *test.C) { - SetTags("gorethink", "json") - defer SetTags() + r.SetTags("gorethink", "json") + defer r.SetTags() var response map[string]interface{} - query := Expr(TagsTest{"1", "2", "3"}) + query := r.Expr(TagsTest{"1", "2", "3"}) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{ + c.Assert(response, JsonEquals, map[string]interface{}{ "a": "1", "b": "2", "c1": "3", }) @@ -216,43 +217,43 @@ func (s *RethinkSuite) TestControlStructTags(c *test.C) { func (s *RethinkSuite) TestControlMapTypeAlias(c *test.C) { var response TMap - query := Expr(TMap{"A": 1, "B": 2}) + query := r.Expr(TMap{"A": 1, "B": 2}) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, TMap{"A": 1, "B": 2}) + c.Assert(response, JsonEquals, TMap{"A": 1, "B": 2}) } func (s *RethinkSuite) TestControlStringTypeAlias(c *test.C) { var response TStr - query := Expr(TStr("Hello")) + query := r.Expr(TStr("Hello")) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, TStr("Hello")) + c.Assert(response, JsonEquals, TStr("Hello")) } func (s *RethinkSuite) TestControlExprTypes(c *test.C) { var response []interface{} - query := Expr([]interface{}{int64(1), uint64(1), float64(1.0), int32(1), uint32(1), float32(1), "1", true, false}) + query := r.Expr([]interface{}{int64(1), uint64(1), float64(1.0), int32(1), uint32(1), float32(1), "1", true, false}) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []interface{}{int64(1), uint64(1), float64(1.0), int32(1), uint32(1), float32(1), "1", true, false}) + c.Assert(response, JsonEquals, []interface{}{int64(1), uint64(1), float64(1.0), int32(1), uint32(1), float32(1), "1", true, false}) } func (s *RethinkSuite) TestControlJs(c *test.C) { var response int - query := JS("1;") + query := r.JS("1;") res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -268,44 +269,44 @@ func (s *RethinkSuite) TestControlHttp(c *test.C) { } var response map[string]interface{} - query := HTTP("httpbin.org/get?data=1") + query := r.HTTP("httpbin.org/get?data=1") res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response["args"], jsonEquals, map[string]interface{}{ + c.Assert(response["args"], JsonEquals, map[string]interface{}{ "data": "1", }) } func (s *RethinkSuite) TestControlError(c *test.C) { - query := Error("An error occurred") + query := r.Error("An error occurred") err := query.Exec(session) c.Assert(err, test.NotNil) c.Assert(err, test.NotNil) - c.Assert(err, test.FitsTypeOf, RQLUserError{}) + c.Assert(err, test.FitsTypeOf, r.RQLUserError{}) c.Assert(err.Error(), test.Equals, "gorethink: An error occurred in:\nr.Error(\"An error occurred\")") } func (s *RethinkSuite) TestControlDoNothing(c *test.C) { var response []interface{} - query := Do([]interface{}{map[string]interface{}{"a": 1}, map[string]interface{}{"a": 2}, map[string]interface{}{"a": 3}}) + query := r.Do([]interface{}{map[string]interface{}{"a": 1}, map[string]interface{}{"a": 2}, map[string]interface{}{"a": 3}}) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []interface{}{map[string]interface{}{"a": 1}, map[string]interface{}{"a": 2}, map[string]interface{}{"a": 3}}) + c.Assert(response, JsonEquals, []interface{}{map[string]interface{}{"a": 1}, map[string]interface{}{"a": 2}, map[string]interface{}{"a": 3}}) } func (s *RethinkSuite) TestControlArgs(c *test.C) { var response time.Time - query := Time(Args(Expr([]interface{}{2014, 7, 12, "Z"}))) + query := r.Time(r.Args(r.Expr([]interface{}{2014, 7, 12, "Z"}))) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -317,7 +318,7 @@ func (s *RethinkSuite) TestControlArgs(c *test.C) { func (s *RethinkSuite) TestControlBinaryByteArray(c *test.C) { var response []byte - query := Binary([]byte("Hello World")) + query := r.Binary([]byte("Hello World")) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -331,7 +332,7 @@ type byteArray []byte func (s *RethinkSuite) TestControlBinaryByteArrayAlias(c *test.C) { var response []byte - query := Binary(byteArray("Hello World")) + query := r.Binary(byteArray("Hello World")) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -343,7 +344,7 @@ func (s *RethinkSuite) TestControlBinaryByteArrayAlias(c *test.C) { func (s *RethinkSuite) TestControlBinaryByteSlice(c *test.C) { var response [5]byte - query := Binary([5]byte{'h', 'e', 'l', 'l', 'o'}) + query := r.Binary([5]byte{'h', 'e', 'l', 'l', 'o'}) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -355,7 +356,7 @@ func (s *RethinkSuite) TestControlBinaryByteSlice(c *test.C) { func (s *RethinkSuite) TestControlBinaryExpr(c *test.C) { var response []byte - query := Expr([]byte("Hello World")) + query := r.Expr([]byte("Hello World")) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -367,7 +368,7 @@ func (s *RethinkSuite) TestControlBinaryExpr(c *test.C) { func (s *RethinkSuite) TestControlBinaryExprAlias(c *test.C) { var response []byte - query := Expr(byteArray("Hello World")) + query := r.Expr(byteArray("Hello World")) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -379,7 +380,7 @@ func (s *RethinkSuite) TestControlBinaryExprAlias(c *test.C) { func (s *RethinkSuite) TestControlBinaryTerm(c *test.C) { var response []byte - query := Binary(Expr([]byte("Hello World"))) + query := r.Binary(r.Expr([]byte("Hello World"))) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -391,7 +392,7 @@ func (s *RethinkSuite) TestControlBinaryTerm(c *test.C) { func (s *RethinkSuite) TestControlBinaryElemTerm(c *test.C) { var response map[string]interface{} - query := Expr(map[string]interface{}{ + query := r.Expr(map[string]interface{}{ "bytes": []byte("Hello World"), }) res, err := query.Run(session) @@ -403,14 +404,14 @@ func (s *RethinkSuite) TestControlBinaryElemTerm(c *test.C) { } func (s *RethinkSuite) TestExprInvalidType(c *test.C) { - query := Expr(map[struct{ string }]string{}) + query := r.Expr(map[struct{ string }]string{}) _, err := query.Run(session) c.Assert(err, test.NotNil) } func (s *RethinkSuite) TestRawQuery(c *test.C) { var response int - query := RawQuery([]byte(`1`)) + query := r.RawQuery([]byte(`1`)) res, err := query.Run(session) c.Assert(err, test.IsNil) @@ -423,24 +424,24 @@ func (s *RethinkSuite) TestRawQuery(c *test.C) { func (s *RethinkSuite) TestRawQuery_advanced(c *test.C) { var response []int // r.expr([1,2,3]).map(function(v) { return v.add(1)}) - query := RawQuery([]byte(`[38,[[2,[1,2,3]],[69,[[2,[25]],[24,[[10,[25]],1]]]]]]`)) + query := r.RawQuery([]byte(`[38,[[2,[1,2,3]],[69,[[2,[25]],[24,[[10,[25]],1]]]]]]`)) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []int{2, 3, 4}) + c.Assert(response, JsonEquals, []int{2, 3, 4}) } func (s *RethinkSuite) TestTableChanges(c *test.C) { - DB("test").TableDrop("changes").Exec(session) - DB("test").TableCreate("changes").Exec(session) - DB("test").Table("changes").Wait().Exec(session) + r.DB("test").TableDrop("changes").Exec(session) + r.DB("test").TableCreate("changes").Exec(session) + r.DB("test").Table("changes").Wait().Exec(session) var n int - res, err := DB("test").Table("changes").Changes().Run(session) + res, err := r.DB("test").Table("changes").Changes().Run(session) if err != nil { c.Fatal(err.Error()) } @@ -463,16 +464,16 @@ func (s *RethinkSuite) TestTableChanges(c *test.C) { wg.Done() }() - DB("test").Table("changes").Insert(map[string]interface{}{"n": 1}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 2}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 3}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 4}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 5}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 6}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 7}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 8}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 9}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 10}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 1}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 2}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 3}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 4}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 5}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 6}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 7}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 8}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 9}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 10}).Exec(session) wg.Wait() @@ -480,19 +481,19 @@ func (s *RethinkSuite) TestTableChanges(c *test.C) { } func (s *RethinkSuite) TestTableChangesExit(c *test.C) { - DB("test").TableDrop("changes").Exec(session) - DB("test").TableCreate("changes").Exec(session) - DB("test").Table("changes").Wait().Exec(session) + r.DB("test").TableDrop("changes").Exec(session) + r.DB("test").TableCreate("changes").Exec(session) + r.DB("test").Table("changes").Wait().Exec(session) var n int - res, err := DB("test").Table("changes").Changes().Run(session) + res, err := r.DB("test").Table("changes").Changes().Run(session) if err != nil { c.Fatal(err.Error()) } c.Assert(res.Type(), test.Equals, "Feed") - change := make(chan ChangeResponse) + change := make(chan r.ChangeResponse) // Close cursor after one second go func() { @@ -501,11 +502,11 @@ func (s *RethinkSuite) TestTableChangesExit(c *test.C) { }() // Insert 5 docs - DB("test").Table("changes").Insert(map[string]interface{}{"n": 1}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 2}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 3}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 4}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 5}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 1}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 2}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 3}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 4}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 5}).Exec(session) // Listen for changes res.Listen(change) @@ -517,19 +518,19 @@ func (s *RethinkSuite) TestTableChangesExit(c *test.C) { } func (s *RethinkSuite) TestTableChangesExitNoResults(c *test.C) { - DB("test").TableDrop("changes").Exec(session) - DB("test").TableCreate("changes").Exec(session) - DB("test").Table("changes").Wait().Exec(session) + r.DB("test").TableDrop("changes").Exec(session) + r.DB("test").TableCreate("changes").Exec(session) + r.DB("test").Table("changes").Wait().Exec(session) var n int - res, err := DB("test").Table("changes").Changes().Run(session) + res, err := r.DB("test").Table("changes").Changes().Run(session) if err != nil { c.Fatal(err.Error()) } c.Assert(res.Type(), test.Equals, "Feed") - change := make(chan ChangeResponse) + change := make(chan r.ChangeResponse) // Close cursor after one second go func() { @@ -547,20 +548,20 @@ func (s *RethinkSuite) TestTableChangesExitNoResults(c *test.C) { } func (s *RethinkSuite) TestTableChangesIncludeInitial(c *test.C) { - DB("test").TableDrop("changes").Exec(session) - DB("test").TableCreate("changes").Exec(session) - DB("test").Table("changes").Wait().Exec(session) + r.DB("test").TableDrop("changes").Exec(session) + r.DB("test").TableCreate("changes").Exec(session) + r.DB("test").Table("changes").Wait().Exec(session) // Insert 5 documents to table initially - DB("test").Table("changes").Insert(map[string]interface{}{"n": 1}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 2}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 3}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 4}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 5}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 1}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 2}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 3}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 4}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 5}).Exec(session) var n int - res, err := DB("test").Table("changes").Changes(ChangesOpts{IncludeInitial: true}).Run(session) + res, err := r.DB("test").Table("changes").Changes(r.ChangesOpts{IncludeInitial: true}).Run(session) if err != nil { c.Fatal(err.Error()) } @@ -583,11 +584,11 @@ func (s *RethinkSuite) TestTableChangesIncludeInitial(c *test.C) { wg.Done() }() - DB("test").Table("changes").Insert(map[string]interface{}{"n": 6}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 7}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 8}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 9}).Exec(session) - DB("test").Table("changes").Insert(map[string]interface{}{"n": 10}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 6}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 7}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 8}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 9}).Exec(session) + r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 10}).Exec(session) wg.Wait() @@ -606,23 +607,23 @@ func (s *RethinkSuite) TestWriteReference(c *test.C) { Author: author, } - DB("test").TableDrop("authors").Exec(session) - DB("test").TableDrop("books").Exec(session) - DB("test").TableCreate("authors").Exec(session) - DB("test").TableCreate("books").Exec(session) - DB("test").Table("authors").Wait().Exec(session) - DB("test").Table("books").Wait().Exec(session) + r.DB("test").TableDrop("authors").Exec(session) + r.DB("test").TableDrop("books").Exec(session) + r.DB("test").TableCreate("authors").Exec(session) + r.DB("test").TableCreate("books").Exec(session) + r.DB("test").Table("authors").Wait().Exec(session) + r.DB("test").Table("books").Wait().Exec(session) - _, err := DB("test").Table("authors").Insert(author).RunWrite(session) + _, err := r.DB("test").Table("authors").Insert(author).RunWrite(session) c.Assert(err, test.IsNil) - _, err = DB("test").Table("books").Insert(book).RunWrite(session) + _, err = r.DB("test").Table("books").Insert(book).RunWrite(session) c.Assert(err, test.IsNil) // Read back book + author and check result - cursor, err := DB("test").Table("books").Get("1").Merge(func(p Term) interface{} { + cursor, err := r.DB("test").Table("books").Get("1").Merge(func(p r.Term) interface{} { return map[string]interface{}{ - "author_id": DB("test").Table("authors").Get(p.Field("author_id")), + "author_id": r.DB("test").Table("authors").Get(p.Field("author_id")), } }).Run(session) c.Assert(err, test.IsNil) @@ -636,22 +637,22 @@ func (s *RethinkSuite) TestWriteReference(c *test.C) { } func (s *RethinkSuite) TestWriteConflict(c *test.C) { - DB("test").TableDrop("test").Exec(session) - DB("test").TableCreate("test").Exec(session) - DB("test").Table("test").Wait().Exec(session) + r.DB("test").TableDrop("test").Exec(session) + r.DB("test").TableCreate("test").Exec(session) + r.DB("test").Table("test").Wait().Exec(session) - query := DB("test").Table("test").Insert(map[string]interface{}{"id": "a"}) + query := r.DB("test").Table("test").Insert(map[string]interface{}{"id": "a"}) _, err := query.RunWrite(session) c.Assert(err, test.IsNil) - query = DB("test").Table("test").Insert(map[string]interface{}{"id": "a"}) + query = r.DB("test").Table("test").Insert(map[string]interface{}{"id": "a"}) _, err = query.RunWrite(session) - c.Assert(IsConflictErr(err), test.Equals, true) + c.Assert(r.IsConflictErr(err), test.Equals, true) } func (s *RethinkSuite) TestTimeTime(c *test.C) { var response time.Time - res, err := Time(1986, 11, 3, 12, 30, 15, "Z").Run(session) + res, err := r.Time(1986, 11, 3, 12, 30, 15, "Z").Run(session) c.Assert(err, test.IsNil) err = res.One(&response) @@ -662,7 +663,7 @@ func (s *RethinkSuite) TestTimeTime(c *test.C) { func (s *RethinkSuite) TestTimeExpr(c *test.C) { var response time.Time t := time.Unix(531360000, 0) - res, err := Expr(Expr(t)).Run(session) + res, err := r.Expr(r.Expr(t)).Run(session) c.Assert(err, test.IsNil) err = res.One(&response) @@ -672,7 +673,7 @@ func (s *RethinkSuite) TestTimeExpr(c *test.C) { func (s *RethinkSuite) TestTimeExprMillisecond(c *test.C) { var response time.Time t := time.Unix(531360000, 679000000) - res, err := Expr(t).Run(session) + res, err := r.Expr(t).Run(session) c.Assert(err, test.IsNil) err = res.One(&response) @@ -683,7 +684,7 @@ func (s *RethinkSuite) TestTimeExprMillisecond(c *test.C) { func (s *RethinkSuite) TestTimeISO8601(c *test.C) { var t1, t2 time.Time t2, _ = time.Parse("2006-01-02T15:04:05-07:00", "1986-11-03T08:30:00-07:00") - res, err := ISO8601("1986-11-03T08:30:00-07:00").Run(session) + res, err := r.ISO8601("1986-11-03T08:30:00-07:00").Run(session) c.Assert(err, test.IsNil) err = res.One(&t1) @@ -693,7 +694,7 @@ func (s *RethinkSuite) TestTimeISO8601(c *test.C) { func (s *RethinkSuite) TestTimeInTimezone(c *test.C) { var response []time.Time - res, err := Expr([]interface{}{Now(), Now().InTimezone("-07:00")}).Run(session) + res, err := r.Expr([]interface{}{r.Now(), r.Now().InTimezone("-07:00")}).Run(session) c.Assert(err, test.IsNil) err = res.All(&response) @@ -702,40 +703,40 @@ func (s *RethinkSuite) TestTimeInTimezone(c *test.C) { } func (s *RethinkSuite) TestSelectJSONNumbers(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Address: url, UseJSONNumber: true, }) c.Assert(err, test.IsNil) defer session.Close() // Ensure table + database exist - DBCreate("test").Exec(session) - DB("test").TableCreate("Table1").Exec(session) - DB("test").Table("Table1").Wait().Exec(session) + r.DBCreate("test").Exec(session) + r.DB("test").TableCreate("Table1").Exec(session) + r.DB("test").Table("Table1").Wait().Exec(session) // Insert rows - DB("test").Table("Table1").Insert(objList).Exec(session) + r.DB("test").Table("Table1").Insert(objList).Exec(session) // Test query var response interface{} - query := DB("test").Table("Table1").Get(6) + query := r.DB("test").Table("Table1").Get(6) res, err := query.Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{"id": json.Number("6"), "g1": json.Number("1"), "g2": json.Number("1"), "num": json.Number("15")}) + c.Assert(response, JsonEquals, map[string]interface{}{"id": json.Number("6"), "g1": json.Number("1"), "g2": json.Number("1"), "num": json.Number("15")}) res.Close() } func (s *RethinkSuite) TestSelectManyRows(c *test.C) { // Ensure table + database exist - DBCreate("test").Exec(session) - DB("test").TableCreate("TestMany").Exec(session) - DB("test").Table("TestMany").Wait().Exec(session) - DB("test").Table("TestMany").Delete().Exec(session) + r.DBCreate("test").Exec(session) + r.DB("test").TableCreate("TestMany").Exec(session) + r.DB("test").Table("TestMany").Wait().Exec(session) + r.DB("test").Table("TestMany").Delete().Exec(session) // Insert rows for i := 0; i < 100; i++ { @@ -748,11 +749,11 @@ func (s *RethinkSuite) TestSelectManyRows(c *test.C) { }) } - DB("test").Table("TestMany").Insert(data).Exec(session) + r.DB("test").Table("TestMany").Insert(data).Exec(session) } // Test query - res, err := DB("test").Table("TestMany").Run(session, RunOpts{ + res, err := r.DB("test").Table("TestMany").Run(session, r.RunOpts{ MaxBatchRows: 1, }) c.Assert(err, test.IsNil) diff --git a/session_test.go b/internal/integration/tests/session_test.go similarity index 71% rename from session_test.go rename to internal/integration/tests/session_test.go index 09662efd..9e27b4af 100644 --- a/session_test.go +++ b/internal/integration/tests/session_test.go @@ -1,19 +1,20 @@ -package gorethink +package tests import ( "os" "time" test "gopkg.in/check.v1" + r "gopkg.in/gorethink/gorethink.v3" ) func (s *RethinkSuite) TestSessionConnect(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Address: url, }) c.Assert(err, test.IsNil) - row, err := Expr("Hello World").Run(session) + row, err := r.Expr("Hello World").Run(session) c.Assert(err, test.IsNil) var response string @@ -23,13 +24,13 @@ func (s *RethinkSuite) TestSessionConnect(c *test.C) { } func (s *RethinkSuite) TestSessionConnectHandshakeV1_0(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Address: url, - HandshakeVersion: HandshakeV1_0, + HandshakeVersion: r.HandshakeV1_0, }) c.Assert(err, test.IsNil) - row, err := Expr("Hello World").Run(session) + row, err := r.Expr("Hello World").Run(session) c.Assert(err, test.IsNil) var response string @@ -39,13 +40,13 @@ func (s *RethinkSuite) TestSessionConnectHandshakeV1_0(c *test.C) { } func (s *RethinkSuite) TestSessionConnectHandshakeV0_4(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Address: url, - HandshakeVersion: HandshakeV0_4, + HandshakeVersion: r.HandshakeV0_4, }) c.Assert(err, test.IsNil) - row, err := Expr("Hello World").Run(session) + row, err := r.Expr("Hello World").Run(session) c.Assert(err, test.IsNil) var response string @@ -55,12 +56,12 @@ func (s *RethinkSuite) TestSessionConnectHandshakeV0_4(c *test.C) { } func (s *RethinkSuite) TestSessionReconnect(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Address: url, }) c.Assert(err, test.IsNil) - row, err := Expr("Hello World").Run(session) + row, err := r.Expr("Hello World").Run(session) c.Assert(err, test.IsNil) var response string @@ -71,7 +72,7 @@ func (s *RethinkSuite) TestSessionReconnect(c *test.C) { err = session.Reconnect() c.Assert(err, test.IsNil) - row, err = Expr("Hello World 2").Run(session) + row, err = r.Expr("Hello World 2").Run(session) c.Assert(err, test.IsNil) err = row.One(&response) @@ -81,33 +82,33 @@ func (s *RethinkSuite) TestSessionReconnect(c *test.C) { func (s *RethinkSuite) TestSessionConnectError(c *test.C) { var err error - _, err = Connect(ConnectOpts{ + _, err = r.Connect(r.ConnectOpts{ Address: "nonexistanturl", Timeout: time.Second, }) c.Assert(err, test.NotNil) - c.Assert(err, test.FitsTypeOf, RQLConnectionError{}) + c.Assert(err, test.FitsTypeOf, r.RQLConnectionError{}) } func (s *RethinkSuite) TestSessionClose(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Address: url, }) c.Assert(err, test.IsNil) - _, err = Expr("Hello World").Run(session) + _, err = r.Expr("Hello World").Run(session) c.Assert(err, test.IsNil) err = session.Close() c.Assert(err, test.IsNil) - _, err = Expr("Hello World").Run(session) + _, err = r.Expr("Hello World").Run(session) c.Assert(err, test.NotNil) } func (s *RethinkSuite) TestSessionServer(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Address: url, }) c.Assert(err, test.IsNil) @@ -120,7 +121,7 @@ func (s *RethinkSuite) TestSessionServer(c *test.C) { } func (s *RethinkSuite) TestSessionConnectDatabase(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Address: url, AuthKey: os.Getenv("RETHINKDB_AUTHKEY"), Database: "test2", @@ -128,7 +129,7 @@ func (s *RethinkSuite) TestSessionConnectDatabase(c *test.C) { c.Assert(err, test.IsNil) c.Assert(session.Database(), test.Equals, "test2") - _, err = Table("test2").Run(session) + _, err = r.Table("test2").Run(session) c.Assert(err, test.NotNil) c.Assert(err.Error(), test.Equals, "gorethink: Database `test2` does not exist. in:\nr.Table(\"test2\")") @@ -137,23 +138,23 @@ func (s *RethinkSuite) TestSessionConnectDatabase(c *test.C) { } func (s *RethinkSuite) TestSessionConnectUsername(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Address: url, }) c.Assert(err, test.IsNil) - DB("rethinkdb").Table("users").Insert(map[string]string{ + r.DB("rethinkdb").Table("users").Insert(map[string]string{ "id": "gorethink_test", "password": "password", }).Exec(session) - session, err = Connect(ConnectOpts{ + session, err = r.Connect(r.ConnectOpts{ Address: url, Username: "gorethink_test", Password: "password", }) c.Assert(err, test.IsNil) - _, err = Expr("Hello World").Run(session) + _, err = r.Expr("Hello World").Run(session) c.Assert(err, test.IsNil) } diff --git a/testdata_test.go b/internal/integration/tests/testdata_test.go similarity index 59% rename from testdata_test.go rename to internal/integration/tests/testdata_test.go index 0a620b2f..e1acc729 100644 --- a/testdata_test.go +++ b/internal/integration/tests/testdata_test.go @@ -1,41 +1,43 @@ -package gorethink +package tests + +import (r "gopkg.in/gorethink/gorethink.v3") func setupTestData() { if *testdata { // Delete any preexisting databases - DBDrop("test").Exec(session) - DBDrop("examples").Exec(session) - DBDrop("superheroes").Exec(session) + r.DBDrop("test").Exec(session) + r.DBDrop("examples").Exec(session) + r.DBDrop("superheroes").Exec(session) - DBCreate("test").Exec(session) - DBCreate("examples").Exec(session) + r.DBCreate("test").Exec(session) + r.DBCreate("examples").Exec(session) - DB("test").TableCreate("test").Exec(session) - DB("test").TableCreate("test2").Exec(session) - DB("test").TableCreate("changes").Exec(session) + r.DB("test").TableCreate("test").Exec(session) + r.DB("test").TableCreate("test2").Exec(session) + r.DB("test").TableCreate("changes").Exec(session) - DB("examples").TableCreate("posts").Exec(session) - DB("examples").TableCreate("heroes").Exec(session) - DB("examples").TableCreate("users").Exec(session) - DB("examples").TableCreate("games").Exec(session) - DB("examples").TableCreate("games2").Exec(session) - DB("examples").TableCreate("marvel").Exec(session) + r.DB("examples").TableCreate("posts").Exec(session) + r.DB("examples").TableCreate("heroes").Exec(session) + r.DB("examples").TableCreate("users").Exec(session) + r.DB("examples").TableCreate("games").Exec(session) + r.DB("examples").TableCreate("games2").Exec(session) + r.DB("examples").TableCreate("marvel").Exec(session) - DB("examples").Table("posts").IndexCreate("date").Exec(session) - DB("examples").Table("posts").IndexWait().Exec(session) - DB("examples").Table("posts").IndexCreateFunc( + r.DB("examples").Table("posts").IndexCreate("date").Exec(session) + r.DB("examples").Table("posts").IndexWait().Exec(session) + r.DB("examples").Table("posts").IndexCreateFunc( "dateAndTitle", - []interface{}{Row.Field("date"), Row.Field("title")}, + []interface{}{r.Row.Field("date"), r.Row.Field("title")}, ).Exec(session) - DB("examples").Table("heroes").IndexCreate("code_name").Exec(session) - DB("examples").Table("heroes").IndexWait().Exec(session) + r.DB("examples").Table("heroes").IndexCreate("code_name").Exec(session) + r.DB("examples").Table("heroes").IndexWait().Exec(session) - DB("examples").Table("games").IndexCreate("type").Exec(session) - DB("examples").Table("games").IndexWait().Exec(session) + r.DB("examples").Table("games").IndexCreate("type").Exec(session) + r.DB("examples").Table("games").IndexWait().Exec(session) // Create heroes table - DB("examples").Table("heroes").Insert([]interface{}{ + r.DB("examples").Table("heroes").Insert([]interface{}{ map[string]interface{}{ "id": 1, "code_name": "batman", @@ -59,7 +61,7 @@ func setupTestData() { }).Exec(session) // Create users table - DB("examples").Table("users").Insert([]interface{}{ + r.DB("examples").Table("users").Insert([]interface{}{ map[string]interface{}{ "id": "william", "email": "william@rethinkdb.com", @@ -93,7 +95,7 @@ func setupTestData() { }).Exec(session) // Create games table - DB("examples").Table("games").Insert([]interface{}{ + r.DB("examples").Table("games").Insert([]interface{}{ map[string]interface{}{"id": 2, "player": "Bob", "points": 15, "type": "ranked"}, map[string]interface{}{"id": 5, "player": "Alice", "points": 7, "type": "free"}, map[string]interface{}{"id": 11, "player": "Bob", "points": 10, "type": "free"}, @@ -101,14 +103,14 @@ func setupTestData() { }).Exec(session) // Create games2 table - DB("examples").Table("games2").Insert([]interface{}{ + r.DB("examples").Table("games2").Insert([]interface{}{ map[string]interface{}{"id": 1, "matches": map[string]interface{}{"a": []int{1, 2, 3}, "b": []int{4, 5, 6}}}, map[string]interface{}{"id": 2, "matches": map[string]interface{}{"b": []int{100}, "c": []int{7, 8, 9}}}, map[string]interface{}{"id": 3, "matches": map[string]interface{}{"a": []int{10, 20}, "c": []int{70, 80}}}, }).Exec(session) // Create marvel table - DB("examples").Table("marvel").Insert([]interface{}{ + r.DB("examples").Table("marvel").Insert([]interface{}{ map[string]interface{}{"name": "Iron Man", "victories": 214}, map[string]interface{}{"name": "Jubilee", "victories": 9}, }).Exec(session) diff --git a/mock_test.go b/mock_test.go index 2ec33ea6..0320bfb2 100644 --- a/mock_test.go +++ b/mock_test.go @@ -4,9 +4,18 @@ import ( "fmt" test "gopkg.in/check.v1" + "testing" + "gopkg.in/gorethink/gorethink.v3/internal/integration/tests" ) -func (s *RethinkSuite) TestMockExecSuccess(c *test.C) { +// Hook up gocheck into the gotest runner. +func Test(t *testing.T) { test.TestingT(t) } + +type MockSuite struct{} + +var _ = test.Suite(&MockSuite{}) + +func (s *MockSuite) TestMockExecSuccess(c *test.C) { mock := NewMock() mock.On(DB("test").Table("test").Insert(map[string]string{ "id": "mocked", @@ -19,7 +28,7 @@ func (s *RethinkSuite) TestMockExecSuccess(c *test.C) { mock.AssertExpectations(c) } -func (s *RethinkSuite) TestMockExecFail(c *test.C) { +func (s *MockSuite) TestMockExecFail(c *test.C) { mock := NewMock() mock.On(DB("test").Table("test").Insert(map[string]string{ "id": "mocked", @@ -32,7 +41,7 @@ func (s *RethinkSuite) TestMockExecFail(c *test.C) { mock.AssertExpectations(c) } -func (s *RethinkSuite) TestMockRunSuccessSingleResult(c *test.C) { +func (s *MockSuite) TestMockRunSuccessSingleResult(c *test.C) { mock := NewMock() mock.On(DB("test").Table("test").Get("mocked")).Return(map[string]interface{}{ "id": "mocked", @@ -45,13 +54,13 @@ func (s *RethinkSuite) TestMockRunSuccessSingleResult(c *test.C) { err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{"id": "mocked"}) + c.Assert(response, tests.JsonEquals, map[string]interface{}{"id": "mocked"}) mock.AssertExpectations(c) res.Close() } -func (s *RethinkSuite) TestMockRunSuccessMultipleResults(c *test.C) { +func (s *MockSuite) TestMockRunSuccessMultipleResults(c *test.C) { mock := NewMock() mock.On(DB("test").Table("test")).Return([]interface{}{ map[string]interface{}{"id": "mocked"}, @@ -64,13 +73,13 @@ func (s *RethinkSuite) TestMockRunSuccessMultipleResults(c *test.C) { err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []interface{}{map[string]interface{}{"id": "mocked"}}) + c.Assert(response, tests.JsonEquals, []interface{}{map[string]interface{}{"id": "mocked"}}) mock.AssertExpectations(c) res.Close() } -func (s *RethinkSuite) TestMockRunSuccessMultipleResults_type(c *test.C) { +func (s *MockSuite) TestMockRunSuccessMultipleResults_type(c *test.C) { type document struct { Id string } @@ -87,13 +96,13 @@ func (s *RethinkSuite) TestMockRunSuccessMultipleResults_type(c *test.C) { err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []document{document{"mocked"}}) + c.Assert(response, tests.JsonEquals, []document{document{"mocked"}}) mock.AssertExpectations(c) res.Close() } -func (s *RethinkSuite) TestMockRunMissingMock(c *test.C) { +func (s *MockSuite) TestMockRunMissingMock(c *test.C) { mock := NewMock() mock.On(DB("test").Table("test")).Return([]interface{}{ map[string]interface{}{"id": "mocked"}, @@ -107,7 +116,7 @@ func (s *RethinkSuite) TestMockRunMissingMock(c *test.C) { mock.AssertExpectations(c) } -func (s *RethinkSuite) TestMockRunMissingQuery(c *test.C) { +func (s *MockSuite) TestMockRunMissingQuery(c *test.C) { mock := NewMock() mock.On(DB("test").Table("test")).Return([]interface{}{ map[string]interface{}{"id": "mocked"}, @@ -121,7 +130,7 @@ func (s *RethinkSuite) TestMockRunMissingQuery(c *test.C) { c.Assert(t.Failed(), test.Equals, true) } -func (s *RethinkSuite) TestMockRunMissingQuerySingle(c *test.C) { +func (s *MockSuite) TestMockRunMissingQuerySingle(c *test.C) { mock := NewMock() mock.On(DB("test").Table("test")).Return([]interface{}{ map[string]interface{}{"id": "mocked"}, @@ -133,7 +142,7 @@ func (s *RethinkSuite) TestMockRunMissingQuerySingle(c *test.C) { c.Assert(t.Failed(), test.Equals, true) } -func (s *RethinkSuite) TestMockRunMissingQueryMultiple(c *test.C) { +func (s *MockSuite) TestMockRunMissingQueryMultiple(c *test.C) { mock := NewMock() mock.On(DB("test").Table("test")).Return([]interface{}{ map[string]interface{}{"id": "mocked"}, @@ -147,7 +156,7 @@ func (s *RethinkSuite) TestMockRunMissingQueryMultiple(c *test.C) { c.Assert(t.Failed(), test.Equals, true) } -func (s *RethinkSuite) TestMockRunMutlipleQueries(c *test.C) { +func (s *MockSuite) TestMockRunMutlipleQueries(c *test.C) { mock := NewMock() mock.On(DB("test").Table("test").Get("mocked1")).Return(map[string]interface{}{ "id": "mocked1", @@ -165,7 +174,7 @@ func (s *RethinkSuite) TestMockRunMutlipleQueries(c *test.C) { err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{"id": "mocked1"}) + c.Assert(response, tests.JsonEquals, map[string]interface{}{"id": "mocked1"}) // Query 2 res, err = DB("test").Table("test").Get("mocked1").Run(mock) @@ -174,7 +183,7 @@ func (s *RethinkSuite) TestMockRunMutlipleQueries(c *test.C) { err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{"id": "mocked1"}) + c.Assert(response, tests.JsonEquals, map[string]interface{}{"id": "mocked1"}) // Query 3 res, err = DB("test").Table("test").Get("mocked2").Run(mock) @@ -183,12 +192,12 @@ func (s *RethinkSuite) TestMockRunMutlipleQueries(c *test.C) { err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, map[string]interface{}{"id": "mocked2"}) + c.Assert(response, tests.JsonEquals, map[string]interface{}{"id": "mocked2"}) mock.AssertExpectations(c) } -func (s *RethinkSuite) TestMockQueriesWithFuncs(c *test.C) { +func (s *MockSuite) TestMockQueriesWithFuncs(c *test.C) { mock := NewMock() mock.On(Expr([]int{2}).Map(func(row Term) interface{} { return row.Add(1) @@ -211,7 +220,7 @@ func (s *RethinkSuite) TestMockQueriesWithFuncs(c *test.C) { err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []int{3}) + c.Assert(response, tests.JsonEquals, []int{3}) // Query 2 res, err = Expr([]int{2}).Map(func(row Term) interface{} { @@ -222,7 +231,7 @@ func (s *RethinkSuite) TestMockQueriesWithFuncs(c *test.C) { err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []int{3}) + c.Assert(response, tests.JsonEquals, []int{3}) // Query 3 res, err = Expr([]int{4}).Map(func(row1, row2 Term) interface{} { @@ -233,7 +242,7 @@ func (s *RethinkSuite) TestMockQueriesWithFuncs(c *test.C) { err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []int{5}) + c.Assert(response, tests.JsonEquals, []int{5}) // Query 5 res, err = Expr([]int{9}).Map(func(row1, row2 Term) interface{} { @@ -244,12 +253,12 @@ func (s *RethinkSuite) TestMockQueriesWithFuncs(c *test.C) { err = res.All(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, []int{10}) + c.Assert(response, tests.JsonEquals, []int{10}) mock.AssertExpectations(c) } -func (s *RethinkSuite) TestMockAnything(c *test.C) { +func (s *MockSuite) TestMockAnything(c *test.C) { mock := NewMock() mock.On(MockAnything()).Return("okay", nil).Times(1) mock.On(Table("test").MockAnything()).Return("okay2", nil).Times(1) @@ -267,7 +276,7 @@ func (s *RethinkSuite) TestMockAnything(c *test.C) { err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, "okay") + c.Assert(response, tests.JsonEquals, "okay") // Query 2 res, err = Table("test").Get("mocked1").Run(mock) @@ -276,7 +285,7 @@ func (s *RethinkSuite) TestMockAnything(c *test.C) { err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, "okay2") + c.Assert(response, tests.JsonEquals, "okay2") // Query 3 res, err = Table("test").Insert(map[string]interface{}{ @@ -287,7 +296,7 @@ func (s *RethinkSuite) TestMockAnything(c *test.C) { err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, "okay3") + c.Assert(response, tests.JsonEquals, "okay3") // Query 3 res, err = Expr([]interface{}{1, 2, 3}).Run(mock) @@ -296,7 +305,7 @@ func (s *RethinkSuite) TestMockAnything(c *test.C) { err = res.One(&response) c.Assert(err, test.IsNil) - c.Assert(response, jsonEquals, "okay4") + c.Assert(response, tests.JsonEquals, "okay4") mock.AssertExpectations(c) } diff --git a/mocks_test.go b/mocks_test.go new file mode 100644 index 00000000..ee3efb32 --- /dev/null +++ b/mocks_test.go @@ -0,0 +1,55 @@ +package gorethink + +import ( + "github.com/stretchr/testify/mock" + "time" + "net" +) + +type connMock struct { + mock.Mock +} + +func (m* connMock) Read(b []byte) (n int, err error) { + args := m.Called(len(b)) + rbuf, ok := args.Get(0).([]byte) + if ok { + copy(b, rbuf) + } + return args.Int(1), args.Error(2) +} + +func (m* connMock) Write(b []byte) (n int, err error) { + args := m.Called(b) + return args.Int(0), args.Error(1) +} + +func (m* connMock) Close() error { + args := m.Called() + return args.Error(0) +} + +func (m* connMock) LocalAddr() net.Addr { + args := m.Called() + return args.Get(0).(net.Addr) +} + +func (m* connMock) RemoteAddr() net.Addr { + args := m.Called() + return args.Get(0).(net.Addr) +} + +func (m* connMock) SetDeadline(t time.Time) error { + args := m.Called(t) + return args.Error(0) +} + +func (m* connMock) SetReadDeadline(t time.Time) error { + args := m.Called(t) + return args.Error(0) +} + +func (m* connMock) SetWriteDeadline(t time.Time) error { + args := m.Called(t) + return args.Error(0) +} From 2b5d135c17815434aaaed5aef613238305b66db1 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Fri, 8 Dec 2017 12:15:46 +0000 Subject: [PATCH 08/13] fix tests --- connection.go | 15 ++++--- connection_test.go | 4 +- .../tests/cluster_integration_test.go | 41 +++++++++++++++---- internal/integration/tests/cluster_test.go | 15 +++---- internal/integration/tests/query_test.go | 6 +-- 5 files changed, 55 insertions(+), 26 deletions(-) diff --git a/connection.go b/connection.go index 51069e47..d5128772 100644 --- a/connection.go +++ b/connection.go @@ -75,7 +75,7 @@ type tokenAndPromise struct { ctx context.Context query *Query promise chan responseAndCursor - span opentracing.Span + span opentracing.Span } // NewConnection creates a new connection to the database server @@ -110,12 +110,14 @@ func NewConnection(address string, opts *ConnectOpts) (*Connection, error) { return nil, err } + c.runConnection() + return c, nil } func newConnection(conn net.Conn, address string, opts *ConnectOpts) *Connection { c := &Connection{ - Conn: conn, + Conn: conn, address: address, opts: opts, cursors: make(map[int64]*Cursor), @@ -125,11 +127,12 @@ func newConnection(conn net.Conn, address string, opts *ConnectOpts) *Connection readRequestsChan: make(chan tokenAndPromise, 16), responseChan: make(chan responseAndError, 16), } + return c +} +func (c *Connection) runConnection() { go c.readSocket() go c.processResponses() - - return c } // Close closes the underlying net.Conn @@ -234,7 +237,7 @@ func (c *Connection) stopQuery(q *Query) (*Response, *Cursor, error) { return nil, nil, ErrQueryTimeout } -func (c* Connection) startTracingSpan(parentSpan opentracing.Span, q *Query) opentracing.Span { +func (c *Connection) startTracingSpan(parentSpan opentracing.Span, q *Query) opentracing.Span { span := parentSpan.Tracer().StartSpan( "Query_"+q.Type.String(), opentracing.ChildOf(parentSpan.Context()), @@ -436,7 +439,7 @@ func (c *Connection) readResponse() (*Response, error) { // Called to fill response for the query func (c *Connection) processResponse(ctx context.Context, q Query, response *Response, span opentracing.Span) (r *Response, cur *Cursor, err error) { if span != nil { - defer func(){ + defer func() { if err != nil { ext.Error.Set(span, true) span.LogFields(log.Error(err)) diff --git a/connection_test.go b/connection_test.go index 85eaf537..9d8a52ec 100644 --- a/connection_test.go +++ b/connection_test.go @@ -6,7 +6,6 @@ import ( "golang.org/x/net/context" "encoding/binary" "encoding/json" - "gopkg.in/gorethink/gorethink.v3/internal/integration/tests" ) type ConnectionSuite struct{} @@ -27,13 +26,14 @@ func (s *ConnectionSuite) TestConnection_Query_Ok(c *test.C) { conn.On("Read", len(respData)).Return(respData, len(respData), nil) connection := newConnection(conn, "addr", &ConnectOpts{}) + connection.runConnection() response, cursor, err := connection.Query(ctx, q) c.Assert(response, test.NotNil) c.Assert(response.Token, test.Equals, token) c.Assert(response.Type, test.Equals, p.Response_SUCCESS_ATOM) c.Assert(response.Responses, test.HasLen, 1) - c.Assert(response.Responses[0], tests.JsonEquals, "response") + c.Assert(response.Responses[0], test.DeepEquals, json.RawMessage([]byte(`"response"`))) c.Assert(cursor, test.NotNil) c.Assert(cursor.token, test.Equals, token) c.Assert(cursor.conn, test.Equals, connection) diff --git a/internal/integration/tests/cluster_integration_test.go b/internal/integration/tests/cluster_integration_test.go index 93b1ddb6..5a920622 100644 --- a/internal/integration/tests/cluster_integration_test.go +++ b/internal/integration/tests/cluster_integration_test.go @@ -7,10 +7,17 @@ import ( "time" test "gopkg.in/check.v1" + r "gopkg.in/gorethink/gorethink.v3" + "strings" + "strconv" ) func (s *RethinkSuite) TestClusterDetectNewNode(c *test.C) { - session, err := Connect(ConnectOpts{ + h1, p1 := splitAddress(url) + h2, p2 := splitAddress(url2) + hosts := []r.Host{r.NewHost(h1, p1), r.NewHost(h2, p2)} + + cluster, err := r.NewCluster(hosts, &r.ConnectOpts{ Addresses: []string{url, url2}, DiscoverHosts: true, NodeRefreshInterval: time.Second, @@ -25,7 +32,7 @@ func (s *RethinkSuite) TestClusterDetectNewNode(c *test.C) { c.Fatal("No node was added to the cluster") default: // Pass if another node was added - if len(session.cluster.GetNodes()) >= 3 { + if len(cluster.GetNodes()) >= 3 { return } } @@ -33,7 +40,11 @@ func (s *RethinkSuite) TestClusterDetectNewNode(c *test.C) { } func (s *RethinkSuite) TestClusterRecoverAfterNoNodes(c *test.C) { - session, err := Connect(ConnectOpts{ + h1, p1 := splitAddress(url) + h2, p2 := splitAddress(url2) + hosts := []r.Host{r.NewHost(h1, p1), r.NewHost(h2, p2)} + + cluster, err := r.NewCluster(hosts, &r.ConnectOpts{ Addresses: []string{url, url2}, DiscoverHosts: true, NodeRefreshInterval: time.Second, @@ -49,12 +60,12 @@ func (s *RethinkSuite) TestClusterRecoverAfterNoNodes(c *test.C) { c.Fatal("No node was added to the cluster") default: // Check if there are no nodes - if len(session.cluster.GetNodes()) == 0 { + if len(cluster.GetNodes()) == 0 { hasHadZeroNodes = true } // Pass if another node was added - if len(session.cluster.GetNodes()) >= 1 && hasHadZeroNodes { + if len(cluster.GetNodes()) >= 1 && hasHadZeroNodes { return } } @@ -62,7 +73,7 @@ func (s *RethinkSuite) TestClusterRecoverAfterNoNodes(c *test.C) { } func (s *RethinkSuite) TestClusterNodeHealth(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Addresses: []string{url1, url2, url3}, DiscoverHosts: true, NodeRefreshInterval: time.Second, @@ -90,10 +101,26 @@ func (s *RethinkSuite) TestClusterNodeHealth(c *test.C) { return default: attempts++ - if err := Expr(1).Exec(session); err != nil { + if err := r.Expr(1).Exec(session); err != nil { c.Logf("Query failed, %s", err) failed++ } } } } + +func splitAddress(address string) (hostname string, port int) { + hostname = "localhost" + port = 28015 + + addrParts := strings.Split(address, ":") + + if len(addrParts) >= 1 { + hostname = addrParts[0] + } + if len(addrParts) >= 2 { + port, _ = strconv.Atoi(addrParts[1]) + } + + return +} diff --git a/internal/integration/tests/cluster_test.go b/internal/integration/tests/cluster_test.go index a9a39805..ae8fcd8e 100644 --- a/internal/integration/tests/cluster_test.go +++ b/internal/integration/tests/cluster_test.go @@ -7,15 +7,16 @@ import ( "time" test "gopkg.in/check.v1" + r "gopkg.in/gorethink/gorethink.v3" ) func (s *RethinkSuite) TestClusterConnect(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Addresses: []string{url1, url2, url3}, }) c.Assert(err, test.IsNil) - row, err := Expr("Hello World").Run(session) + row, err := r.Expr("Hello World").Run(session) c.Assert(err, test.IsNil) var response string @@ -25,13 +26,13 @@ func (s *RethinkSuite) TestClusterConnect(c *test.C) { } func (s *RethinkSuite) TestClusterMultipleQueries(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Addresses: []string{url1, url2, url3}, }) c.Assert(err, test.IsNil) for i := 0; i < 1000; i++ { - row, err := Expr(fmt.Sprintf("Hello World %v", i)).Run(session) + row, err := r.Expr(fmt.Sprintf("Hello World %v", i)).Run(session) c.Assert(err, test.IsNil) var response string @@ -43,7 +44,7 @@ func (s *RethinkSuite) TestClusterMultipleQueries(c *test.C) { func (s *RethinkSuite) TestClusterConnectError(c *test.C) { var err error - _, err = Connect(ConnectOpts{ + _, err = r.Connect(r.ConnectOpts{ Addresses: []string{"nonexistanturl"}, Timeout: time.Second, }) @@ -51,13 +52,13 @@ func (s *RethinkSuite) TestClusterConnectError(c *test.C) { } func (s *RethinkSuite) TestClusterConnectDatabase(c *test.C) { - session, err := Connect(ConnectOpts{ + session, err := r.Connect(r.ConnectOpts{ Addresses: []string{url1, url2, url3}, Database: "test2", }) c.Assert(err, test.IsNil) - _, err = Table("test2").Run(session) + _, err = r.Table("test2").Run(session) c.Assert(err, test.NotNil) c.Assert(err.Error(), test.Equals, "gorethink: Database `test2` does not exist. in:\nr.Table(\"test2\")") } diff --git a/internal/integration/tests/query_test.go b/internal/integration/tests/query_test.go index 6e3dac26..d02d4c55 100644 --- a/internal/integration/tests/query_test.go +++ b/internal/integration/tests/query_test.go @@ -457,11 +457,10 @@ func (s *RethinkSuite) TestTableChanges(c *test.C) { n++ } + defer wg.Done() if res.Err() != nil { c.Fatal(res.Err()) } - - wg.Done() }() r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 1}).Exec(session) @@ -577,11 +576,10 @@ func (s *RethinkSuite) TestTableChangesIncludeInitial(c *test.C) { n++ } + defer wg.Done() if res.Err() != nil { c.Fatal(res.Err()) } - - wg.Done() }() r.DB("test").Table("changes").Insert(map[string]interface{}{"n": 6}).Exec(session) From e6087a816d9f249980434e000cdbbafe79690456 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Fri, 8 Dec 2017 16:25:01 +0000 Subject: [PATCH 09/13] connection unit tests --- .gitignore | 2 + Makefile | 8 ++ connection.go | 5 + connection_test.go | 289 ++++++++++++++++++++++++++++++++++++++++++++- mocks_test.go | 6 +- 5 files changed, 304 insertions(+), 6 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 125f317e..588303d5 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ _testmain.go *.exe .wercker + +cover.html diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..d31d9b71 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +test: + test -d ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3 && mv ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3 ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3.bak; true + cp -R . ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3 + go test -coverprofile=cover.out -race gopkg.in/gorethink/gorethink.v3; true + go tool cover -html=cover.out -o cover.html; true + rm -f cover.out; true + rm -rf ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3 + test -d ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3.bak && mv ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3.bak ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3; true diff --git a/connection.go b/connection.go index d5128772..1a03a62b 100644 --- a/connection.go +++ b/connection.go @@ -201,6 +201,9 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er ext.Error.Set(fetchingSpan, true) fetchingSpan.LogFields(log.Error(err)) fetchingSpan.Finish() + if q.Type == p.Query_START { + opentracing.SpanFromContext(ctx).Finish() + } } return nil, nil, err } @@ -290,6 +293,7 @@ func (c *Connection) processResponses() { close(rr.promise) } } + readRequests = []tokenAndPromise{} c.Close() continue } @@ -317,6 +321,7 @@ func (c *Connection) processResponses() { case <-c.stopReadChan: for _, rr := range readRequests { if rr.promise != nil { + rr.promise <- responseAndCursor{err: ErrConnectionClosed} close(rr.promise) } } diff --git a/connection_test.go b/connection_test.go index 9d8a52ec..1bbdc146 100644 --- a/connection_test.go +++ b/connection_test.go @@ -6,6 +6,10 @@ import ( "golang.org/x/net/context" "encoding/binary" "encoding/json" + "io" + "time" + "github.com/opentracing/opentracing-go/mocktracer" + "github.com/opentracing/opentracing-go" ) type ConnectionSuite struct{} @@ -15,7 +19,7 @@ var _ = test.Suite(&ConnectionSuite{}) func (s *ConnectionSuite) TestConnection_Query_Ok(c *test.C) { ctx := context.Background() token := int64(1) - q := testQuery() + q := testQuery(DB("db").Table("table").Get("id")) writeData := serializeQuery(token, q) respData := serializeAtomResponse() header := respHeader(token, respData) @@ -24,10 +28,12 @@ func (s *ConnectionSuite) TestConnection_Query_Ok(c *test.C) { conn.On("Write", writeData).Return(len(writeData), nil) conn.On("Read", respHeaderLen).Return(header, respHeaderLen, nil) conn.On("Read", len(respData)).Return(respData, len(respData), nil) + conn.On("Close").Return(nil) connection := newConnection(conn, "addr", &ConnectOpts{}) connection.runConnection() response, cursor, err := connection.Query(ctx, q) + connection.Close() c.Assert(response, test.NotNil) c.Assert(response.Token, test.Equals, token) @@ -43,9 +49,286 @@ func (s *ConnectionSuite) TestConnection_Query_Ok(c *test.C) { conn.AssertExpectations(c) } -func testQuery() Query { +func (s *ConnectionSuite) TestConnection_Query_DefaultDBOk(c *test.C) { + ctx := context.Background() + token := int64(1) + q := testQuery(Table("table").Get("id"),) + q2 := q + q2.Opts["db"], _ = DB("db").Build() + writeData := serializeQuery(token, q2) + respData := serializeAtomResponse() + header := respHeader(token, respData) + + conn := &connMock{} + conn.On("Write", writeData).Return(len(writeData), nil) + conn.On("Read", respHeaderLen).Return(header, respHeaderLen, nil) + conn.On("Read", len(respData)).Return(respData, len(respData), nil) + conn.On("Close").Return(nil) + + connection := newConnection(conn, "addr", &ConnectOpts{Database: "db"}) + connection.runConnection() + response, cursor, err := connection.Query(ctx, q) + connection.Close() + + c.Assert(response, test.NotNil) + c.Assert(response.Token, test.Equals, token) + c.Assert(response.Type, test.Equals, p.Response_SUCCESS_ATOM) + c.Assert(response.Responses, test.HasLen, 1) + c.Assert(response.Responses[0], test.DeepEquals, json.RawMessage([]byte(`"response"`))) + c.Assert(cursor, test.NotNil) + c.Assert(cursor.token, test.Equals, token) + c.Assert(cursor.conn, test.Equals, connection) + c.Assert(cursor.ctx, test.Equals, ctx) + c.Assert(cursor.responses, test.DeepEquals, response.Responses) + c.Assert(err, test.IsNil) + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_Query_Nil(c *test.C) { + response, cursor, err := (*Connection)(nil).Query(nil, Query{}) + c.Assert(err, test.Equals, ErrConnectionClosed) + c.Assert(response, test.IsNil) + c.Assert(cursor, test.IsNil) +} + +func (s *ConnectionSuite) TestConnection_Query_NilConn(c *test.C) { + connection := newConnection(nil, "addr", &ConnectOpts{Database: "db"}) + response, cursor, err := connection.Query(nil, Query{}) + c.Assert(err, test.Equals, ErrConnectionClosed) + c.Assert(response, test.IsNil) + c.Assert(cursor, test.IsNil) +} + +func (s *ConnectionSuite) TestConnection_Query_SendFail(c *test.C) { + ctx := context.Background() + token := int64(1) + q := testQuery(DB("db").Table("table").Get("id")) + writeData := serializeQuery(token, q) + + conn := &connMock{} + conn.On("Write", writeData).Return(0, io.EOF) + + connection := newConnection(conn, "addr", &ConnectOpts{}) + response, cursor, err := connection.Query(ctx, q) + + c.Assert(response, test.IsNil) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.Equals, RQLConnectionError{rqlError(io.EOF.Error())}) + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_Query_NoReplyOk(c *test.C) { + token := int64(1) + q := testQuery(DB("db").Table("table").Get("id")) + q.Opts["noreply"] = true + writeData := serializeQuery(token, q) + respData := serializeAtomResponse() + header := respHeader(token, respData) + + conn := &connMock{} + conn.On("Write", writeData).Return(len(writeData), nil) + conn.On("Read", respHeaderLen).Return(header, respHeaderLen, nil) + conn.On("Read", len(respData)).Return(respData, len(respData), nil) + conn.On("Close").Return(nil) + + connection := newConnection(conn, "addr", &ConnectOpts{}) + connection.runConnection() + response, cursor, err := connection.Query(nil, q) + time.Sleep(5*time.Millisecond) + connection.Close() + + c.Assert(response, test.IsNil) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.IsNil) + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_Query_NoReplyTimeoutWrite(c *test.C) { + ctx, cancel := context.WithCancel(context.Background()) + token := int64(1) + q := testQuery(DB("db").Table("table").Get("id")) + q.Opts["noreply"] = true + writeData := serializeQuery(token, q) + stopData := serializeQuery(token, newStopQuery(token)) + + conn := &connMock{} + conn.On("Write", writeData).Return(len(writeData), nil) + conn.On("Write", stopData).Return(len(stopData), nil) + conn.On("SetWriteDeadline").Return(nil) + + connection := newConnection(conn, "addr", &ConnectOpts{ReadTimeout: time.Millisecond, WriteTimeout: time.Millisecond}) + connection.readRequestsChan = make(chan tokenAndPromise, 0) + cancel() + response, cursor, err := connection.Query(ctx, q) + + c.Assert(response, test.IsNil) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.Equals, ErrQueryTimeout) + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_Query_TimeoutWrite(c *test.C) { + ctx, cancel := context.WithCancel(context.Background()) + token := int64(1) + q := testQuery(DB("db").Table("table").Get("id")) + writeData := serializeQuery(token, q) + stopData := serializeQuery(token, newStopQuery(token)) + + conn := &connMock{} + conn.On("Write", writeData).Return(len(writeData), nil) + conn.On("Write", stopData).Return(len(stopData), nil) + conn.On("SetWriteDeadline").Return(nil) + + connection := newConnection(conn, "addr", &ConnectOpts{ReadTimeout: time.Millisecond, WriteTimeout: time.Millisecond}) + connection.readRequestsChan = make(chan tokenAndPromise, 0) + cancel() + response, cursor, err := connection.Query(ctx, q) + + c.Assert(response, test.IsNil) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.Equals, ErrQueryTimeout) + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_Query_TimeoutRead(c *test.C) { + ctx, _ := context.WithTimeout(context.Background(), 5*time.Millisecond) + token := int64(1) + q := testQuery(DB("db").Table("table").Get("id")) + writeData := serializeQuery(token, q) + stopData := serializeQuery(token, newStopQuery(token)) + + conn := &connMock{} + conn.On("Write", writeData).Return(len(writeData), nil) + conn.On("Write", stopData).Return(len(stopData), nil) + conn.On("SetWriteDeadline").Return(nil) + + connection := newConnection(conn, "addr", &ConnectOpts{ReadTimeout: time.Millisecond, WriteTimeout: time.Millisecond}) + response, cursor, err := connection.Query(ctx, q) + + c.Assert(response, test.IsNil) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.Equals, ErrQueryTimeout) + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_Query_SendFailTracing(c *test.C) { + tracer := mocktracer.New() + rootSpan := tracer.StartSpan("root") + ctx := opentracing.ContextWithSpan(context.Background(), rootSpan) + token := int64(1) + q := testQuery(DB("db").Table("table").Get("id")) + writeData := serializeQuery(token, q) + + conn := &connMock{} + conn.On("Write", writeData).Return(0, io.EOF) + + connection := newConnection(conn, "addr", &ConnectOpts{UseOpentracing: true}) + response, cursor, err := connection.Query(ctx, q) + + c.Assert(response, test.IsNil) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.Equals, RQLConnectionError{rqlError(io.EOF.Error())}) + conn.AssertExpectations(c) + c.Assert(tracer.FinishedSpans(), test.HasLen, 2) +} + +func (s *ConnectionSuite) TestConnection_processResponses_SocketErr(c *test.C) { + promise1 := make(chan responseAndCursor, 1) + promise2 := make(chan responseAndCursor, 1) + promise3 := make(chan responseAndCursor, 1) + + conn := &connMock{} + conn.On("Close").Return(nil) + + connection := newConnection(conn, "addr", &ConnectOpts{}) + + go connection.processResponses() + + connection.readRequestsChan <- tokenAndPromise{query: &Query{Token: 1}, promise: promise1} + connection.readRequestsChan <- tokenAndPromise{query: &Query{Token: 2}, promise: promise2} + connection.readRequestsChan <- tokenAndPromise{query: &Query{Token: 2}, promise: promise3} + time.Sleep(5*time.Millisecond) + connection.responseChan <- responseAndError{err: io.EOF} + time.Sleep(5*time.Millisecond) + + select { + case f := <-promise1: + c.Assert(f.err, test.Equals, io.EOF) + c.Assert(f.response, test.IsNil) + default: + c.Fail() + } + select { + case f := <-promise2: + c.Assert(f.err, test.Equals, io.EOF) + c.Assert(f.response, test.IsNil) + default: + c.Fail() + } + select { + case f := <-promise3: + c.Assert(f.err, test.Equals, io.EOF) + c.Assert(f.response, test.IsNil) + default: + c.Fail() + } + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_processResponses_StopOk(c *test.C) { + promise1 := make(chan responseAndCursor, 1) + + connection := newConnection(nil, "addr", &ConnectOpts{}) + + go connection.processResponses() + + connection.readRequestsChan <- tokenAndPromise{query: &Query{Token: 1}, promise: promise1} + close(connection.responseChan) + time.Sleep(5*time.Millisecond) + close(connection.stopReadChan) + time.Sleep(5*time.Millisecond) + + select { + case f := <-promise1: + c.Assert(f.err, test.Equals, ErrConnectionClosed) + c.Assert(f.response, test.IsNil) + default: + c.Fail() + } +} + +func (s *ConnectionSuite) TestConnection_processResponses_ResponseFirst(c *test.C) { + promise1 := make(chan responseAndCursor, 1) + response1 := &Response{Token:1, Type: p.Response_RUNTIME_ERROR, ErrorType: p.Response_INTERNAL} + + conn := &connMock{} + conn.On("Close").Return(nil) + + connection := newConnection(conn, "addr", &ConnectOpts{}) + + go connection.processResponses() + + connection.responseChan <- responseAndError{response: response1} + time.Sleep(5*time.Millisecond) + connection.readRequestsChan <- tokenAndPromise{query: &Query{Token: 1}, promise: promise1} + time.Sleep(5*time.Millisecond) + connection.Close() + time.Sleep(5*time.Millisecond) + + select { + case f := <-promise1: + c.Assert(f.err, test.FitsTypeOf, RQLInternalError{}) + c.Assert(f.response, test.Equals, response1) + c.Assert(f.cursor, test.IsNil) + default: + c.Fail() + } + conn.AssertExpectations(c) +} + +func testQuery(t Term) Query { q, _ := newQuery( - DB("db").Table("table").Get("id"), + t, map[string]interface{}{}, &ConnectOpts{}, ) diff --git a/mocks_test.go b/mocks_test.go index ee3efb32..6664f221 100644 --- a/mocks_test.go +++ b/mocks_test.go @@ -40,16 +40,16 @@ func (m* connMock) RemoteAddr() net.Addr { } func (m* connMock) SetDeadline(t time.Time) error { - args := m.Called(t) + args := m.Called() return args.Error(0) } func (m* connMock) SetReadDeadline(t time.Time) error { - args := m.Called(t) + args := m.Called() return args.Error(0) } func (m* connMock) SetWriteDeadline(t time.Time) error { - args := m.Called(t) + args := m.Called() return args.Error(0) } From 233a03188e0c0d52155ccc7c20c2dad2b99174c7 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Tue, 12 Dec 2017 16:19:31 +0000 Subject: [PATCH 10/13] connection tests --- connection.go | 2 - connection_test.go | 219 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+), 2 deletions(-) diff --git a/connection.go b/connection.go index 1a03a62b..3095d19e 100644 --- a/connection.go +++ b/connection.go @@ -457,10 +457,8 @@ func (c *Connection) processResponse(ctx context.Context, q Query, response *Res case p.Response_CLIENT_ERROR: return response, c.processErrorResponse(response), createClientError(response, q.Term) case p.Response_COMPILE_ERROR: - c.processErrorResponse(response) return response, c.processErrorResponse(response), createCompileError(response, q.Term) case p.Response_RUNTIME_ERROR: - c.processErrorResponse(response) return response, c.processErrorResponse(response), createRuntimeError(response.ErrorType, response, q.Term) case p.Response_SUCCESS_ATOM, p.Response_SERVER_INFO: return c.processAtomResponse(ctx, q, response) diff --git a/connection_test.go b/connection_test.go index 1bbdc146..0e235ea9 100644 --- a/connection_test.go +++ b/connection_test.go @@ -326,6 +326,225 @@ func (s *ConnectionSuite) TestConnection_processResponses_ResponseFirst(c *test. conn.AssertExpectations(c) } +func (s *ConnectionSuite) TestConnection_readResponse_TimeoutHeader(c *test.C) { + timeout := time.Second + + conn := &connMock{} + conn.On("SetReadDeadline").Return(nil) + conn.On("Read", respHeaderLen).Return(nil, 0, io.EOF) + + connection := newConnection(conn, "addr", &ConnectOpts{ReadTimeout: timeout}) + + response, err := connection.readResponse() + + c.Assert(response, test.IsNil) + c.Assert(err, test.FitsTypeOf, RQLConnectionError{}) + c.Assert(connection.isBad(), test.Equals, true) + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_readResponse_BodySocketErr(c *test.C) { + token := int64(5) + respData := serializeAtomResponse() + header := respHeader(token, respData) + + conn := &connMock{} + conn.On("Read", respHeaderLen).Return(header, len(header), nil) + conn.On("Read", len(respData)).Return(nil, 0, io.EOF) + + connection := newConnection(conn, "addr", &ConnectOpts{}) + + response, err := connection.readResponse() + + c.Assert(response, test.IsNil) + c.Assert(err, test.FitsTypeOf, RQLConnectionError{}) + c.Assert(connection.isBad(), test.Equals, true) + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_readResponse_BodyUnmarshalErr(c *test.C) { + token := int64(5) + respData := serializeAtomResponse() + header := respHeader(token, respData) + + conn := &connMock{} + conn.On("Read", respHeaderLen).Return(header, len(header), nil) + conn.On("Read", len(respData)).Return(make([]byte, len(respData)), len(respData), nil) + + connection := newConnection(conn, "addr", &ConnectOpts{}) + + response, err := connection.readResponse() + + c.Assert(response, test.IsNil) + c.Assert(err, test.FitsTypeOf, RQLDriverError{}) + c.Assert(connection.isBad(), test.Equals, true) + conn.AssertExpectations(c) +} + +func (s *ConnectionSuite) TestConnection_processResponse_ClientErrOk(c *test.C) { + ctx := context.Background() + token := int64(3) + q := Query{Token: token} + response := &Response{Token: token, Type: p.Response_CLIENT_ERROR} + + connection := newConnection(nil, "addr", &ConnectOpts{}) + + resp, cursor, err := connection.processResponse(ctx, q, response, nil) + + c.Assert(resp, test.Equals, response) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.FitsTypeOf, RQLClientError{}) +} + +func (s *ConnectionSuite) TestConnection_processResponse_CompileErrOk(c *test.C) { + ctx := context.Background() + token := int64(3) + q := Query{Token: token} + response := &Response{Token: token, Type: p.Response_COMPILE_ERROR} + + connection := newConnection(nil, "addr", &ConnectOpts{}) + + resp, cursor, err := connection.processResponse(ctx, q, response, nil) + + c.Assert(resp, test.Equals, response) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.FitsTypeOf, RQLCompileError{}) +} + +func (s *ConnectionSuite) TestConnection_processResponse_RuntimeErrOk(c *test.C) { + tracer := mocktracer.New() + rootSpan := tracer.StartSpan("root") + ctx := opentracing.ContextWithSpan(context.Background(), rootSpan) + qSpan := rootSpan.Tracer().StartSpan("q", opentracing.ChildOf(rootSpan.Context())) + + token := int64(3) + term := Table("test") + q := Query{Token: token, Term: &term} + response := &Response{Token: token, Type: p.Response_RUNTIME_ERROR, Responses: []json.RawMessage{{'e', 'r', 'r'}}} + + connection := newConnection(nil, "addr", &ConnectOpts{}) + + resp, cursor, err := connection.processResponse(ctx, q, response, qSpan) + + c.Assert(resp, test.Equals, response) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.FitsTypeOf, RQLRuntimeError{}) + c.Assert(tracer.FinishedSpans(), test.HasLen, 1) + c.Assert(tracer.FinishedSpans()[0].Tags()["error"], test.Equals, true) +} + +func (s *ConnectionSuite) TestConnection_processResponse_FirstPartialOk(c *test.C) { + ctx := context.Background() + token := int64(3) + q := Query{Token: token} + rawResponse1 := json.RawMessage{1,2,3} + rawResponse2 := json.RawMessage{3,4,5} + response := &Response{Token: token, Type: p.Response_SUCCESS_PARTIAL, Responses: []json.RawMessage{rawResponse1, rawResponse2}} + + connection := newConnection(nil, "addr", &ConnectOpts{}) + + resp, cursor, err := connection.processResponse(ctx, q, response, nil) + + c.Assert(resp, test.Equals, response) + c.Assert(cursor, test.NotNil) + c.Assert(cursor.token, test.Equals, token) + c.Assert(cursor.ctx, test.Equals, ctx) + c.Assert(cursor.responses, test.HasLen, 2) + c.Assert(cursor.responses[0], test.DeepEquals, rawResponse1) + c.Assert(cursor.responses[1], test.DeepEquals, rawResponse2) + c.Assert(cursor.conn, test.Equals, connection) + c.Assert(err, test.IsNil) + c.Assert(connection.cursors, test.HasLen, 1) + c.Assert(connection.cursors[token], test.Equals, cursor) +} + +func (s *ConnectionSuite) TestConnection_processResponse_PartialOk(c *test.C) { + ctx := context.Background() + token := int64(3) + term := Table("test") + q := Query{Token: token} + rawResponse1 := json.RawMessage{1,2,3} + rawResponse2 := json.RawMessage{3,4,5} + response := &Response{Token: token, Type: p.Response_SUCCESS_PARTIAL, Responses: []json.RawMessage{rawResponse1, rawResponse2}} + + connection := newConnection(nil, "addr", &ConnectOpts{}) + oldCursor := newCursor(ctx, connection, "Cursor", token, &term, q.Opts) + connection.cursors[token] = oldCursor + + resp, cursor, err := connection.processResponse(ctx, q, response, nil) + + c.Assert(resp, test.Equals, response) + c.Assert(cursor, test.Equals, oldCursor) + c.Assert(cursor.responses, test.HasLen, 2) + c.Assert(cursor.responses[0], test.DeepEquals, rawResponse1) + c.Assert(cursor.responses[1], test.DeepEquals, rawResponse2) + c.Assert(err, test.IsNil) + c.Assert(connection.cursors, test.HasLen, 1) + c.Assert(connection.cursors[token], test.Equals, cursor) +} + +func (s *ConnectionSuite) TestConnection_processResponse_SequenceOk(c *test.C) { + tracer := mocktracer.New() + rootSpan := tracer.StartSpan("root") + ctx := opentracing.ContextWithSpan(context.Background(), rootSpan) + qSpan := rootSpan.Tracer().StartSpan("q", opentracing.ChildOf(rootSpan.Context())) + + token := int64(3) + q := Query{Token: token} + rawResponse1 := json.RawMessage{1,2,3} + rawResponse2 := json.RawMessage{3,4,5} + response := &Response{Token: token, Type: p.Response_SUCCESS_SEQUENCE, Responses: []json.RawMessage{rawResponse1, rawResponse2}} + + connection := newConnection(nil, "addr", &ConnectOpts{}) + + resp, cursor, err := connection.processResponse(ctx, q, response, qSpan) + + c.Assert(resp, test.Equals, response) + c.Assert(cursor, test.NotNil) + c.Assert(cursor.token, test.Equals, token) + c.Assert(cursor.ctx, test.Equals, ctx) + c.Assert(cursor.responses, test.HasLen, 2) + c.Assert(cursor.responses[0], test.DeepEquals, rawResponse1) + c.Assert(cursor.responses[1], test.DeepEquals, rawResponse2) + c.Assert(cursor.conn, test.Equals, connection) + c.Assert(err, test.IsNil) + c.Assert(connection.cursors, test.HasLen, 0) + c.Assert(tracer.FinishedSpans(), test.HasLen, 1) + c.Assert(tracer.FinishedSpans()[0].Tags(), test.HasLen, 0) +} + +func (s *ConnectionSuite) TestConnection_processResponse_WaitOk(c *test.C) { + ctx := context.Background() + token := int64(3) + q := Query{Token: token} + response := &Response{Token: token, Type: p.Response_WAIT_COMPLETE} + + connection := newConnection(nil, "addr", &ConnectOpts{}) + connection.cursors[token] = &Cursor{} + + resp, cursor, err := connection.processResponse(ctx, q, response, nil) + + c.Assert(resp, test.Equals, response) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.IsNil) + c.Assert(connection.cursors, test.HasLen, 0) +} + +func (s *ConnectionSuite) TestConnection_processResponse_UnexpectedOk(c *test.C) { + ctx := context.Background() + token := int64(3) + q := Query{Token: token} + response := &Response{Token: token, Type: 99} + + connection := newConnection(nil, "addr", &ConnectOpts{}) + + resp, cursor, err := connection.processResponse(ctx, q, response, nil) + + c.Assert(resp, test.IsNil) + c.Assert(cursor, test.IsNil) + c.Assert(err, test.FitsTypeOf, RQLDriverError{}) +} + func testQuery(t Term) Query { q, _ := newQuery( t, From ea25a76ad1e456bb5cc710ca527e2bedb787b55f Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Thu, 14 Dec 2017 13:27:30 +0000 Subject: [PATCH 11/13] try fix builds travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d53857a7..b37b8c11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ cache: apt go_import_path: gopkg.in/gorethink/gorethink.v3 before_script: + - go get -t ./... - source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list - wget -qO- http://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add - - sudo apt-get update From 31a159a972548d73e1bb88c643a5807883ab2b26 Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Thu, 14 Dec 2017 14:22:51 +0000 Subject: [PATCH 12/13] prepare for v4 --- .travis.yml | 11 ++++++----- Makefile | 10 +++++----- README.md | 4 ++-- connection.go | 2 +- connection_handshake.go | 2 +- connection_test.go | 2 +- cursor.go | 4 ++-- errors.go | 2 +- gorethink.go | 2 +- internal/integration/reql_tests/common.go | 4 ++-- internal/integration/reql_tests/gorethink_test.go | 2 +- .../integration/reql_tests/reql_aggregation_test.go | 4 ++-- .../reql_tests/reql_changefeeds_edge_test.go | 4 ++-- .../reql_tests/reql_changefeeds_idxcopy_test.go | 4 ++-- .../reql_changefeeds_include_states_test.go | 4 ++-- .../reql_tests/reql_changefeeds_point_test.go | 4 ++-- .../reql_tests/reql_changefeeds_table_test.go | 4 ++-- internal/integration/reql_tests/reql_control_test.go | 4 ++-- .../integration/reql_tests/reql_datum_array_test.go | 4 ++-- .../integration/reql_tests/reql_datum_binary_test.go | 4 ++-- .../integration/reql_tests/reql_datum_bool_test.go | 4 ++-- .../integration/reql_tests/reql_datum_null_test.go | 4 ++-- .../integration/reql_tests/reql_datum_number_test.go | 4 ++-- .../integration/reql_tests/reql_datum_object_test.go | 4 ++-- .../integration/reql_tests/reql_datum_string_test.go | 4 ++-- .../integration/reql_tests/reql_datum_typeof_test.go | 4 ++-- .../integration/reql_tests/reql_datum_uuid_test.go | 4 ++-- internal/integration/reql_tests/reql_default_test.go | 4 ++-- .../reql_tests/reql_geo_constructors_test.go | 4 ++-- .../integration/reql_tests/reql_geo_geojson_test.go | 4 ++-- .../integration/reql_tests/reql_geo_indexing_test.go | 4 ++-- .../reql_geo_intersection_inclusion_test.go | 4 ++-- .../reql_tests/reql_geo_operations_test.go | 4 ++-- .../reql_tests/reql_geo_primitives_test.go | 4 ++-- internal/integration/reql_tests/reql_joins_test.go | 4 ++-- internal/integration/reql_tests/reql_json_test.go | 4 ++-- internal/integration/reql_tests/reql_match_test.go | 4 ++-- .../reql_tests/reql_math_logic_add_test.go | 4 ++-- .../reql_tests/reql_math_logic_aliases_test.go | 4 ++-- .../reql_tests/reql_math_logic_comparison_test.go | 4 ++-- .../reql_tests/reql_math_logic_div_test.go | 4 ++-- .../reql_math_logic_floor_ceil_round_test.go | 4 ++-- .../reql_tests/reql_math_logic_logic_test.go | 4 ++-- .../reql_tests/reql_math_logic_math_test.go | 4 ++-- .../reql_tests/reql_math_logic_mod_test.go | 4 ++-- .../reql_tests/reql_math_logic_mul_test.go | 4 ++-- .../reql_tests/reql_math_logic_sub_test.go | 4 ++-- .../reql_tests/reql_meta_composite_test.go | 4 ++-- internal/integration/reql_tests/reql_meta_dbs_test.go | 4 ++-- .../integration/reql_tests/reql_meta_table_test.go | 4 ++-- .../reql_tests/reql_mutation_atomic_get_set_test.go | 4 ++-- .../reql_tests/reql_mutation_delete_test.go | 4 ++-- .../reql_tests/reql_mutation_insert_test.go | 4 ++-- .../reql_tests/reql_mutation_replace_test.go | 4 ++-- .../integration/reql_tests/reql_mutation_sync_test.go | 4 ++-- .../reql_tests/reql_mutation_update_test.go | 4 ++-- .../integration/reql_tests/reql_polymorphism_test.go | 4 ++-- internal/integration/reql_tests/reql_random_test.go | 4 ++-- internal/integration/reql_tests/reql_range_test.go | 4 ++-- .../integration/reql_tests/reql_selection_test.go | 4 ++-- .../integration/reql_tests/reql_sindex_api_test.go | 4 ++-- .../reql_tests/reql_sindex_nullsinstrings_test.go | 4 ++-- .../integration/reql_tests/reql_sindex_status_test.go | 4 ++-- internal/integration/reql_tests/reql_timeout_test.go | 4 ++-- .../integration/reql_tests/reql_times_api_test.go | 4 ++-- .../reql_tests/reql_times_constructors_test.go | 4 ++-- .../integration/reql_tests/reql_times_index_test.go | 4 ++-- .../reql_tests/reql_times_portions_test.go | 4 ++-- .../integration/reql_tests/reql_times_shim_test.go | 4 ++-- .../reql_tests/reql_times_time_arith_test.go | 4 ++-- .../reql_tests/reql_times_timezones_test.go | 4 ++-- .../reql_tests/reql_transform_array_test.go | 4 ++-- .../reql_tests/reql_transform_fold_test.go | 4 ++-- .../integration/reql_tests/reql_transform_map_test.go | 4 ++-- .../reql_tests/reql_transform_object_test.go | 4 ++-- .../reql_tests/reql_transform_table_test.go | 4 ++-- .../reql_tests/reql_transform_unordered_map_test.go | 4 ++-- .../reql_tests/reql_transformation_test.go | 4 ++-- internal/integration/reql_tests/template.go.tpl | 4 ++-- internal/integration/tests/benchmarks_test.go | 2 +- internal/integration/tests/checkers.go | 2 +- .../integration/tests/cluster_integration_test.go | 2 +- internal/integration/tests/cluster_test.go | 2 +- internal/integration/tests/cursor_test.go | 2 +- internal/integration/tests/example_connect_test.go | 2 +- .../tests/example_query_aggregation_test.go | 2 +- .../integration/tests/example_query_control_test.go | 2 +- internal/integration/tests/example_query_db_test.go | 2 +- .../tests/example_query_manipulation_test.go | 2 +- .../integration/tests/example_query_select_test.go | 2 +- .../integration/tests/example_query_table_test.go | 2 +- .../tests/example_query_transformation_test.go | 2 +- .../integration/tests/example_query_write_test.go | 2 +- internal/integration/tests/example_test.go | 2 +- internal/integration/tests/gorethink_test.go | 2 +- internal/integration/tests/query_test.go | 2 +- internal/integration/tests/session_test.go | 2 +- internal/integration/tests/testdata_test.go | 2 +- mock.go | 2 +- mock_test.go | 2 +- node.go | 2 +- pseudotypes.go | 2 +- query.go | 2 +- query_admin.go | 2 +- query_aggregation.go | 2 +- query_control.go | 2 +- query_db.go | 2 +- query_geospatial.go | 2 +- query_helpers.go | 2 +- query_join.go | 2 +- query_manipulation.go | 2 +- query_math.go | 2 +- query_select.go | 2 +- query_string.go | 2 +- query_table.go | 2 +- query_time.go | 2 +- query_transformation.go | 2 +- query_write.go | 2 +- session.go | 2 +- utils.go | 4 ++-- 120 files changed, 201 insertions(+), 200 deletions(-) diff --git a/.travis.yml b/.travis.yml index b37b8c11..7eef85e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,18 @@ language: go go: - - 1.7.5 - - 1.8.1 - - 1.9.2 + - 1.7.x + - 1.8.x + - 1.9.x - tip cache: apt -go_import_path: gopkg.in/gorethink/gorethink.v3 +go_import_path: gopkg.in/gorethink/gorethink.v4 + +install: go get -t ./... before_script: - - go get -t ./... - source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list - wget -qO- http://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add - - sudo apt-get update diff --git a/Makefile b/Makefile index d31d9b71..5ddcf020 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ test: - test -d ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3 && mv ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3 ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3.bak; true - cp -R . ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3 - go test -coverprofile=cover.out -race gopkg.in/gorethink/gorethink.v3; true + test -d ${GOPATH}/src/gopkg.in/gorethink/gorethink.v4 && mv ${GOPATH}/src/gopkg.in/gorethink/gorethink.v4 ${GOPATH}/src/gopkg.in/gorethink/gorethink.v4.bak; true + cp -R . ${GOPATH}/src/gopkg.in/gorethink/gorethink.v4 + go test -coverprofile=cover.out -race gopkg.in/gorethink/gorethink.v4; true go tool cover -html=cover.out -o cover.html; true rm -f cover.out; true - rm -rf ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3 - test -d ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3.bak && mv ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3.bak ${GOPATH}/src/gopkg.in/gorethink/gorethink.v3; true + rm -rf ${GOPATH}/src/gopkg.in/gorethink/gorethink.v4 + test -d ${GOPATH}/src/gopkg.in/gorethink/gorethink.v4.bak && mv ${GOPATH}/src/gopkg.in/gorethink/gorethink.v4.bak ${GOPATH}/src/gopkg.in/gorethink/gorethink.v4; true diff --git a/README.md b/README.md index 1ae43f46..b90239db 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If you need any help you can find me on the [RethinkDB slack](http://slack.rethi ## Installation ``` -go get gopkg.in/gorethink/gorethink.v3 +go get gopkg.in/gorethink/gorethink.v4 ``` Replace `v3` with `v2` or `v1` to use previous versions. @@ -35,7 +35,7 @@ import ( "fmt" "log" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) func Example() { diff --git a/connection.go b/connection.go index 3095d19e..06d2a57c 100644 --- a/connection.go +++ b/connection.go @@ -10,7 +10,7 @@ import ( "time" "golang.org/x/net/context" - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" "sync" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" diff --git a/connection_handshake.go b/connection_handshake.go index d24fa457..c0716df9 100644 --- a/connection_handshake.go +++ b/connection_handshake.go @@ -16,7 +16,7 @@ import ( "golang.org/x/crypto/pbkdf2" - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) type HandshakeVersion int diff --git a/connection_test.go b/connection_test.go index 0e235ea9..e15d5c8d 100644 --- a/connection_test.go +++ b/connection_test.go @@ -2,7 +2,7 @@ package gorethink import ( test "gopkg.in/check.v1" - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" "golang.org/x/net/context" "encoding/binary" "encoding/json" diff --git a/cursor.go b/cursor.go index 8dad0ef4..0d826886 100644 --- a/cursor.go +++ b/cursor.go @@ -8,8 +8,8 @@ import ( "sync" "golang.org/x/net/context" - "gopkg.in/gorethink/gorethink.v3/encoding" - p "gopkg.in/gorethink/gorethink.v3/ql2" + "gopkg.in/gorethink/gorethink.v4/encoding" + p "gopkg.in/gorethink/gorethink.v4/ql2" "github.com/opentracing/opentracing-go" ) diff --git a/errors.go b/errors.go index bd803e2b..f59924ed 100644 --- a/errors.go +++ b/errors.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) var ( diff --git a/gorethink.go b/gorethink.go index b7d1daa8..991b795e 100644 --- a/gorethink.go +++ b/gorethink.go @@ -5,7 +5,7 @@ import ( "github.com/sirupsen/logrus" - "gopkg.in/gorethink/gorethink.v3/encoding" + "gopkg.in/gorethink/gorethink.v4/encoding" "io/ioutil" ) diff --git a/internal/integration/reql_tests/common.go b/internal/integration/reql_tests/common.go index 3624018a..f125fb4a 100644 --- a/internal/integration/reql_tests/common.go +++ b/internal/integration/reql_tests/common.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) func maybeRun(query interface{}, session *r.Session, opts r.RunOpts) interface{} { diff --git a/internal/integration/reql_tests/gorethink_test.go b/internal/integration/reql_tests/gorethink_test.go index c50386cb..6d1dddff 100644 --- a/internal/integration/reql_tests/gorethink_test.go +++ b/internal/integration/reql_tests/gorethink_test.go @@ -6,7 +6,7 @@ import ( "flag" "os" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) var url string diff --git a/internal/integration/reql_tests/reql_aggregation_test.go b/internal/integration/reql_tests/reql_aggregation_test.go index aa676f96..01413fe6 100644 --- a/internal/integration/reql_tests/reql_aggregation_test.go +++ b/internal/integration/reql_tests/reql_aggregation_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests that manipulation data in tables diff --git a/internal/integration/reql_tests/reql_changefeeds_edge_test.go b/internal/integration/reql_tests/reql_changefeeds_edge_test.go index 7479f897..72e28cc6 100644 --- a/internal/integration/reql_tests/reql_changefeeds_edge_test.go +++ b/internal/integration/reql_tests/reql_changefeeds_edge_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test edge cases of changefeed operations diff --git a/internal/integration/reql_tests/reql_changefeeds_idxcopy_test.go b/internal/integration/reql_tests/reql_changefeeds_idxcopy_test.go index 0c58855d..5224111f 100644 --- a/internal/integration/reql_tests/reql_changefeeds_idxcopy_test.go +++ b/internal/integration/reql_tests/reql_changefeeds_idxcopy_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test duplicate indexes with squashing diff --git a/internal/integration/reql_tests/reql_changefeeds_include_states_test.go b/internal/integration/reql_tests/reql_changefeeds_include_states_test.go index 4134c40b..0f1a890b 100644 --- a/internal/integration/reql_tests/reql_changefeeds_include_states_test.go +++ b/internal/integration/reql_tests/reql_changefeeds_include_states_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test `include_states` diff --git a/internal/integration/reql_tests/reql_changefeeds_point_test.go b/internal/integration/reql_tests/reql_changefeeds_point_test.go index f1fd4828..a01954d6 100644 --- a/internal/integration/reql_tests/reql_changefeeds_point_test.go +++ b/internal/integration/reql_tests/reql_changefeeds_point_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test point changebasics diff --git a/internal/integration/reql_tests/reql_changefeeds_table_test.go b/internal/integration/reql_tests/reql_changefeeds_table_test.go index 880b49f3..96301706 100644 --- a/internal/integration/reql_tests/reql_changefeeds_table_test.go +++ b/internal/integration/reql_tests/reql_changefeeds_table_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test changefeeds on a table diff --git a/internal/integration/reql_tests/reql_control_test.go b/internal/integration/reql_tests/reql_control_test.go index 7a6bd3a4..4121e6af 100644 --- a/internal/integration/reql_tests/reql_control_test.go +++ b/internal/integration/reql_tests/reql_control_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests RQL control flow structures diff --git a/internal/integration/reql_tests/reql_datum_array_test.go b/internal/integration/reql_tests/reql_datum_array_test.go index 8eae9e09..6b3d594a 100644 --- a/internal/integration/reql_tests/reql_datum_array_test.go +++ b/internal/integration/reql_tests/reql_datum_array_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests conversion to and from the RQL array type diff --git a/internal/integration/reql_tests/reql_datum_binary_test.go b/internal/integration/reql_tests/reql_datum_binary_test.go index 2fd2359e..f6008aec 100644 --- a/internal/integration/reql_tests/reql_datum_binary_test.go +++ b/internal/integration/reql_tests/reql_datum_binary_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests of converstion to and from the RQL binary type diff --git a/internal/integration/reql_tests/reql_datum_bool_test.go b/internal/integration/reql_tests/reql_datum_bool_test.go index f5bccd0c..c142a345 100644 --- a/internal/integration/reql_tests/reql_datum_bool_test.go +++ b/internal/integration/reql_tests/reql_datum_bool_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests of conversion to and from the RQL bool type diff --git a/internal/integration/reql_tests/reql_datum_null_test.go b/internal/integration/reql_tests/reql_datum_null_test.go index 8c53bb95..a5d9e03f 100644 --- a/internal/integration/reql_tests/reql_datum_null_test.go +++ b/internal/integration/reql_tests/reql_datum_null_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests of conversion to and from the RQL null type diff --git a/internal/integration/reql_tests/reql_datum_number_test.go b/internal/integration/reql_tests/reql_datum_number_test.go index 82e1e6cd..3c0606e4 100644 --- a/internal/integration/reql_tests/reql_datum_number_test.go +++ b/internal/integration/reql_tests/reql_datum_number_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests of conversion to and from the RQL number type diff --git a/internal/integration/reql_tests/reql_datum_object_test.go b/internal/integration/reql_tests/reql_datum_object_test.go index 0326299e..2f2e4311 100644 --- a/internal/integration/reql_tests/reql_datum_object_test.go +++ b/internal/integration/reql_tests/reql_datum_object_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests conversion to and from the RQL object type diff --git a/internal/integration/reql_tests/reql_datum_string_test.go b/internal/integration/reql_tests/reql_datum_string_test.go index 967d8120..58b38bb5 100644 --- a/internal/integration/reql_tests/reql_datum_string_test.go +++ b/internal/integration/reql_tests/reql_datum_string_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests of converstion to and from the RQL string type diff --git a/internal/integration/reql_tests/reql_datum_typeof_test.go b/internal/integration/reql_tests/reql_datum_typeof_test.go index cf8e2e6a..c9fe590a 100644 --- a/internal/integration/reql_tests/reql_datum_typeof_test.go +++ b/internal/integration/reql_tests/reql_datum_typeof_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // These tests test the type of command diff --git a/internal/integration/reql_tests/reql_datum_uuid_test.go b/internal/integration/reql_tests/reql_datum_uuid_test.go index e8c097ef..2f0b221a 100644 --- a/internal/integration/reql_tests/reql_datum_uuid_test.go +++ b/internal/integration/reql_tests/reql_datum_uuid_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test that UUIDs work diff --git a/internal/integration/reql_tests/reql_default_test.go b/internal/integration/reql_tests/reql_default_test.go index 72b086e9..9e90288f 100644 --- a/internal/integration/reql_tests/reql_default_test.go +++ b/internal/integration/reql_tests/reql_default_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests r.default diff --git a/internal/integration/reql_tests/reql_geo_constructors_test.go b/internal/integration/reql_tests/reql_geo_constructors_test.go index 058f3064..af8d2bc7 100644 --- a/internal/integration/reql_tests/reql_geo_constructors_test.go +++ b/internal/integration/reql_tests/reql_geo_constructors_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test geo constructors diff --git a/internal/integration/reql_tests/reql_geo_geojson_test.go b/internal/integration/reql_tests/reql_geo_geojson_test.go index 02b6d46c..aff52a86 100644 --- a/internal/integration/reql_tests/reql_geo_geojson_test.go +++ b/internal/integration/reql_tests/reql_geo_geojson_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test geoJSON conversion diff --git a/internal/integration/reql_tests/reql_geo_indexing_test.go b/internal/integration/reql_tests/reql_geo_indexing_test.go index 486483ec..f59f66fb 100644 --- a/internal/integration/reql_tests/reql_geo_indexing_test.go +++ b/internal/integration/reql_tests/reql_geo_indexing_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test ReQL interface to geo indexes diff --git a/internal/integration/reql_tests/reql_geo_intersection_inclusion_test.go b/internal/integration/reql_tests/reql_geo_intersection_inclusion_test.go index a6781173..4083e621 100644 --- a/internal/integration/reql_tests/reql_geo_intersection_inclusion_test.go +++ b/internal/integration/reql_tests/reql_geo_intersection_inclusion_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test intersects and includes semantics diff --git a/internal/integration/reql_tests/reql_geo_operations_test.go b/internal/integration/reql_tests/reql_geo_operations_test.go index 0f25c270..36086e2f 100644 --- a/internal/integration/reql_tests/reql_geo_operations_test.go +++ b/internal/integration/reql_tests/reql_geo_operations_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test basic geometry operators diff --git a/internal/integration/reql_tests/reql_geo_primitives_test.go b/internal/integration/reql_tests/reql_geo_primitives_test.go index ba0aef95..87c38e26 100644 --- a/internal/integration/reql_tests/reql_geo_primitives_test.go +++ b/internal/integration/reql_tests/reql_geo_primitives_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test geometric primitive constructors diff --git a/internal/integration/reql_tests/reql_joins_test.go b/internal/integration/reql_tests/reql_joins_test.go index a8a7e684..9c64b71d 100644 --- a/internal/integration/reql_tests/reql_joins_test.go +++ b/internal/integration/reql_tests/reql_joins_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests that manipulation data in tables diff --git a/internal/integration/reql_tests/reql_json_test.go b/internal/integration/reql_tests/reql_json_test.go index f68dc71d..05247b8c 100644 --- a/internal/integration/reql_tests/reql_json_test.go +++ b/internal/integration/reql_tests/reql_json_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests RQL json parsing diff --git a/internal/integration/reql_tests/reql_match_test.go b/internal/integration/reql_tests/reql_match_test.go index e9b12236..02f08a90 100644 --- a/internal/integration/reql_tests/reql_match_test.go +++ b/internal/integration/reql_tests/reql_match_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests for match diff --git a/internal/integration/reql_tests/reql_math_logic_add_test.go b/internal/integration/reql_tests/reql_math_logic_add_test.go index 2b0ae75d..8183fc97 100644 --- a/internal/integration/reql_tests/reql_math_logic_add_test.go +++ b/internal/integration/reql_tests/reql_math_logic_add_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests for basic usage of the add operation diff --git a/internal/integration/reql_tests/reql_math_logic_aliases_test.go b/internal/integration/reql_tests/reql_math_logic_aliases_test.go index e4a11067..37447fa1 100644 --- a/internal/integration/reql_tests/reql_math_logic_aliases_test.go +++ b/internal/integration/reql_tests/reql_math_logic_aliases_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test named aliases for math and logic operators diff --git a/internal/integration/reql_tests/reql_math_logic_comparison_test.go b/internal/integration/reql_tests/reql_math_logic_comparison_test.go index acf42331..4b333a4b 100644 --- a/internal/integration/reql_tests/reql_math_logic_comparison_test.go +++ b/internal/integration/reql_tests/reql_math_logic_comparison_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests of comparison operators diff --git a/internal/integration/reql_tests/reql_math_logic_div_test.go b/internal/integration/reql_tests/reql_math_logic_div_test.go index 32d445df..13d65af4 100644 --- a/internal/integration/reql_tests/reql_math_logic_div_test.go +++ b/internal/integration/reql_tests/reql_math_logic_div_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests for the basic usage of the division operation diff --git a/internal/integration/reql_tests/reql_math_logic_floor_ceil_round_test.go b/internal/integration/reql_tests/reql_math_logic_floor_ceil_round_test.go index a1b68d5a..21c6492e 100644 --- a/internal/integration/reql_tests/reql_math_logic_floor_ceil_round_test.go +++ b/internal/integration/reql_tests/reql_math_logic_floor_ceil_round_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // tests for `floor`, `ceil`, and `round`, tests inspired by the Python test suite diff --git a/internal/integration/reql_tests/reql_math_logic_logic_test.go b/internal/integration/reql_tests/reql_math_logic_logic_test.go index ecbc4884..536f9286 100644 --- a/internal/integration/reql_tests/reql_math_logic_logic_test.go +++ b/internal/integration/reql_tests/reql_math_logic_logic_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // These tests are aimed at &&, ||, and ! diff --git a/internal/integration/reql_tests/reql_math_logic_math_test.go b/internal/integration/reql_tests/reql_math_logic_math_test.go index 8e2dc6c1..1ddbff7f 100644 --- a/internal/integration/reql_tests/reql_math_logic_math_test.go +++ b/internal/integration/reql_tests/reql_math_logic_math_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests of nested arithmetic expressions diff --git a/internal/integration/reql_tests/reql_math_logic_mod_test.go b/internal/integration/reql_tests/reql_math_logic_mod_test.go index 57ea5a6b..31734e23 100644 --- a/internal/integration/reql_tests/reql_math_logic_mod_test.go +++ b/internal/integration/reql_tests/reql_math_logic_mod_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests for the basic usage of the mod operation diff --git a/internal/integration/reql_tests/reql_math_logic_mul_test.go b/internal/integration/reql_tests/reql_math_logic_mul_test.go index 9d4aee60..6f8155ec 100644 --- a/internal/integration/reql_tests/reql_math_logic_mul_test.go +++ b/internal/integration/reql_tests/reql_math_logic_mul_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests for the basic usage of the multiplication operation diff --git a/internal/integration/reql_tests/reql_math_logic_sub_test.go b/internal/integration/reql_tests/reql_math_logic_sub_test.go index 7bfaa417..58c2d387 100644 --- a/internal/integration/reql_tests/reql_math_logic_sub_test.go +++ b/internal/integration/reql_tests/reql_math_logic_sub_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests for basic usage of the subtraction operation diff --git a/internal/integration/reql_tests/reql_meta_composite_test.go b/internal/integration/reql_tests/reql_meta_composite_test.go index efb43481..e8a870d9 100644 --- a/internal/integration/reql_tests/reql_meta_composite_test.go +++ b/internal/integration/reql_tests/reql_meta_composite_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests meta operations in composite queries diff --git a/internal/integration/reql_tests/reql_meta_dbs_test.go b/internal/integration/reql_tests/reql_meta_dbs_test.go index 7259a2c5..60292c9c 100644 --- a/internal/integration/reql_tests/reql_meta_dbs_test.go +++ b/internal/integration/reql_tests/reql_meta_dbs_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests meta queries for databases diff --git a/internal/integration/reql_tests/reql_meta_table_test.go b/internal/integration/reql_tests/reql_meta_table_test.go index a952060a..e7934d69 100644 --- a/internal/integration/reql_tests/reql_meta_table_test.go +++ b/internal/integration/reql_tests/reql_meta_table_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests meta queries for creating and deleting tables diff --git a/internal/integration/reql_tests/reql_mutation_atomic_get_set_test.go b/internal/integration/reql_tests/reql_mutation_atomic_get_set_test.go index 2524ca2c..bdb7e4f5 100644 --- a/internal/integration/reql_tests/reql_mutation_atomic_get_set_test.go +++ b/internal/integration/reql_tests/reql_mutation_atomic_get_set_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests replacement of selections diff --git a/internal/integration/reql_tests/reql_mutation_delete_test.go b/internal/integration/reql_tests/reql_mutation_delete_test.go index a1701a88..64af56c7 100644 --- a/internal/integration/reql_tests/reql_mutation_delete_test.go +++ b/internal/integration/reql_tests/reql_mutation_delete_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests deletes of selections diff --git a/internal/integration/reql_tests/reql_mutation_insert_test.go b/internal/integration/reql_tests/reql_mutation_insert_test.go index 0f6e3223..6f936d76 100644 --- a/internal/integration/reql_tests/reql_mutation_insert_test.go +++ b/internal/integration/reql_tests/reql_mutation_insert_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests insertion into tables diff --git a/internal/integration/reql_tests/reql_mutation_replace_test.go b/internal/integration/reql_tests/reql_mutation_replace_test.go index 860d087b..82caa367 100644 --- a/internal/integration/reql_tests/reql_mutation_replace_test.go +++ b/internal/integration/reql_tests/reql_mutation_replace_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests replacement of selections diff --git a/internal/integration/reql_tests/reql_mutation_sync_test.go b/internal/integration/reql_tests/reql_mutation_sync_test.go index 50e9a437..bd6b81b5 100644 --- a/internal/integration/reql_tests/reql_mutation_sync_test.go +++ b/internal/integration/reql_tests/reql_mutation_sync_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests syncing tables diff --git a/internal/integration/reql_tests/reql_mutation_update_test.go b/internal/integration/reql_tests/reql_mutation_update_test.go index 336fd868..64d7b95f 100644 --- a/internal/integration/reql_tests/reql_mutation_update_test.go +++ b/internal/integration/reql_tests/reql_mutation_update_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests updates of selections diff --git a/internal/integration/reql_tests/reql_polymorphism_test.go b/internal/integration/reql_tests/reql_polymorphism_test.go index cdad3d7e..9697b7ca 100644 --- a/internal/integration/reql_tests/reql_polymorphism_test.go +++ b/internal/integration/reql_tests/reql_polymorphism_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests that manipulation data in tables diff --git a/internal/integration/reql_tests/reql_random_test.go b/internal/integration/reql_tests/reql_random_test.go index 45f288cb..02d9cc7c 100644 --- a/internal/integration/reql_tests/reql_random_test.go +++ b/internal/integration/reql_tests/reql_random_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests randomization functions diff --git a/internal/integration/reql_tests/reql_range_test.go b/internal/integration/reql_tests/reql_range_test.go index aa411423..4acf1b2c 100644 --- a/internal/integration/reql_tests/reql_range_test.go +++ b/internal/integration/reql_tests/reql_range_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests RQL range generation diff --git a/internal/integration/reql_tests/reql_selection_test.go b/internal/integration/reql_tests/reql_selection_test.go index 9bbd5ccd..6b8147b1 100644 --- a/internal/integration/reql_tests/reql_selection_test.go +++ b/internal/integration/reql_tests/reql_selection_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests that manipulation data in tables diff --git a/internal/integration/reql_tests/reql_sindex_api_test.go b/internal/integration/reql_tests/reql_sindex_api_test.go index 82ca2c61..729071f8 100644 --- a/internal/integration/reql_tests/reql_sindex_api_test.go +++ b/internal/integration/reql_tests/reql_sindex_api_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // sindex api (#602) diff --git a/internal/integration/reql_tests/reql_sindex_nullsinstrings_test.go b/internal/integration/reql_tests/reql_sindex_nullsinstrings_test.go index 5bf3b5df..ec2f3d55 100644 --- a/internal/integration/reql_tests/reql_sindex_nullsinstrings_test.go +++ b/internal/integration/reql_tests/reql_sindex_nullsinstrings_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // sindex nulls in strings diff --git a/internal/integration/reql_tests/reql_sindex_status_test.go b/internal/integration/reql_tests/reql_sindex_status_test.go index 947def2d..2d106cfc 100644 --- a/internal/integration/reql_tests/reql_sindex_status_test.go +++ b/internal/integration/reql_tests/reql_sindex_status_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // sindex status diff --git a/internal/integration/reql_tests/reql_timeout_test.go b/internal/integration/reql_tests/reql_timeout_test.go index 7c153929..54900f04 100644 --- a/internal/integration/reql_tests/reql_timeout_test.go +++ b/internal/integration/reql_tests/reql_timeout_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests timeouts. diff --git a/internal/integration/reql_tests/reql_times_api_test.go b/internal/integration/reql_tests/reql_times_api_test.go index 1d39ceb4..cb9f176d 100644 --- a/internal/integration/reql_tests/reql_times_api_test.go +++ b/internal/integration/reql_tests/reql_times_api_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // date/time api (#977) diff --git a/internal/integration/reql_tests/reql_times_constructors_test.go b/internal/integration/reql_tests/reql_times_constructors_test.go index 59d450dc..16e5e7e0 100644 --- a/internal/integration/reql_tests/reql_times_constructors_test.go +++ b/internal/integration/reql_tests/reql_times_constructors_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test basic time arithmetic diff --git a/internal/integration/reql_tests/reql_times_index_test.go b/internal/integration/reql_tests/reql_times_index_test.go index fbda5ed7..07434cc9 100644 --- a/internal/integration/reql_tests/reql_times_index_test.go +++ b/internal/integration/reql_tests/reql_times_index_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // secondary indexes on times diff --git a/internal/integration/reql_tests/reql_times_portions_test.go b/internal/integration/reql_tests/reql_times_portions_test.go index d92ee3dd..7063911c 100644 --- a/internal/integration/reql_tests/reql_times_portions_test.go +++ b/internal/integration/reql_tests/reql_times_portions_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // accessing portions diff --git a/internal/integration/reql_tests/reql_times_shim_test.go b/internal/integration/reql_tests/reql_times_shim_test.go index cd215df5..34a123c9 100644 --- a/internal/integration/reql_tests/reql_times_shim_test.go +++ b/internal/integration/reql_tests/reql_times_shim_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test the native shims. diff --git a/internal/integration/reql_tests/reql_times_time_arith_test.go b/internal/integration/reql_tests/reql_times_time_arith_test.go index 34270ea4..525f4d41 100644 --- a/internal/integration/reql_tests/reql_times_time_arith_test.go +++ b/internal/integration/reql_tests/reql_times_time_arith_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test basic time arithmetic diff --git a/internal/integration/reql_tests/reql_times_timezones_test.go b/internal/integration/reql_tests/reql_times_timezones_test.go index c3833dab..943f3411 100644 --- a/internal/integration/reql_tests/reql_times_timezones_test.go +++ b/internal/integration/reql_tests/reql_times_timezones_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Test basic timezone manipulation diff --git a/internal/integration/reql_tests/reql_transform_array_test.go b/internal/integration/reql_tests/reql_transform_array_test.go index a2ae9034..cc59c852 100644 --- a/internal/integration/reql_tests/reql_transform_array_test.go +++ b/internal/integration/reql_tests/reql_transform_array_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests manipulation operations on arrays diff --git a/internal/integration/reql_tests/reql_transform_fold_test.go b/internal/integration/reql_tests/reql_transform_fold_test.go index 67243a80..0cccdcea 100644 --- a/internal/integration/reql_tests/reql_transform_fold_test.go +++ b/internal/integration/reql_tests/reql_transform_fold_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests for the fold term diff --git a/internal/integration/reql_tests/reql_transform_map_test.go b/internal/integration/reql_tests/reql_transform_map_test.go index 1f608909..e5789bd1 100644 --- a/internal/integration/reql_tests/reql_transform_map_test.go +++ b/internal/integration/reql_tests/reql_transform_map_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests the RQL `map` function diff --git a/internal/integration/reql_tests/reql_transform_object_test.go b/internal/integration/reql_tests/reql_transform_object_test.go index 1e643a14..1da407d6 100644 --- a/internal/integration/reql_tests/reql_transform_object_test.go +++ b/internal/integration/reql_tests/reql_transform_object_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests manipulation operations on objects diff --git a/internal/integration/reql_tests/reql_transform_table_test.go b/internal/integration/reql_tests/reql_transform_table_test.go index e68c74f6..7a3f90d9 100644 --- a/internal/integration/reql_tests/reql_transform_table_test.go +++ b/internal/integration/reql_tests/reql_transform_table_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests manipulation operations on tables diff --git a/internal/integration/reql_tests/reql_transform_unordered_map_test.go b/internal/integration/reql_tests/reql_transform_unordered_map_test.go index c4005697..cba02545 100644 --- a/internal/integration/reql_tests/reql_transform_unordered_map_test.go +++ b/internal/integration/reql_tests/reql_transform_unordered_map_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests for ordered_union diff --git a/internal/integration/reql_tests/reql_transformation_test.go b/internal/integration/reql_tests/reql_transformation_test.go index 6e3a481d..34a5a0f1 100644 --- a/internal/integration/reql_tests/reql_transformation_test.go +++ b/internal/integration/reql_tests/reql_transformation_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // Tests that manipulation data in tables diff --git a/internal/integration/reql_tests/template.go.tpl b/internal/integration/reql_tests/template.go.tpl index 3ca8fbb4..7d69df74 100644 --- a/internal/integration/reql_tests/template.go.tpl +++ b/internal/integration/reql_tests/template.go.tpl @@ -5,8 +5,8 @@ import ( "time" "github.com/stretchr/testify/suite" - r "gopkg.in/gorethink/gorethink.v3" - "gopkg.in/gorethink/gorethink.v3/internal/compare" + r "gopkg.in/gorethink/gorethink.v4" + "gopkg.in/gorethink/gorethink.v4/internal/compare" ) // ${description} diff --git a/internal/integration/tests/benchmarks_test.go b/internal/integration/tests/benchmarks_test.go index 90549165..6c206999 100644 --- a/internal/integration/tests/benchmarks_test.go +++ b/internal/integration/tests/benchmarks_test.go @@ -6,7 +6,7 @@ import ( "sync" "testing" "time" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) func BenchmarkBatch200RandomWrites(b *testing.B) { diff --git a/internal/integration/tests/checkers.go b/internal/integration/tests/checkers.go index 4d56cac1..9cb1bf06 100644 --- a/internal/integration/tests/checkers.go +++ b/internal/integration/tests/checkers.go @@ -6,7 +6,7 @@ import ( test "gopkg.in/check.v1" - "gopkg.in/gorethink/gorethink.v3/types" + "gopkg.in/gorethink/gorethink.v4/types" ) type jsonChecker struct { diff --git a/internal/integration/tests/cluster_integration_test.go b/internal/integration/tests/cluster_integration_test.go index 5a920622..9c188709 100644 --- a/internal/integration/tests/cluster_integration_test.go +++ b/internal/integration/tests/cluster_integration_test.go @@ -7,7 +7,7 @@ import ( "time" test "gopkg.in/check.v1" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" "strings" "strconv" ) diff --git a/internal/integration/tests/cluster_test.go b/internal/integration/tests/cluster_test.go index ae8fcd8e..6a20fad7 100644 --- a/internal/integration/tests/cluster_test.go +++ b/internal/integration/tests/cluster_test.go @@ -7,7 +7,7 @@ import ( "time" test "gopkg.in/check.v1" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) func (s *RethinkSuite) TestClusterConnect(c *test.C) { diff --git a/internal/integration/tests/cursor_test.go b/internal/integration/tests/cursor_test.go index ba59cb81..bfeada6b 100644 --- a/internal/integration/tests/cursor_test.go +++ b/internal/integration/tests/cursor_test.go @@ -5,7 +5,7 @@ import ( "time" test "gopkg.in/check.v1" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) type object struct { diff --git a/internal/integration/tests/example_connect_test.go b/internal/integration/tests/example_connect_test.go index 5f83f281..8e09d1a7 100644 --- a/internal/integration/tests/example_connect_test.go +++ b/internal/integration/tests/example_connect_test.go @@ -4,7 +4,7 @@ import ( "log" "os" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) var sessionEx *r.Session diff --git a/internal/integration/tests/example_query_aggregation_test.go b/internal/integration/tests/example_query_aggregation_test.go index 2d6082b1..c1690613 100644 --- a/internal/integration/tests/example_query_aggregation_test.go +++ b/internal/integration/tests/example_query_aggregation_test.go @@ -2,7 +2,7 @@ package tests import ( "fmt" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) // Group games by player. diff --git a/internal/integration/tests/example_query_control_test.go b/internal/integration/tests/example_query_control_test.go index 963cf5d1..e17d1d89 100644 --- a/internal/integration/tests/example_query_control_test.go +++ b/internal/integration/tests/example_query_control_test.go @@ -2,7 +2,7 @@ package tests import ( "fmt" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) // Return heroes and superheroes. diff --git a/internal/integration/tests/example_query_db_test.go b/internal/integration/tests/example_query_db_test.go index ec1798eb..8925f418 100644 --- a/internal/integration/tests/example_query_db_test.go +++ b/internal/integration/tests/example_query_db_test.go @@ -2,7 +2,7 @@ package tests import ( "fmt" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) // Create a database named ’superheroes’. diff --git a/internal/integration/tests/example_query_manipulation_test.go b/internal/integration/tests/example_query_manipulation_test.go index 0496169e..c78bdac9 100644 --- a/internal/integration/tests/example_query_manipulation_test.go +++ b/internal/integration/tests/example_query_manipulation_test.go @@ -2,7 +2,7 @@ package tests import ( "fmt" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) // Get john's age diff --git a/internal/integration/tests/example_query_select_test.go b/internal/integration/tests/example_query_select_test.go index 11acc0f5..979b14dd 100644 --- a/internal/integration/tests/example_query_select_test.go +++ b/internal/integration/tests/example_query_select_test.go @@ -2,7 +2,7 @@ package tests import ( "fmt" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) // Find a document by ID. diff --git a/internal/integration/tests/example_query_table_test.go b/internal/integration/tests/example_query_table_test.go index 3667c947..e6a283b3 100644 --- a/internal/integration/tests/example_query_table_test.go +++ b/internal/integration/tests/example_query_table_test.go @@ -2,7 +2,7 @@ package tests import ( "fmt" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) // Create a table named "table" with the default settings. diff --git a/internal/integration/tests/example_query_transformation_test.go b/internal/integration/tests/example_query_transformation_test.go index 33cdc985..7405a7ad 100644 --- a/internal/integration/tests/example_query_transformation_test.go +++ b/internal/integration/tests/example_query_transformation_test.go @@ -2,7 +2,7 @@ package tests import ( "fmt" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) // Return the first five squares. diff --git a/internal/integration/tests/example_query_write_test.go b/internal/integration/tests/example_query_write_test.go index b3104519..249dd952 100644 --- a/internal/integration/tests/example_query_write_test.go +++ b/internal/integration/tests/example_query_write_test.go @@ -2,7 +2,7 @@ package tests import ( "fmt" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) // Insert a document into the table posts using a struct. diff --git a/internal/integration/tests/example_test.go b/internal/integration/tests/example_test.go index 369add16..4e0cfba0 100644 --- a/internal/integration/tests/example_test.go +++ b/internal/integration/tests/example_test.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) func Example() { diff --git a/internal/integration/tests/gorethink_test.go b/internal/integration/tests/gorethink_test.go index 58d91e33..496ec3a5 100644 --- a/internal/integration/tests/gorethink_test.go +++ b/internal/integration/tests/gorethink_test.go @@ -10,7 +10,7 @@ import ( "time" test "gopkg.in/check.v1" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) var session *r.Session diff --git a/internal/integration/tests/query_test.go b/internal/integration/tests/query_test.go index d02d4c55..f8a21182 100644 --- a/internal/integration/tests/query_test.go +++ b/internal/integration/tests/query_test.go @@ -8,7 +8,7 @@ import ( "time" test "gopkg.in/check.v1" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) func (s *RethinkSuite) TestQueryRun(c *test.C) { diff --git a/internal/integration/tests/session_test.go b/internal/integration/tests/session_test.go index 9e27b4af..5ea97d96 100644 --- a/internal/integration/tests/session_test.go +++ b/internal/integration/tests/session_test.go @@ -5,7 +5,7 @@ import ( "time" test "gopkg.in/check.v1" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) func (s *RethinkSuite) TestSessionConnect(c *test.C) { diff --git a/internal/integration/tests/testdata_test.go b/internal/integration/tests/testdata_test.go index e1acc729..5919debc 100644 --- a/internal/integration/tests/testdata_test.go +++ b/internal/integration/tests/testdata_test.go @@ -1,6 +1,6 @@ package tests -import (r "gopkg.in/gorethink/gorethink.v3") +import (r "gopkg.in/gorethink/gorethink.v4") func setupTestData() { if *testdata { diff --git a/mock.go b/mock.go index 7d91fcac..989a7261 100644 --- a/mock.go +++ b/mock.go @@ -8,7 +8,7 @@ import ( "time" "golang.org/x/net/context" - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // Mocking is based on the amazing package github.com/stretchr/testify diff --git a/mock_test.go b/mock_test.go index 0320bfb2..c01fea64 100644 --- a/mock_test.go +++ b/mock_test.go @@ -5,7 +5,7 @@ import ( test "gopkg.in/check.v1" "testing" - "gopkg.in/gorethink/gorethink.v3/internal/integration/tests" + "gopkg.in/gorethink/gorethink.v4/internal/integration/tests" ) // Hook up gocheck into the gotest runner. diff --git a/node.go b/node.go index 6d521cba..c846c916 100644 --- a/node.go +++ b/node.go @@ -4,7 +4,7 @@ import ( "sync" "golang.org/x/net/context" - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // Node represents a database server in the cluster diff --git a/pseudotypes.go b/pseudotypes.go index b46aeeb9..5be3137e 100644 --- a/pseudotypes.go +++ b/pseudotypes.go @@ -6,7 +6,7 @@ import ( "strconv" "time" - "gopkg.in/gorethink/gorethink.v3/types" + "gopkg.in/gorethink/gorethink.v4/types" "fmt" ) diff --git a/query.go b/query.go index 0343947c..967b5c1e 100644 --- a/query.go +++ b/query.go @@ -7,7 +7,7 @@ import ( "strings" "golang.org/x/net/context" - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // A Query represents a query ready to be sent to the database, A Query differs diff --git a/query_admin.go b/query_admin.go index 9dd267bb..fced1c6c 100644 --- a/query_admin.go +++ b/query_admin.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // Config can be used to read and/or update the configurations for individual diff --git a/query_aggregation.go b/query_aggregation.go index 7feb7d13..65327963 100644 --- a/query_aggregation.go +++ b/query_aggregation.go @@ -1,6 +1,6 @@ package gorethink -import p "gopkg.in/gorethink/gorethink.v3/ql2" +import p "gopkg.in/gorethink/gorethink.v4/ql2" // Aggregation // These commands are used to compute smaller values from large sequences. diff --git a/query_control.go b/query_control.go index cde7ea32..366677fa 100644 --- a/query_control.go +++ b/query_control.go @@ -6,7 +6,7 @@ import ( "reflect" - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // Expr converts any value to an expression and is also used by many other terms diff --git a/query_db.go b/query_db.go index a1596a45..e19421b4 100644 --- a/query_db.go +++ b/query_db.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // DBCreate creates a database. A RethinkDB database is a collection of tables, diff --git a/query_geospatial.go b/query_geospatial.go index aeb710dd..978b495b 100644 --- a/query_geospatial.go +++ b/query_geospatial.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // CircleOpts contains the optional arguments for the Circle term. diff --git a/query_helpers.go b/query_helpers.go index 5d894b86..47a6d629 100644 --- a/query_helpers.go +++ b/query_helpers.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) func newStopQuery(token int64) Query { diff --git a/query_join.go b/query_join.go index 1ec6b161..13bc37e4 100644 --- a/query_join.go +++ b/query_join.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // InnerJoin returns the inner product of two sequences (e.g. a table, a filter result) diff --git a/query_manipulation.go b/query_manipulation.go index 5927d19e..f42acd7b 100644 --- a/query_manipulation.go +++ b/query_manipulation.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // Row returns the currently visited document. Note that Row does not work within diff --git a/query_math.go b/query_math.go index 44064753..8ced2e9f 100644 --- a/query_math.go +++ b/query_math.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) var ( diff --git a/query_select.go b/query_select.go index 9dfd3e4e..bc389312 100644 --- a/query_select.go +++ b/query_select.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // DB references a database. diff --git a/query_string.go b/query_string.go index 5660af98..a1bc168e 100644 --- a/query_string.go +++ b/query_string.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // Match matches against a regular expression. If no match is found, returns diff --git a/query_table.go b/query_table.go index e4283a3a..c6c6f581 100644 --- a/query_table.go +++ b/query_table.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // TableCreateOpts contains the optional arguments for the TableCreate term diff --git a/query_time.go b/query_time.go index f4e37d20..0f63616e 100644 --- a/query_time.go +++ b/query_time.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // Now returns a time object representing the current time in UTC diff --git a/query_transformation.go b/query_transformation.go index 0b24cc14..2c62eb5a 100644 --- a/query_transformation.go +++ b/query_transformation.go @@ -1,6 +1,6 @@ package gorethink -import p "gopkg.in/gorethink/gorethink.v3/ql2" +import p "gopkg.in/gorethink/gorethink.v4/ql2" // Map transform each element of the sequence by applying the given mapping // function. It takes two arguments, a sequence and a function of type diff --git a/query_write.go b/query_write.go index 9bc1f683..a4a64c6e 100644 --- a/query_write.go +++ b/query_write.go @@ -1,7 +1,7 @@ package gorethink import ( - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // InsertOpts contains the optional arguments for the Insert term diff --git a/session.go b/session.go index c508f4c5..c476de68 100644 --- a/session.go +++ b/session.go @@ -6,7 +6,7 @@ import ( "time" "golang.org/x/net/context" - p "gopkg.in/gorethink/gorethink.v3/ql2" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // A Session represents a connection to a RethinkDB cluster and should be used diff --git a/utils.go b/utils.go index 32126d50..8aa1c0c5 100644 --- a/utils.go +++ b/utils.go @@ -6,8 +6,8 @@ import ( "strings" "sync/atomic" - "gopkg.in/gorethink/gorethink.v3/encoding" - p "gopkg.in/gorethink/gorethink.v3/ql2" + "gopkg.in/gorethink/gorethink.v4/encoding" + p "gopkg.in/gorethink/gorethink.v4/ql2" ) // Helper functions for constructing terms From b4cac7c524565475df79d3167339b4b6a4efe7aa Mon Sep 17 00:00:00 2001 From: Alexander Mogilko Date: Thu, 14 Dec 2017 14:44:56 +0000 Subject: [PATCH 13/13] docs for v4 --- CHANGELOG.md | 13 +++++++++++++ README.md | 13 +++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f692b445..bc4442f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## v4.0.0 - 2017-12-14 + +### Fixed + + - `Connection` work with sockets, now only a single goroutine reads from socket. + - Optimized threadsafe operations in `Connection` with channels and atomics instead of mutex. + - All tests with real db moved to integration folder + +### Added + + - Added support for tracing with `opentracing-go` + - Added a brand-new unit tests for `Connection` + ## v3.0.5 - 2017-09-28 - Fixed typo at http opts diff --git a/README.md b/README.md index b90239db..b39d9dc5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ![GoRethink Logo](https://raw.github.com/wiki/gorethink/gorethink/gopher-and-thinker-s.png "Golang Gopher and RethinkDB Thinker") -Current version: v3.0.5 (RethinkDB v2.3) +Current version: v4.0.0 (RethinkDB v2.3) @@ -23,7 +23,7 @@ If you need any help you can find me on the [RethinkDB slack](http://slack.rethi go get gopkg.in/gorethink/gorethink.v4 ``` -Replace `v3` with `v2` or `v1` to use previous versions. +Replace `v4` with `v3` or `v2` to use previous versions. ## Example @@ -413,6 +413,15 @@ r.Log.Out = os.Stderr r.Log.Out = ioutil.Discard ``` +## Tracing + +The driver supports [opentracing-go](https://github.com/opentracing/opentracing-go/). You can enable this feature by setting `UseOpentracing` to true in the `ConnectOpts`. Then driver will expect `opentracing.Span` in the `RunOpts.Context` and will start new child spans for queries. +Also you need to configure tracer in your program by yourself. + +The driver starts span for the whole query, from the first byte is sent to the cursor closed, and second-level span for each query for fetching data. + +So you can trace how much time you program spends for RethinkDB queries. + ## Mocking The driver includes the ability to mock queries meaning that you can test your code without needing to talk to a real RethinkDB cluster, this is perfect for ensuring that your application has high unit test coverage.