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/.travis.yml b/.travis.yml index 22199ec0..7eef85e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,16 @@ language: go go: - - 1.7.5 - - 1.8.1 + - 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: - source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list 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/Makefile b/Makefile new file mode 100644 index 00000000..5ddcf020 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +test: + 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.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..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) @@ -20,10 +20,10 @@ 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. +Replace `v4` with `v3` or `v2` to use previous versions. ## Example @@ -35,7 +35,7 @@ import ( "fmt" "log" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) func 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. diff --git a/connection.go b/connection.go index e8adc25e..06d2a57c 100644 --- a/connection.go +++ b/connection.go @@ -6,17 +6,27 @@ import ( "encoding/json" "fmt" "net" - "sync" "sync/atomic" "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" + "github.com/opentracing/opentracing-go/log" + "bytes" ) const ( respHeaderLen = 12 defaultKeepAlivePeriod = time.Second * 30 + + notBad = 0 + bad = 1 + + working = 0 + closed = 1 ) // Response represents the raw response from a query, most of the time you @@ -39,39 +49,57 @@ type Connection struct { address string opts *ConnectOpts - _ [4]byte - mu sync.Mutex - token int64 - cursors map[int64]*Cursor - bad bool - closed bool + _ [4]byte + token int64 + cursors map[int64]*Cursor + bad int32 // 0 - not bad, 1 - bad + closed int32 // 0 - working, 1 - closed + stopReadChan chan bool + readRequestsChan chan tokenAndPromise + responseChan chan responseAndError + mu sync.Mutex +} + +type responseAndError struct { + response *Response + err error +} + +type responseAndCursor struct { + response *Response + cursor *Cursor + err error +} + +type tokenAndPromise struct { + ctx context.Context + query *Query + promise chan responseAndCursor + span opentracing.Span } // 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), - } - 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 { @@ -82,20 +110,42 @@ 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, + 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), + } + return c +} + +func (c *Connection) runConnection() { + go c.readSocket() + go c.processResponses() +} + // Close closes the underlying net.Conn func (c *Connection) Close() error { + var err error + c.mu.Lock() defer c.mu.Unlock() - var err error - - if !c.closed { + if !c.isClosed() { + c.setClosed() + close(c.stopReadChan) err = c.Conn.Close() - c.closed = true - c.cursors = make(map[int64]*Cursor) } return err @@ -106,19 +156,16 @@ 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 } - c.mu.Lock() - if c.Conn == nil { - c.bad = true - c.mu.Unlock() + if c.Conn == nil || c.isClosed() { + 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 { @@ -129,58 +176,164 @@ 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 + 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() + if q.Type == p.Query_START { + opentracing.SpanFromContext(ctx).Finish() + } + } + return nil, nil, err + } + + if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) { + select { + case c.readRequestsChan <- tokenAndPromise{ctx: ctx, query: &q, span: fetchingSpan}: + return nil, nil, nil + case <-ctx.Done(): + return c.stopQuery(&q) + } + } + + promise := make(chan responseAndCursor, 1) + 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(): + 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 +} - if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) { - errchan <- nil +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() { + for { + response, err := c.readResponse() + + respPair := responseAndError{ + response: response, + err: err, + } + + select { + case c.responseChan <- respPair: + case <-c.stopReadChan: + close(c.responseChan) return } + } +} - for { - response, err := c.readResponse() - if err != nil { - errchan <- err - return +func (c *Connection) processResponses() { + readRequests := make([]tokenAndPromise, 0, 16) + responses := make([]*Response, 0, 16) + for { + var response *Response + 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 { + if rr.promise != nil { + rr.promise <- responseAndCursor{err: respPair.err} + close(rr.promise) + } + } + readRequests = []tokenAndPromise{} + c.Close() + continue } + if respPair.response == nil && respPair.err == nil { // responseChan is closed + continue + } + + response = respPair.response - 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) + 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: + response, ok = getResponse(responses, readRequest.query.Token) + if !ok { + readRequests = append(readRequests, readRequest) + continue + } + responses = removeResponse(responses, readRequest.query.Token) + + case <-c.stopReadChan: + for _, rr := range readRequests { + if rr.promise != nil { + rr.promise <- responseAndCursor{err: ErrConnectionClosed} + close(rr.promise) + } + } + c.cursors = nil + return } - }() - select { - case err := <-errchan: - return response, cursor, err - case <-ctx.Done(): - if q.Type != p.Query_STOP { - stopQuery := newStopQuery(q.Token) - c.Query(c.contextFromConnectionOpts(), stopQuery) + 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) } - return nil, nil, ErrQueryTimeout } } @@ -213,22 +366,31 @@ 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.Time{}) - } else { + 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 { - c.bad = true + if err = c.writeData(b); err != nil { + c.setBad() return RQLConnectionError{rqlError(err.Error())} } @@ -246,16 +408,14 @@ 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)) } // 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 +425,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,14 +441,25 @@ 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) 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 c.processErrorResponse(q, response, RQLClientError{rqlServerError{response, q.Term}}) + return response, c.processErrorResponse(response), createClientError(response, q.Term) case p.Response_COMPILE_ERROR: - return c.processErrorResponse(q, response, RQLCompileError{rqlServerError{response, q.Term}}) + return response, c.processErrorResponse(response), createCompileError(response, q.Term) case p.Response_RUNTIME_ERROR: - return c.processErrorResponse(q, response, 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: @@ -296,28 +467,21 @@ 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(q, response) + return c.processWaitResponse(response) default: - putResponse(response) - return nil, nil, RQLDriverError{rqlError("Unexpected response type")} + return nil, nil, RQLDriverError{rqlError("Unexpected response type: %v")} } } -func (c *Connection) processErrorResponse(q Query, response *Response, err error) (*Response, *Cursor, error) { - c.mu.Lock() +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 @@ -340,7 +504,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,7 +512,6 @@ func (c *Connection) processPartialResponse(ctx context.Context, q Query, respon c.cursors[response.Token] = cursor } - c.mu.Unlock() cursor.extend(response) @@ -357,52 +519,72 @@ func (c *Connection) processPartialResponse(ctx context.Context, q Query, respon } func (c *Connection) processSequenceResponse(ctx context.Context, q Query, response *Response) (*Response, *Cursor, error) { - c.mu.Lock() 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) processWaitResponse(response *Response) (*Response, *Cursor, error) { delete(c.cursors, response.Token) - c.mu.Unlock() - return response, nil, nil } +func (c *Connection) setBad() { + atomic.StoreInt32(&c.bad, bad) +} + func (c *Connection) isBad() bool { - c.mu.Lock() - defer c.mu.Unlock() + return atomic.LoadInt32(&c.bad) == bad +} - return c.bad +func (c *Connection) setClosed() { + atomic.StoreInt32(&c.closed, closed) } -var responseCache = make(chan *Response, 16) +func (c *Connection) isClosed() bool { + return atomic.LoadInt32(&c.closed) == closed +} -func newCachedResponse() *Response { - select { - case r := <-responseCache: - return r - default: - return new(Response) +func getReadRequest(list []tokenAndPromise, token int64) (tokenAndPromise, bool) { + for _, e := range list { + if e.query.Token == token { + return e, true + } } + return tokenAndPromise{}, false } -func putResponse(r *Response) { - *r = Response{} // zero it - select { - case responseCache <- r: - default: +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].query.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 } 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_helper.go b/connection_helper.go index ba4ff52b..4684225e 100644 --- a/connection_helper.go +++ b/connection_helper.go @@ -1,8 +1,8 @@ package gorethink import ( - "encoding/binary" "golang.org/x/net/context" + "io" ) // Write 'data' to conn @@ -12,35 +12,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) 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) read(buf []byte) (total int, err error) { + return io.ReadFull(c.Conn, buf) } func (c *Connection) contextFromConnectionOpts() context.Context { diff --git a/connection_test.go b/connection_test.go new file mode 100644 index 00000000..e15d5c8d --- /dev/null +++ b/connection_test.go @@ -0,0 +1,580 @@ +package gorethink + +import ( + test "gopkg.in/check.v1" + p "gopkg.in/gorethink/gorethink.v4/ql2" + "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{} + +var _ = test.Suite(&ConnectionSuite{}) + +func (s *ConnectionSuite) TestConnection_Query_Ok(c *test.C) { + ctx := context.Background() + token := int64(1) + q := testQuery(DB("db").Table("table").Get("id")) + 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(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_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 (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, + 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/cursor.go b/cursor.go index fe670951..0d826886 100644 --- a/cursor.go +++ b/cursor.go @@ -8,8 +8,9 @@ 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" ) 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 @@ -583,8 +588,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..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 ( @@ -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/gorethink.go b/gorethink.go index 22614eab..991b795e 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" + "gopkg.in/gorethink/gorethink.v4/encoding" + "io/ioutil" ) var ( diff --git a/internal/reql_tests/common.go b/internal/integration/reql_tests/common.go similarity index 98% rename from internal/reql_tests/common.go rename to internal/integration/reql_tests/common.go index 3624018a..f125fb4a 100644 --- a/internal/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/reql_tests/gorethink_test.go b/internal/integration/reql_tests/gorethink_test.go similarity index 88% rename from internal/reql_tests/gorethink_test.go rename to internal/integration/reql_tests/gorethink_test.go index c50386cb..6d1dddff 100644 --- a/internal/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/reql_tests/reql_aggregation_test.go b/internal/integration/reql_tests/reql_aggregation_test.go similarity index 99% rename from internal/reql_tests/reql_aggregation_test.go rename to internal/integration/reql_tests/reql_aggregation_test.go index aa676f96..01413fe6 100644 --- a/internal/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/reql_tests/reql_changefeeds_edge_test.go b/internal/integration/reql_tests/reql_changefeeds_edge_test.go similarity index 99% rename from internal/reql_tests/reql_changefeeds_edge_test.go rename to internal/integration/reql_tests/reql_changefeeds_edge_test.go index 7479f897..72e28cc6 100644 --- a/internal/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/reql_tests/reql_changefeeds_idxcopy_test.go b/internal/integration/reql_tests/reql_changefeeds_idxcopy_test.go similarity index 98% rename from internal/reql_tests/reql_changefeeds_idxcopy_test.go rename to internal/integration/reql_tests/reql_changefeeds_idxcopy_test.go index 0c58855d..5224111f 100644 --- a/internal/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/reql_tests/reql_changefeeds_include_states_test.go b/internal/integration/reql_tests/reql_changefeeds_include_states_test.go similarity index 99% rename from internal/reql_tests/reql_changefeeds_include_states_test.go rename to internal/integration/reql_tests/reql_changefeeds_include_states_test.go index 4134c40b..0f1a890b 100644 --- a/internal/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/reql_tests/reql_changefeeds_point_test.go b/internal/integration/reql_tests/reql_changefeeds_point_test.go similarity index 99% rename from internal/reql_tests/reql_changefeeds_point_test.go rename to internal/integration/reql_tests/reql_changefeeds_point_test.go index f1fd4828..a01954d6 100644 --- a/internal/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/reql_tests/reql_changefeeds_table_test.go b/internal/integration/reql_tests/reql_changefeeds_table_test.go similarity index 99% rename from internal/reql_tests/reql_changefeeds_table_test.go rename to internal/integration/reql_tests/reql_changefeeds_table_test.go index 880b49f3..96301706 100644 --- a/internal/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/reql_tests/reql_control_test.go b/internal/integration/reql_tests/reql_control_test.go similarity index 99% rename from internal/reql_tests/reql_control_test.go rename to internal/integration/reql_tests/reql_control_test.go index 7a6bd3a4..4121e6af 100644 --- a/internal/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/reql_tests/reql_datum_array_test.go b/internal/integration/reql_tests/reql_datum_array_test.go similarity index 99% rename from internal/reql_tests/reql_datum_array_test.go rename to internal/integration/reql_tests/reql_datum_array_test.go index 8eae9e09..6b3d594a 100644 --- a/internal/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/reql_tests/reql_datum_binary_test.go b/internal/integration/reql_tests/reql_datum_binary_test.go similarity index 99% rename from internal/reql_tests/reql_datum_binary_test.go rename to internal/integration/reql_tests/reql_datum_binary_test.go index 2fd2359e..f6008aec 100644 --- a/internal/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/reql_tests/reql_datum_bool_test.go b/internal/integration/reql_tests/reql_datum_bool_test.go similarity index 98% rename from internal/reql_tests/reql_datum_bool_test.go rename to internal/integration/reql_tests/reql_datum_bool_test.go index f5bccd0c..c142a345 100644 --- a/internal/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/reql_tests/reql_datum_null_test.go b/internal/integration/reql_tests/reql_datum_null_test.go similarity index 96% rename from internal/reql_tests/reql_datum_null_test.go rename to internal/integration/reql_tests/reql_datum_null_test.go index 8c53bb95..a5d9e03f 100644 --- a/internal/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/reql_tests/reql_datum_number_test.go b/internal/integration/reql_tests/reql_datum_number_test.go similarity index 98% rename from internal/reql_tests/reql_datum_number_test.go rename to internal/integration/reql_tests/reql_datum_number_test.go index 82e1e6cd..3c0606e4 100644 --- a/internal/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/reql_tests/reql_datum_object_test.go b/internal/integration/reql_tests/reql_datum_object_test.go similarity index 99% rename from internal/reql_tests/reql_datum_object_test.go rename to internal/integration/reql_tests/reql_datum_object_test.go index 0326299e..2f2e4311 100644 --- a/internal/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/reql_tests/reql_datum_string_test.go b/internal/integration/reql_tests/reql_datum_string_test.go similarity index 99% rename from internal/reql_tests/reql_datum_string_test.go rename to internal/integration/reql_tests/reql_datum_string_test.go index 967d8120..58b38bb5 100644 --- a/internal/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/reql_tests/reql_datum_typeof_test.go b/internal/integration/reql_tests/reql_datum_typeof_test.go similarity index 95% rename from internal/reql_tests/reql_datum_typeof_test.go rename to internal/integration/reql_tests/reql_datum_typeof_test.go index cf8e2e6a..c9fe590a 100644 --- a/internal/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/reql_tests/reql_datum_uuid_test.go b/internal/integration/reql_tests/reql_datum_uuid_test.go similarity index 98% rename from internal/reql_tests/reql_datum_uuid_test.go rename to internal/integration/reql_tests/reql_datum_uuid_test.go index e8c097ef..2f0b221a 100644 --- a/internal/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/reql_tests/reql_default_test.go b/internal/integration/reql_tests/reql_default_test.go similarity index 99% rename from internal/reql_tests/reql_default_test.go rename to internal/integration/reql_tests/reql_default_test.go index 72b086e9..9e90288f 100644 --- a/internal/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/reql_tests/reql_geo_constructors_test.go b/internal/integration/reql_tests/reql_geo_constructors_test.go similarity index 99% rename from internal/reql_tests/reql_geo_constructors_test.go rename to internal/integration/reql_tests/reql_geo_constructors_test.go index 058f3064..af8d2bc7 100644 --- a/internal/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/reql_tests/reql_geo_geojson_test.go b/internal/integration/reql_tests/reql_geo_geojson_test.go similarity index 99% rename from internal/reql_tests/reql_geo_geojson_test.go rename to internal/integration/reql_tests/reql_geo_geojson_test.go index 02b6d46c..aff52a86 100644 --- a/internal/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/reql_tests/reql_geo_indexing_test.go b/internal/integration/reql_tests/reql_geo_indexing_test.go similarity index 99% rename from internal/reql_tests/reql_geo_indexing_test.go rename to internal/integration/reql_tests/reql_geo_indexing_test.go index 486483ec..f59f66fb 100644 --- a/internal/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/reql_tests/reql_geo_intersection_inclusion_test.go b/internal/integration/reql_tests/reql_geo_intersection_inclusion_test.go similarity index 99% rename from internal/reql_tests/reql_geo_intersection_inclusion_test.go rename to internal/integration/reql_tests/reql_geo_intersection_inclusion_test.go index a6781173..4083e621 100644 --- a/internal/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/reql_tests/reql_geo_operations_test.go b/internal/integration/reql_tests/reql_geo_operations_test.go similarity index 99% rename from internal/reql_tests/reql_geo_operations_test.go rename to internal/integration/reql_tests/reql_geo_operations_test.go index 0f25c270..36086e2f 100644 --- a/internal/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/reql_tests/reql_geo_primitives_test.go b/internal/integration/reql_tests/reql_geo_primitives_test.go similarity index 99% rename from internal/reql_tests/reql_geo_primitives_test.go rename to internal/integration/reql_tests/reql_geo_primitives_test.go index ba0aef95..87c38e26 100644 --- a/internal/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/reql_tests/reql_joins_test.go b/internal/integration/reql_tests/reql_joins_test.go similarity index 99% rename from internal/reql_tests/reql_joins_test.go rename to internal/integration/reql_tests/reql_joins_test.go index a8a7e684..9c64b71d 100644 --- a/internal/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/reql_tests/reql_json_test.go b/internal/integration/reql_tests/reql_json_test.go similarity index 99% rename from internal/reql_tests/reql_json_test.go rename to internal/integration/reql_tests/reql_json_test.go index f68dc71d..05247b8c 100644 --- a/internal/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/reql_tests/reql_match_test.go b/internal/integration/reql_tests/reql_match_test.go similarity index 98% rename from internal/reql_tests/reql_match_test.go rename to internal/integration/reql_tests/reql_match_test.go index e9b12236..02f08a90 100644 --- a/internal/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/reql_tests/reql_math_logic_add_test.go b/internal/integration/reql_tests/reql_math_logic_add_test.go similarity index 98% rename from internal/reql_tests/reql_math_logic_add_test.go rename to internal/integration/reql_tests/reql_math_logic_add_test.go index 2b0ae75d..8183fc97 100644 --- a/internal/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/reql_tests/reql_math_logic_aliases_test.go b/internal/integration/reql_tests/reql_math_logic_aliases_test.go similarity index 99% rename from internal/reql_tests/reql_math_logic_aliases_test.go rename to internal/integration/reql_tests/reql_math_logic_aliases_test.go index e4a11067..37447fa1 100644 --- a/internal/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/reql_tests/reql_math_logic_comparison_test.go b/internal/integration/reql_tests/reql_math_logic_comparison_test.go similarity index 99% rename from internal/reql_tests/reql_math_logic_comparison_test.go rename to internal/integration/reql_tests/reql_math_logic_comparison_test.go index acf42331..4b333a4b 100644 --- a/internal/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/reql_tests/reql_math_logic_div_test.go b/internal/integration/reql_tests/reql_math_logic_div_test.go similarity index 98% rename from internal/reql_tests/reql_math_logic_div_test.go rename to internal/integration/reql_tests/reql_math_logic_div_test.go index 32d445df..13d65af4 100644 --- a/internal/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/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 99% 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 index a1b68d5a..21c6492e 100644 --- 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 @@ -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/reql_tests/reql_math_logic_logic_test.go b/internal/integration/reql_tests/reql_math_logic_logic_test.go similarity index 99% rename from internal/reql_tests/reql_math_logic_logic_test.go rename to internal/integration/reql_tests/reql_math_logic_logic_test.go index ecbc4884..536f9286 100644 --- a/internal/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/reql_tests/reql_math_logic_math_test.go b/internal/integration/reql_tests/reql_math_logic_math_test.go similarity index 95% rename from internal/reql_tests/reql_math_logic_math_test.go rename to internal/integration/reql_tests/reql_math_logic_math_test.go index 8e2dc6c1..1ddbff7f 100644 --- a/internal/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/reql_tests/reql_math_logic_mod_test.go b/internal/integration/reql_tests/reql_math_logic_mod_test.go similarity index 97% rename from internal/reql_tests/reql_math_logic_mod_test.go rename to internal/integration/reql_tests/reql_math_logic_mod_test.go index 57ea5a6b..31734e23 100644 --- a/internal/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/reql_tests/reql_math_logic_mul_test.go b/internal/integration/reql_tests/reql_math_logic_mul_test.go similarity index 98% rename from internal/reql_tests/reql_math_logic_mul_test.go rename to internal/integration/reql_tests/reql_math_logic_mul_test.go index 9d4aee60..6f8155ec 100644 --- a/internal/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/reql_tests/reql_math_logic_sub_test.go b/internal/integration/reql_tests/reql_math_logic_sub_test.go similarity index 98% rename from internal/reql_tests/reql_math_logic_sub_test.go rename to internal/integration/reql_tests/reql_math_logic_sub_test.go index 7bfaa417..58c2d387 100644 --- a/internal/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/reql_tests/reql_meta_composite_test.go b/internal/integration/reql_tests/reql_meta_composite_test.go similarity index 97% rename from internal/reql_tests/reql_meta_composite_test.go rename to internal/integration/reql_tests/reql_meta_composite_test.go index efb43481..e8a870d9 100644 --- a/internal/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/reql_tests/reql_meta_dbs_test.go b/internal/integration/reql_tests/reql_meta_dbs_test.go similarity index 98% rename from internal/reql_tests/reql_meta_dbs_test.go rename to internal/integration/reql_tests/reql_meta_dbs_test.go index 7259a2c5..60292c9c 100644 --- a/internal/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/reql_tests/reql_meta_table_test.go b/internal/integration/reql_tests/reql_meta_table_test.go similarity index 99% rename from internal/reql_tests/reql_meta_table_test.go rename to internal/integration/reql_tests/reql_meta_table_test.go index a952060a..e7934d69 100644 --- a/internal/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/reql_tests/reql_mutation_atomic_get_set_test.go b/internal/integration/reql_tests/reql_mutation_atomic_get_set_test.go similarity index 99% 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 index 2524ca2c..bdb7e4f5 100644 --- a/internal/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/reql_tests/reql_mutation_delete_test.go b/internal/integration/reql_tests/reql_mutation_delete_test.go similarity index 98% rename from internal/reql_tests/reql_mutation_delete_test.go rename to internal/integration/reql_tests/reql_mutation_delete_test.go index a1701a88..64af56c7 100644 --- a/internal/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/reql_tests/reql_mutation_insert_test.go b/internal/integration/reql_tests/reql_mutation_insert_test.go similarity index 99% rename from internal/reql_tests/reql_mutation_insert_test.go rename to internal/integration/reql_tests/reql_mutation_insert_test.go index 0f6e3223..6f936d76 100644 --- a/internal/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/reql_tests/reql_mutation_replace_test.go b/internal/integration/reql_tests/reql_mutation_replace_test.go similarity index 99% rename from internal/reql_tests/reql_mutation_replace_test.go rename to internal/integration/reql_tests/reql_mutation_replace_test.go index 860d087b..82caa367 100644 --- a/internal/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/reql_tests/reql_mutation_sync_test.go b/internal/integration/reql_tests/reql_mutation_sync_test.go similarity index 98% rename from internal/reql_tests/reql_mutation_sync_test.go rename to internal/integration/reql_tests/reql_mutation_sync_test.go index 50e9a437..bd6b81b5 100644 --- a/internal/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/reql_tests/reql_mutation_update_test.go b/internal/integration/reql_tests/reql_mutation_update_test.go similarity index 99% rename from internal/reql_tests/reql_mutation_update_test.go rename to internal/integration/reql_tests/reql_mutation_update_test.go index 336fd868..64d7b95f 100644 --- a/internal/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/reql_tests/reql_polymorphism_test.go b/internal/integration/reql_tests/reql_polymorphism_test.go similarity index 98% rename from internal/reql_tests/reql_polymorphism_test.go rename to internal/integration/reql_tests/reql_polymorphism_test.go index cdad3d7e..9697b7ca 100644 --- a/internal/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/reql_tests/reql_random_test.go b/internal/integration/reql_tests/reql_random_test.go similarity index 99% rename from internal/reql_tests/reql_random_test.go rename to internal/integration/reql_tests/reql_random_test.go index 45f288cb..02d9cc7c 100644 --- a/internal/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/reql_tests/reql_range_test.go b/internal/integration/reql_tests/reql_range_test.go similarity index 98% rename from internal/reql_tests/reql_range_test.go rename to internal/integration/reql_tests/reql_range_test.go index aa411423..4acf1b2c 100644 --- a/internal/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/reql_tests/reql_selection_test.go b/internal/integration/reql_tests/reql_selection_test.go similarity index 99% rename from internal/reql_tests/reql_selection_test.go rename to internal/integration/reql_tests/reql_selection_test.go index 9bbd5ccd..6b8147b1 100644 --- a/internal/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/reql_tests/reql_sindex_api_test.go b/internal/integration/reql_tests/reql_sindex_api_test.go similarity index 99% rename from internal/reql_tests/reql_sindex_api_test.go rename to internal/integration/reql_tests/reql_sindex_api_test.go index 82ca2c61..729071f8 100644 --- a/internal/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/reql_tests/reql_sindex_nullsinstrings_test.go b/internal/integration/reql_tests/reql_sindex_nullsinstrings_test.go similarity index 98% rename from internal/reql_tests/reql_sindex_nullsinstrings_test.go rename to internal/integration/reql_tests/reql_sindex_nullsinstrings_test.go index 5bf3b5df..ec2f3d55 100644 --- a/internal/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/reql_tests/reql_sindex_status_test.go b/internal/integration/reql_tests/reql_sindex_status_test.go similarity index 99% rename from internal/reql_tests/reql_sindex_status_test.go rename to internal/integration/reql_tests/reql_sindex_status_test.go index 947def2d..2d106cfc 100644 --- a/internal/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/reql_tests/reql_timeout_test.go b/internal/integration/reql_tests/reql_timeout_test.go similarity index 98% rename from internal/reql_tests/reql_timeout_test.go rename to internal/integration/reql_tests/reql_timeout_test.go index 7c153929..54900f04 100644 --- a/internal/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/reql_tests/reql_times_api_test.go b/internal/integration/reql_tests/reql_times_api_test.go similarity index 99% rename from internal/reql_tests/reql_times_api_test.go rename to internal/integration/reql_tests/reql_times_api_test.go index 1d39ceb4..cb9f176d 100644 --- a/internal/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/reql_tests/reql_times_constructors_test.go b/internal/integration/reql_tests/reql_times_constructors_test.go similarity index 99% rename from internal/reql_tests/reql_times_constructors_test.go rename to internal/integration/reql_tests/reql_times_constructors_test.go index 59d450dc..16e5e7e0 100644 --- a/internal/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/reql_tests/reql_times_index_test.go b/internal/integration/reql_tests/reql_times_index_test.go similarity index 99% rename from internal/reql_tests/reql_times_index_test.go rename to internal/integration/reql_tests/reql_times_index_test.go index fbda5ed7..07434cc9 100644 --- a/internal/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/reql_tests/reql_times_portions_test.go b/internal/integration/reql_tests/reql_times_portions_test.go similarity index 98% rename from internal/reql_tests/reql_times_portions_test.go rename to internal/integration/reql_tests/reql_times_portions_test.go index d92ee3dd..7063911c 100644 --- a/internal/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/reql_tests/reql_times_shim_test.go b/internal/integration/reql_tests/reql_times_shim_test.go similarity index 97% rename from internal/reql_tests/reql_times_shim_test.go rename to internal/integration/reql_tests/reql_times_shim_test.go index cd215df5..34a123c9 100644 --- a/internal/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/reql_tests/reql_times_time_arith_test.go b/internal/integration/reql_tests/reql_times_time_arith_test.go similarity index 99% rename from internal/reql_tests/reql_times_time_arith_test.go rename to internal/integration/reql_tests/reql_times_time_arith_test.go index 34270ea4..525f4d41 100644 --- a/internal/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/reql_tests/reql_times_timezones_test.go b/internal/integration/reql_tests/reql_times_timezones_test.go similarity index 99% rename from internal/reql_tests/reql_times_timezones_test.go rename to internal/integration/reql_tests/reql_times_timezones_test.go index c3833dab..943f3411 100644 --- a/internal/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/reql_tests/reql_transform_array_test.go b/internal/integration/reql_tests/reql_transform_array_test.go similarity index 99% rename from internal/reql_tests/reql_transform_array_test.go rename to internal/integration/reql_tests/reql_transform_array_test.go index a2ae9034..cc59c852 100644 --- a/internal/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/reql_tests/reql_transform_fold_test.go b/internal/integration/reql_tests/reql_transform_fold_test.go similarity index 99% rename from internal/reql_tests/reql_transform_fold_test.go rename to internal/integration/reql_tests/reql_transform_fold_test.go index 67243a80..0cccdcea 100644 --- a/internal/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/reql_tests/reql_transform_map_test.go b/internal/integration/reql_tests/reql_transform_map_test.go similarity index 99% rename from internal/reql_tests/reql_transform_map_test.go rename to internal/integration/reql_tests/reql_transform_map_test.go index 1f608909..e5789bd1 100644 --- a/internal/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/reql_tests/reql_transform_object_test.go b/internal/integration/reql_tests/reql_transform_object_test.go similarity index 99% rename from internal/reql_tests/reql_transform_object_test.go rename to internal/integration/reql_tests/reql_transform_object_test.go index 1e643a14..1da407d6 100644 --- a/internal/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/reql_tests/reql_transform_table_test.go b/internal/integration/reql_tests/reql_transform_table_test.go similarity index 97% rename from internal/reql_tests/reql_transform_table_test.go rename to internal/integration/reql_tests/reql_transform_table_test.go index e68c74f6..7a3f90d9 100644 --- a/internal/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/reql_tests/reql_transform_unordered_map_test.go b/internal/integration/reql_tests/reql_transform_unordered_map_test.go similarity index 99% rename from internal/reql_tests/reql_transform_unordered_map_test.go rename to internal/integration/reql_tests/reql_transform_unordered_map_test.go index c4005697..cba02545 100644 --- a/internal/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/reql_tests/reql_transformation_test.go b/internal/integration/reql_tests/reql_transformation_test.go similarity index 99% rename from internal/reql_tests/reql_transformation_test.go rename to internal/integration/reql_tests/reql_transformation_test.go index 6e3a481d..34a5a0f1 100644 --- a/internal/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/reql_tests/template.go.tpl b/internal/integration/reql_tests/template.go.tpl similarity index 97% rename from internal/reql_tests/template.go.tpl rename to internal/integration/reql_tests/template.go.tpl index 3ca8fbb4..7d69df74 100644 --- a/internal/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/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..6c206999 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.v4" ) 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 95% rename from checkers_test.go rename to internal/integration/tests/checkers.go index baca1b1a..9cb1bf06 100644 --- a/checkers_test.go +++ b/internal/integration/tests/checkers.go @@ -1,4 +1,4 @@ -package gorethink +package tests import ( "encoding/json" @@ -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 { @@ -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 66% rename from cluster_integration_test.go rename to internal/integration/tests/cluster_integration_test.go index 929a235b..9c188709 100644 --- a/cluster_integration_test.go +++ b/internal/integration/tests/cluster_integration_test.go @@ -1,16 +1,23 @@ // +build cluster // +build integration -package gorethink +package tests import ( "time" test "gopkg.in/check.v1" + r "gopkg.in/gorethink/gorethink.v4" + "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/cluster_test.go b/internal/integration/tests/cluster_test.go similarity index 71% rename from cluster_test.go rename to internal/integration/tests/cluster_test.go index d7f334f8..6a20fad7 100644 --- a/cluster_test.go +++ b/internal/integration/tests/cluster_test.go @@ -1,21 +1,22 @@ // +build cluster -package gorethink +package tests import ( "fmt" "time" test "gopkg.in/check.v1" + r "gopkg.in/gorethink/gorethink.v4" ) 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,25 +26,25 @@ 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", i)).Run(session) + row, err := r.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)) } } 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/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..bfeada6b 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.v4" ) 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 57% rename from example_connect_test.go rename to internal/integration/tests/example_connect_test.go index 18ce3050..8e09d1a7 100644 --- a/example_connect_test.go +++ b/internal/integration/tests/example_connect_test.go @@ -1,28 +1,28 @@ -package gorethink_test +package tests import ( "log" "os" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) -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..c1690613 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.v4" ) // 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..e17d1d89 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.v4" ) // 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..8925f418 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.v4" ) // 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..c78bdac9 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.v4" ) // 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..979b14dd 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.v4" ) // 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..e6a283b3 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.v4" ) // 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..7405a7ad 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.v4" ) // 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..249dd952 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.v4" ) // 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 86% rename from example_test.go rename to internal/integration/tests/example_test.go index 83743826..4e0cfba0 100644 --- a/example_test.go +++ b/internal/integration/tests/example_test.go @@ -1,10 +1,10 @@ -package gorethink_test +package tests import ( "fmt" "log" - r "gopkg.in/gorethink/gorethink.v3" + r "gopkg.in/gorethink/gorethink.v4" ) func Example() { 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..496ec3a5 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.v4" ) -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..f8a21182 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.v4" ) 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()) } @@ -456,23 +457,22 @@ func (s *RethinkSuite) TestTableChanges(c *test.C) { n++ } + defer wg.Done() if res.Err() != nil { c.Fatal(res.Err()) } - - 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 +480,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 +501,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 +517,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 +547,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()) } @@ -576,18 +576,17 @@ func (s *RethinkSuite) TestTableChangesIncludeInitial(c *test.C) { n++ } + defer wg.Done() if res.Err() != nil { c.Fatal(res.Err()) } - - 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 +605,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 +635,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 +661,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 +671,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 +682,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 +692,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 +701,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 +747,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..5ea97d96 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.v4" ) 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..5919debc 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.v4") 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.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 2ec33ea6..c01fea64 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.v4/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..6664f221 --- /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() + return args.Error(0) +} + +func (m* connMock) SetReadDeadline(t time.Time) error { + args := m.Called() + return args.Error(0) +} + +func (m* connMock) SetWriteDeadline(t time.Time) error { + args := m.Called() + return args.Error(0) +} 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 dbdb14a9..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 @@ -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"` @@ -219,7 +224,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 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