├── README.md ├── collection.go ├── database.go ├── dbtest.go ├── gen-mocks.sh ├── iter.go ├── pipe.go ├── pmgo.go ├── pmgomock ├── collection.go ├── database.go ├── dbtest.go ├── iter.go ├── pipe.go ├── pmgo.go ├── query.go └── session.go ├── query.go └── session.go /README.md: -------------------------------------------------------------------------------- 1 | # Percona MongoDB Go driver 2 | 3 | [![](https://godoc.org/github.com/percona/toolkit-go/pmgo?status.svg)](https://godoc.org/github.com/percona/toolkit-go/pmgo) 4 | 5 | **WIP** NOT ALL INTERFACES HAVE BEEN IMPLEMENTED YET 6 | 7 | This is just a collection of interfaces around the structures in mgo, ([Rich MongoDB driver for Go](https://labix.org/mgo)) to be able to mock methods in the driver. 8 | 9 | The motivation for this package is that there are certain things, like errors, that cannot be tested/reproduced using a real db connection. 10 | Also, for some of our tests we need very specific MongoDB configuration. Tests for some parts of our code need 2 replicas, config and mongo**s** servers and that's not easily reproducible in all CI environments. 11 | 12 | ## How to use it 13 | 14 | This package is almost a drop-in replacement with the exception that you need to use the `Dialer` interface. 15 | 16 | ```go 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | 23 | "github.com/percona/pmgo" 24 | "gopkg.in/mgo.v2/bson" 25 | ) 26 | 27 | type User struct { 28 | ID int `bson:"id"` 29 | Name string `bson:"name"` 30 | } 31 | 32 | func main() { 33 | dialer := pmgo.NewDialer() 34 | session, err := dialer.Dial("localhost") 35 | if err != nil { 36 | print(err) 37 | return 38 | } 39 | 40 | user, err := getUser(session, 1) 41 | if err != nil { 42 | log.Printf("error reading the user from the db: %s", err.Error()) 43 | return 44 | } 45 | fmt.Printf("User: %+v\n", user) 46 | 47 | } 48 | 49 | func getUser(session pmgo.SessionManager, id int) (*User, error) { 50 | var user User 51 | err := session.DB("test").C("testc").Find(bson.M{"id": id}).One(&user) 52 | 53 | if err != nil { 54 | return nil, err 55 | } 56 | 57 | return &user, nil 58 | } 59 | ``` 60 | 61 | ### How to write unitary tests (mocking interfaces) 62 | 63 | ```go 64 | package main 65 | 66 | import ( 67 | "fmt" 68 | "io/ioutil" 69 | "os" 70 | "reflect" 71 | "testing" 72 | 73 | "gopkg.in/mgo.v2/bson" 74 | 75 | "github.com/golang/mock/gomock" 76 | "github.com/percona/pmgo" 77 | "github.com/percona/pmgo/pmgomock" 78 | ) 79 | 80 | var Server pmgo.DBTestServer 81 | 82 | func TestGetUser(t *testing.T) { 83 | 84 | ctrl := gomock.NewController(t) 85 | defer ctrl.Finish() 86 | 87 | user := User{ 88 | ID: 1, 89 | Name: "Zapp Brannigan", 90 | } 91 | 92 | // Mock up a database, session, collection and a query and set 93 | // expected/returned values for each type 94 | query := pmgomock.NewMockQueryManager(ctrl) 95 | query.EXPECT().One(gomock.Any()).SetArg(0, user).Return(nil) 96 | 97 | collection := pmgomock.NewMockCollectionManager(ctrl) 98 | collection.EXPECT().Find(bson.M{"id": 1}).Return(query) 99 | 100 | database := pmgomock.NewMockDatabaseManager(ctrl) 101 | database.EXPECT().C("testc").Return(collection) 102 | 103 | session := pmgomock.NewMockSessionManager(ctrl) 104 | session.EXPECT().DB("test").Return(database) 105 | 106 | // Call the function we want to test. It will use the mocked interfaces 107 | readUser, err := getUser(session, 1) 108 | 109 | if err != nil { 110 | t.Errorf("getUser returned an error: %s\n", err.Error()) 111 | } 112 | 113 | if !reflect.DeepEqual(*readUser, user) { 114 | t.Errorf("Users don't match. Got %+v, want %+v\n", readUser, user) 115 | } 116 | } 117 | ``` 118 | 119 | ### How to write integration tests 120 | A not so well known testing method is the use of mgo's dbtest server. 121 | dbtest starts a new MongoDB instance (mongo binary must be in the path), using a temporary directory as dbpath 122 | and then on Stop() it will clean all testing data. 123 | pmgo also has interfaces for `dbtest.DBServer` to use in integration tests: 124 | 125 | ```go 126 | func TestIntegration(t *testing.T) { 127 | setup() 128 | 129 | readUser, err := getUser(Server.Session(), 1) 130 | if err != nil { 131 | t.Errorf("getUser returned an error: %s\n", err.Error()) 132 | } 133 | 134 | if !reflect.DeepEqual(*readUser, mockUser()) { 135 | t.Errorf("Users don't match. Got %+v, want %+v\n", readUser, mockUser()) 136 | } 137 | 138 | tearDown() 139 | } 140 | 141 | func setup() { 142 | os.Setenv("CHECK_SESSIONS", "0") 143 | tempDir, _ := ioutil.TempDir("", "testing") 144 | Server = pmgo.NewDBServer() 145 | Server.SetPath(tempDir) 146 | 147 | session := Server.Session() 148 | // load some fake data into the db 149 | session.DB("test").C("testc").Insert(mockUser()) 150 | } 151 | 152 | func mockUser() User { 153 | return User{ 154 | ID: 1, 155 | Name: "Zapp Brannigan", 156 | } 157 | 158 | } 159 | 160 | func tearDown() { 161 | Server.Session().Close() 162 | Server.Session().DB("samples").DropDatabase() 163 | Server.Stop() 164 | } 165 | ``` 166 | 167 | 168 | ## Generating new mocks 169 | If you update a file to add more functions, you can create new mocks by running: 170 | ``` 171 | mockgen -source /pmgo/collection.go -destination=/pmgo/pmgomock/collection.go -package pmgomock -imports ".=github.com/percona/pmgo" 172 | ``` 173 | 174 | -------------------------------------------------------------------------------- /collection.go: -------------------------------------------------------------------------------- 1 | package pmgo 2 | 3 | import mgo "gopkg.in/mgo.v2" 4 | 5 | // CollectionManager is an interface for mgo.Collection struct. 6 | // All implemented methods returns interfaces when needed 7 | type CollectionManager interface { 8 | Count() (int, error) 9 | Create(*mgo.CollectionInfo) error 10 | DropCollection() error 11 | //DropIndex(key ...string) error 12 | //DropIndexName(name string) error 13 | //EnsureIndex(index mgo.Index) error 14 | //EnsureIndexKey(key ...string) error 15 | Find(interface{}) QueryManager 16 | //FindId(id interface{}) *QueryManager 17 | //Indexes() (indexes []mgo.Index, err error) 18 | Insert(docs ...interface{}) error 19 | //NewIter(session *mgo.Session, firstBatch []bson.Raw, cursorId int64, err error) *mgo.Iter 20 | Pipe(interface{}) PipeManager 21 | //Remove(selector interface{}) error 22 | //RemoveAll(selector interface{}) (info *mgo.ChangeInfo, err error) 23 | //RemoveId(id interface{}) error 24 | //Repair() *mgo.Iter 25 | //Update(selector interface{}, update interface{}) error 26 | //UpdateAll(selector interface{}, update interface{}) (info *mgo.ChangeInfo, err error) 27 | //UpdateId(id interface{}, update interface{}) error 28 | //Upsert(selector interface{}, update interface{}) (info *mgo.ChangeInfo, err error) 29 | //UpsertId(id interface{}, update interface{}) (info *mgo.ChangeInfo, err error) 30 | //With(s *mgo.Session) *CollectionManager 31 | } 32 | 33 | type Collection struct { 34 | collection *mgo.Collection 35 | } 36 | 37 | func NewCollectionManager(c *mgo.Collection) CollectionManager { 38 | return &Collection{ 39 | collection: c, 40 | } 41 | } 42 | 43 | func (c *Collection) Count() (int, error) { 44 | return c.collection.Count() 45 | } 46 | 47 | func (c *Collection) Create(info *mgo.CollectionInfo) error { 48 | return c.collection.Create(info) 49 | } 50 | 51 | func (c *Collection) DropCollection() error { 52 | return c.collection.DropCollection() 53 | } 54 | 55 | func (c *Collection) Find(qu interface{}) QueryManager { 56 | return &Query{ 57 | query: c.collection.Find(qu), 58 | } 59 | } 60 | 61 | func (c *Collection) Insert(docs ...interface{}) error { 62 | return c.collection.Insert(docs...) 63 | } 64 | 65 | func (c *Collection) Pipe(query interface{}) PipeManager { 66 | return &Pipe{ 67 | pipe: c.collection.Pipe(query), 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /database.go: -------------------------------------------------------------------------------- 1 | package pmgo 2 | 3 | import mgo "gopkg.in/mgo.v2" 4 | 5 | type DatabaseManager interface { 6 | // AddUser(username, password string, readOnly bool) error 7 | C(name string) CollectionManager 8 | CollectionNames() (names []string, err error) 9 | DropDatabase() error 10 | // FindRef(ref *DBRef) *Query 11 | // GridFS(prefix string) *GridFS 12 | Login(user, pass string) error 13 | // Logout() 14 | // RemoveUser(user string) error 15 | Run(cmd interface{}, result interface{}) error 16 | // UpsertUser(user *User) error 17 | // With(s *Session) *Database 18 | } 19 | 20 | type Database struct { 21 | db *mgo.Database 22 | } 23 | 24 | func NewDatabaseManager(d *mgo.Database) DatabaseManager { 25 | return &Database{ 26 | db: d, 27 | } 28 | } 29 | 30 | func (d *Database) C(name string) CollectionManager { 31 | c := &Collection{ 32 | collection: d.db.C(name), 33 | } 34 | return c 35 | } 36 | 37 | func (d *Database) CollectionNames() ([]string, error) { 38 | return d.db.CollectionNames() 39 | } 40 | 41 | func (d *Database) DropDatabase() error { 42 | return d.db.DropDatabase() 43 | } 44 | 45 | func (d *Database) Run(cmd interface{}, result interface{}) error { 46 | return d.db.Run(cmd, result) 47 | } 48 | 49 | func (d *Database) Login(user, pass string) error { 50 | return d.db.Login(user, pass) 51 | } 52 | 53 | func (d *Database) Logout() { 54 | d.db.Logout() 55 | } 56 | -------------------------------------------------------------------------------- /dbtest.go: -------------------------------------------------------------------------------- 1 | package pmgo 2 | 3 | import "gopkg.in/mgo.v2/dbtest" 4 | 5 | type DBTestServer interface { 6 | Session() SessionManager 7 | SetPath(dbpath string) 8 | Stop() 9 | Wipe() 10 | } 11 | 12 | type DBTServer struct { 13 | dbserver dbtest.DBServer 14 | } 15 | 16 | func NewDBServer() DBTestServer { 17 | return &DBTServer{} 18 | } 19 | 20 | func (d *DBTServer) Session() SessionManager { 21 | se := &Session{ 22 | session: d.dbserver.Session(), 23 | } 24 | return se 25 | } 26 | 27 | func (d *DBTServer) SetPath(dbpath string) { 28 | d.dbserver.SetPath(dbpath) 29 | } 30 | 31 | func (d *DBTServer) Stop() { 32 | d.dbserver.Stop() 33 | } 34 | 35 | func (d *DBTServer) Wipe() { 36 | d.dbserver.Wipe() 37 | } 38 | -------------------------------------------------------------------------------- /gen-mocks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CURDIR=$(pwd) 3 | for file in *.go 4 | do 5 | echo "mockgen -source ${CURDIR}/${file} -destination=${CURDIR}/pmgomock/${file} -package pmgomock -imports \".=github.com/percona/pmgo\"" 6 | mockgen -source ${CURDIR}/${file} -destination=${CURDIR}/pmgomock/${file} -package pmgomock -imports ".=github.com/percona/pmgo" 7 | done 8 | -------------------------------------------------------------------------------- /iter.go: -------------------------------------------------------------------------------- 1 | package pmgo 2 | 3 | import mgo "gopkg.in/mgo.v2" 4 | 5 | type IterManager interface { 6 | All(result interface{}) error 7 | Close() error 8 | Done() bool 9 | Err() error 10 | For(result interface{}, f func() error) (err error) 11 | Next(result interface{}) bool 12 | Timeout() bool 13 | } 14 | 15 | type Iter struct { 16 | iter *mgo.Iter 17 | } 18 | 19 | func NewIter(iter *mgo.Iter) IterManager { 20 | return &Iter{iter} 21 | } 22 | 23 | func (i *Iter) All(result interface{}) error { 24 | return i.iter.All(result) 25 | } 26 | 27 | func (i *Iter) Close() error { 28 | return i.iter.Close() 29 | } 30 | 31 | func (i *Iter) Done() bool { 32 | return i.iter.Done() 33 | } 34 | 35 | func (i *Iter) Err() error { 36 | return i.iter.Err() 37 | } 38 | 39 | func (i *Iter) For(result interface{}, f func() error) (err error) { 40 | return i.iter.For(result, f) 41 | } 42 | 43 | func (i *Iter) Next(result interface{}) bool { 44 | return i.iter.Next(result) 45 | } 46 | 47 | func (i *Iter) Timeout() bool { 48 | return i.iter.Timeout() 49 | } 50 | -------------------------------------------------------------------------------- /pipe.go: -------------------------------------------------------------------------------- 1 | package pmgo 2 | 3 | import mgo "gopkg.in/mgo.v2" 4 | 5 | type PipeManager interface { 6 | All(result interface{}) error 7 | AllowDiskUse() PipeManager 8 | Batch(n int) PipeManager 9 | Explain(result interface{}) error 10 | Iter() *mgo.Iter 11 | One(result interface{}) error 12 | } 13 | 14 | type Pipe struct { 15 | pipe *mgo.Pipe 16 | } 17 | 18 | func NewPipeManager(p *mgo.Pipe) PipeManager { 19 | return &Pipe{ 20 | pipe: p, 21 | } 22 | } 23 | 24 | func (p *Pipe) All(result interface{}) error { 25 | return p.pipe.All(result) 26 | } 27 | 28 | func (p *Pipe) AllowDiskUse() PipeManager { 29 | return &Pipe{ 30 | pipe: p.pipe, 31 | } 32 | } 33 | 34 | func (p *Pipe) Batch(n int) PipeManager { 35 | return &Pipe{ 36 | pipe: p.pipe.Batch(n), 37 | } 38 | } 39 | 40 | func (p *Pipe) Explain(result interface{}) error { 41 | return p.pipe.Explain(result) 42 | } 43 | 44 | func (p *Pipe) Iter() *mgo.Iter { 45 | return p.pipe.Iter() 46 | } 47 | 48 | func (p *Pipe) One(result interface{}) error { 49 | return p.pipe.One(result) 50 | } 51 | -------------------------------------------------------------------------------- /pmgo.go: -------------------------------------------------------------------------------- 1 | package pmgo 2 | 3 | import ( 4 | "crypto/tls" 5 | "crypto/x509" 6 | "fmt" 7 | "io/ioutil" 8 | "net" 9 | "os" 10 | "time" 11 | 12 | mgo "gopkg.in/mgo.v2" 13 | ) 14 | 15 | type Dialer interface { 16 | Dial(string) (SessionManager, error) 17 | DialWithInfo(*DialInfo) (SessionManager, error) 18 | DialWithTimeout(string, time.Duration) (SessionManager, error) 19 | } 20 | 21 | type DialInfo struct { 22 | SSLPEMKeyFile string 23 | SSLCAFile string 24 | 25 | Addrs []string 26 | Direct bool 27 | Timeout time.Duration 28 | FailFast bool 29 | Database string 30 | ReplicaSetName string 31 | Source string 32 | Service string 33 | ServiceHost string 34 | Mechanism string 35 | Username string 36 | Password string 37 | PoolLimit int 38 | DialServer func(addr *mgo.ServerAddr) (net.Conn, error) 39 | } 40 | 41 | type dialer struct{} 42 | 43 | func NewDialInfo(src *mgo.DialInfo) *DialInfo { 44 | return &DialInfo{ 45 | Addrs: src.Addrs, 46 | Direct: src.Direct, 47 | Timeout: src.Timeout, 48 | FailFast: src.FailFast, 49 | Database: src.Database, 50 | ReplicaSetName: src.ReplicaSetName, 51 | Source: src.Source, 52 | Service: src.Service, 53 | ServiceHost: src.ServiceHost, 54 | Mechanism: src.Mechanism, 55 | Username: src.Username, 56 | Password: src.Password, 57 | PoolLimit: src.PoolLimit, 58 | DialServer: src.DialServer, 59 | } 60 | } 61 | 62 | func ParseURL(url string) (*DialInfo, error) { 63 | di, err := mgo.ParseURL(url) 64 | if err != nil { 65 | return nil, err 66 | } 67 | return NewDialInfo(di), nil 68 | } 69 | 70 | func NewDialer() Dialer { 71 | return new(dialer) 72 | } 73 | 74 | func (d *dialer) Dial(url string) (SessionManager, error) { 75 | s, err := mgo.Dial(url) 76 | se := &Session{ 77 | session: s, 78 | } 79 | return se, err 80 | } 81 | 82 | func (d *dialer) DialWithInfo(info *DialInfo) (SessionManager, error) { 83 | mgoInfo := &mgo.DialInfo{ 84 | Addrs: info.Addrs, 85 | Direct: info.Direct, 86 | Timeout: info.Timeout, 87 | FailFast: info.FailFast, 88 | Database: info.Database, 89 | ReplicaSetName: info.ReplicaSetName, 90 | Source: info.Source, 91 | Service: info.Service, 92 | ServiceHost: info.ServiceHost, 93 | Mechanism: info.Mechanism, 94 | Username: info.Username, 95 | Password: info.Password, 96 | PoolLimit: info.PoolLimit, 97 | DialServer: info.DialServer, 98 | } 99 | 100 | if info.SSLCAFile != "" || info.SSLPEMKeyFile != "" { 101 | tlsConfig := &tls.Config{} 102 | 103 | if info.SSLCAFile != "" { 104 | if _, err := os.Stat(info.SSLCAFile); os.IsNotExist(err) { 105 | return nil, err 106 | } 107 | 108 | roots := x509.NewCertPool() 109 | var ca []byte 110 | var err error 111 | 112 | if ca, err = ioutil.ReadFile(info.SSLCAFile); err != nil { 113 | return nil, fmt.Errorf("invalid pem file: %s", err.Error()) 114 | } 115 | roots.AppendCertsFromPEM(ca) 116 | tlsConfig.RootCAs = roots 117 | 118 | } 119 | 120 | if info.SSLPEMKeyFile != "" { 121 | cert, err := tls.LoadX509KeyPair(info.SSLPEMKeyFile, info.SSLPEMKeyFile) 122 | if err != nil { 123 | return nil, err 124 | } 125 | tlsConfig.Certificates = []tls.Certificate{cert} 126 | } 127 | 128 | mgoInfo.DialServer = func(addr *mgo.ServerAddr) (net.Conn, error) { 129 | conn, err := tls.Dial("tcp", addr.String(), tlsConfig) 130 | return conn, err 131 | } 132 | 133 | mgoInfo.Source = "$external" 134 | mgoInfo.Mechanism = "MONGODB-X509" 135 | } 136 | 137 | s, err := mgo.DialWithInfo(mgoInfo) 138 | 139 | se := &Session{ 140 | session: s, 141 | } 142 | return se, err 143 | } 144 | 145 | func (d *dialer) DialWithTimeout(url string, timeout time.Duration) (SessionManager, error) { 146 | s, err := mgo.DialWithTimeout(url, timeout) 147 | se := &Session{ 148 | session: s, 149 | } 150 | return se, err 151 | } 152 | -------------------------------------------------------------------------------- /pmgomock/collection.go: -------------------------------------------------------------------------------- 1 | // Automatically generated by MockGen. DO NOT EDIT! 2 | // Source: /home/karl/golang/src/github.com/percona/pmgo/collection.go 3 | 4 | package pmgomock 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | . "github.com/percona/pmgo" 9 | mgo_v2 "gopkg.in/mgo.v2" 10 | ) 11 | 12 | // Mock of CollectionManager interface 13 | type MockCollectionManager struct { 14 | ctrl *gomock.Controller 15 | recorder *_MockCollectionManagerRecorder 16 | } 17 | 18 | // Recorder for MockCollectionManager (not exported) 19 | type _MockCollectionManagerRecorder struct { 20 | mock *MockCollectionManager 21 | } 22 | 23 | func NewMockCollectionManager(ctrl *gomock.Controller) *MockCollectionManager { 24 | mock := &MockCollectionManager{ctrl: ctrl} 25 | mock.recorder = &_MockCollectionManagerRecorder{mock} 26 | return mock 27 | } 28 | 29 | func (_m *MockCollectionManager) EXPECT() *_MockCollectionManagerRecorder { 30 | return _m.recorder 31 | } 32 | 33 | func (_m *MockCollectionManager) Count() (int, error) { 34 | ret := _m.ctrl.Call(_m, "Count") 35 | ret0, _ := ret[0].(int) 36 | ret1, _ := ret[1].(error) 37 | return ret0, ret1 38 | } 39 | 40 | func (_mr *_MockCollectionManagerRecorder) Count() *gomock.Call { 41 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Count") 42 | } 43 | 44 | func (_m *MockCollectionManager) Create(_param0 *mgo_v2.CollectionInfo) error { 45 | ret := _m.ctrl.Call(_m, "Create", _param0) 46 | ret0, _ := ret[0].(error) 47 | return ret0 48 | } 49 | 50 | func (_mr *_MockCollectionManagerRecorder) Create(arg0 interface{}) *gomock.Call { 51 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Create", arg0) 52 | } 53 | 54 | func (_m *MockCollectionManager) DropCollection() error { 55 | ret := _m.ctrl.Call(_m, "DropCollection") 56 | ret0, _ := ret[0].(error) 57 | return ret0 58 | } 59 | 60 | func (_mr *_MockCollectionManagerRecorder) DropCollection() *gomock.Call { 61 | return _mr.mock.ctrl.RecordCall(_mr.mock, "DropCollection") 62 | } 63 | 64 | func (_m *MockCollectionManager) Find(_param0 interface{}) QueryManager { 65 | ret := _m.ctrl.Call(_m, "Find", _param0) 66 | ret0, _ := ret[0].(QueryManager) 67 | return ret0 68 | } 69 | 70 | func (_mr *_MockCollectionManagerRecorder) Find(arg0 interface{}) *gomock.Call { 71 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Find", arg0) 72 | } 73 | 74 | func (_m *MockCollectionManager) Insert(docs ...interface{}) error { 75 | _s := []interface{}{} 76 | for _, _x := range docs { 77 | _s = append(_s, _x) 78 | } 79 | ret := _m.ctrl.Call(_m, "Insert", _s...) 80 | ret0, _ := ret[0].(error) 81 | return ret0 82 | } 83 | 84 | func (_mr *_MockCollectionManagerRecorder) Insert(arg0 ...interface{}) *gomock.Call { 85 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Insert", arg0...) 86 | } 87 | 88 | func (_m *MockCollectionManager) Pipe(_param0 interface{}) PipeManager { 89 | ret := _m.ctrl.Call(_m, "Pipe", _param0) 90 | ret0, _ := ret[0].(PipeManager) 91 | return ret0 92 | } 93 | 94 | func (_mr *_MockCollectionManagerRecorder) Pipe(arg0 interface{}) *gomock.Call { 95 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Pipe", arg0) 96 | } 97 | -------------------------------------------------------------------------------- /pmgomock/database.go: -------------------------------------------------------------------------------- 1 | // Automatically generated by MockGen. DO NOT EDIT! 2 | // Source: /home/karl/golang/src/github.com/percona/pmgo/database.go 3 | 4 | package pmgomock 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | . "github.com/percona/pmgo" 9 | ) 10 | 11 | // Mock of DatabaseManager interface 12 | type MockDatabaseManager struct { 13 | ctrl *gomock.Controller 14 | recorder *_MockDatabaseManagerRecorder 15 | } 16 | 17 | // Recorder for MockDatabaseManager (not exported) 18 | type _MockDatabaseManagerRecorder struct { 19 | mock *MockDatabaseManager 20 | } 21 | 22 | func NewMockDatabaseManager(ctrl *gomock.Controller) *MockDatabaseManager { 23 | mock := &MockDatabaseManager{ctrl: ctrl} 24 | mock.recorder = &_MockDatabaseManagerRecorder{mock} 25 | return mock 26 | } 27 | 28 | func (_m *MockDatabaseManager) EXPECT() *_MockDatabaseManagerRecorder { 29 | return _m.recorder 30 | } 31 | 32 | func (_m *MockDatabaseManager) C(name string) CollectionManager { 33 | ret := _m.ctrl.Call(_m, "C", name) 34 | ret0, _ := ret[0].(CollectionManager) 35 | return ret0 36 | } 37 | 38 | func (_mr *_MockDatabaseManagerRecorder) C(arg0 interface{}) *gomock.Call { 39 | return _mr.mock.ctrl.RecordCall(_mr.mock, "C", arg0) 40 | } 41 | 42 | func (_m *MockDatabaseManager) CollectionNames() ([]string, error) { 43 | ret := _m.ctrl.Call(_m, "CollectionNames") 44 | ret0, _ := ret[0].([]string) 45 | ret1, _ := ret[1].(error) 46 | return ret0, ret1 47 | } 48 | 49 | func (_mr *_MockDatabaseManagerRecorder) CollectionNames() *gomock.Call { 50 | return _mr.mock.ctrl.RecordCall(_mr.mock, "CollectionNames") 51 | } 52 | 53 | func (_m *MockDatabaseManager) DropDatabase() error { 54 | ret := _m.ctrl.Call(_m, "DropDatabase") 55 | ret0, _ := ret[0].(error) 56 | return ret0 57 | } 58 | 59 | func (_mr *_MockDatabaseManagerRecorder) DropDatabase() *gomock.Call { 60 | return _mr.mock.ctrl.RecordCall(_mr.mock, "DropDatabase") 61 | } 62 | 63 | func (_m *MockDatabaseManager) Login(user string, pass string) error { 64 | ret := _m.ctrl.Call(_m, "Login", user, pass) 65 | ret0, _ := ret[0].(error) 66 | return ret0 67 | } 68 | 69 | func (_mr *_MockDatabaseManagerRecorder) Login(arg0, arg1 interface{}) *gomock.Call { 70 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Login", arg0, arg1) 71 | } 72 | 73 | func (_m *MockDatabaseManager) Run(cmd interface{}, result interface{}) error { 74 | ret := _m.ctrl.Call(_m, "Run", cmd, result) 75 | ret0, _ := ret[0].(error) 76 | return ret0 77 | } 78 | 79 | func (_mr *_MockDatabaseManagerRecorder) Run(arg0, arg1 interface{}) *gomock.Call { 80 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Run", arg0, arg1) 81 | } 82 | -------------------------------------------------------------------------------- /pmgomock/dbtest.go: -------------------------------------------------------------------------------- 1 | // Automatically generated by MockGen. DO NOT EDIT! 2 | // Source: /home/karl/golang/src/github.com/percona/pmgo/dbtest.go 3 | 4 | package pmgomock 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | . "github.com/percona/pmgo" 9 | ) 10 | 11 | // Mock of DBTestServer interface 12 | type MockDBTestServer struct { 13 | ctrl *gomock.Controller 14 | recorder *_MockDBTestServerRecorder 15 | } 16 | 17 | // Recorder for MockDBTestServer (not exported) 18 | type _MockDBTestServerRecorder struct { 19 | mock *MockDBTestServer 20 | } 21 | 22 | func NewMockDBTestServer(ctrl *gomock.Controller) *MockDBTestServer { 23 | mock := &MockDBTestServer{ctrl: ctrl} 24 | mock.recorder = &_MockDBTestServerRecorder{mock} 25 | return mock 26 | } 27 | 28 | func (_m *MockDBTestServer) EXPECT() *_MockDBTestServerRecorder { 29 | return _m.recorder 30 | } 31 | 32 | func (_m *MockDBTestServer) Session() SessionManager { 33 | ret := _m.ctrl.Call(_m, "Session") 34 | ret0, _ := ret[0].(SessionManager) 35 | return ret0 36 | } 37 | 38 | func (_mr *_MockDBTestServerRecorder) Session() *gomock.Call { 39 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Session") 40 | } 41 | 42 | func (_m *MockDBTestServer) SetPath(dbpath string) { 43 | _m.ctrl.Call(_m, "SetPath", dbpath) 44 | } 45 | 46 | func (_mr *_MockDBTestServerRecorder) SetPath(arg0 interface{}) *gomock.Call { 47 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetPath", arg0) 48 | } 49 | 50 | func (_m *MockDBTestServer) Stop() { 51 | _m.ctrl.Call(_m, "Stop") 52 | } 53 | 54 | func (_mr *_MockDBTestServerRecorder) Stop() *gomock.Call { 55 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Stop") 56 | } 57 | 58 | func (_m *MockDBTestServer) Wipe() { 59 | _m.ctrl.Call(_m, "Wipe") 60 | } 61 | 62 | func (_mr *_MockDBTestServerRecorder) Wipe() *gomock.Call { 63 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Wipe") 64 | } 65 | -------------------------------------------------------------------------------- /pmgomock/iter.go: -------------------------------------------------------------------------------- 1 | // Automatically generated by MockGen. DO NOT EDIT! 2 | // Source: /home/karl/golang/src/github.com/percona/pmgo/iter.go 3 | 4 | package pmgomock 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | ) 9 | 10 | // Mock of IterManager interface 11 | type MockIterManager struct { 12 | ctrl *gomock.Controller 13 | recorder *_MockIterManagerRecorder 14 | } 15 | 16 | // Recorder for MockIterManager (not exported) 17 | type _MockIterManagerRecorder struct { 18 | mock *MockIterManager 19 | } 20 | 21 | func NewMockIterManager(ctrl *gomock.Controller) *MockIterManager { 22 | mock := &MockIterManager{ctrl: ctrl} 23 | mock.recorder = &_MockIterManagerRecorder{mock} 24 | return mock 25 | } 26 | 27 | func (_m *MockIterManager) EXPECT() *_MockIterManagerRecorder { 28 | return _m.recorder 29 | } 30 | 31 | func (_m *MockIterManager) All(result interface{}) error { 32 | ret := _m.ctrl.Call(_m, "All", result) 33 | ret0, _ := ret[0].(error) 34 | return ret0 35 | } 36 | 37 | func (_mr *_MockIterManagerRecorder) All(arg0 interface{}) *gomock.Call { 38 | return _mr.mock.ctrl.RecordCall(_mr.mock, "All", arg0) 39 | } 40 | 41 | func (_m *MockIterManager) Close() error { 42 | ret := _m.ctrl.Call(_m, "Close") 43 | ret0, _ := ret[0].(error) 44 | return ret0 45 | } 46 | 47 | func (_mr *_MockIterManagerRecorder) Close() *gomock.Call { 48 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Close") 49 | } 50 | 51 | func (_m *MockIterManager) Done() bool { 52 | ret := _m.ctrl.Call(_m, "Done") 53 | ret0, _ := ret[0].(bool) 54 | return ret0 55 | } 56 | 57 | func (_mr *_MockIterManagerRecorder) Done() *gomock.Call { 58 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Done") 59 | } 60 | 61 | func (_m *MockIterManager) Err() error { 62 | ret := _m.ctrl.Call(_m, "Err") 63 | ret0, _ := ret[0].(error) 64 | return ret0 65 | } 66 | 67 | func (_mr *_MockIterManagerRecorder) Err() *gomock.Call { 68 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Err") 69 | } 70 | 71 | func (_m *MockIterManager) For(result interface{}, f func() error) error { 72 | ret := _m.ctrl.Call(_m, "For", result, f) 73 | ret0, _ := ret[0].(error) 74 | return ret0 75 | } 76 | 77 | func (_mr *_MockIterManagerRecorder) For(arg0, arg1 interface{}) *gomock.Call { 78 | return _mr.mock.ctrl.RecordCall(_mr.mock, "For", arg0, arg1) 79 | } 80 | 81 | func (_m *MockIterManager) Next(result interface{}) bool { 82 | ret := _m.ctrl.Call(_m, "Next", result) 83 | ret0, _ := ret[0].(bool) 84 | return ret0 85 | } 86 | 87 | func (_mr *_MockIterManagerRecorder) Next(arg0 interface{}) *gomock.Call { 88 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Next", arg0) 89 | } 90 | 91 | func (_m *MockIterManager) Timeout() bool { 92 | ret := _m.ctrl.Call(_m, "Timeout") 93 | ret0, _ := ret[0].(bool) 94 | return ret0 95 | } 96 | 97 | func (_mr *_MockIterManagerRecorder) Timeout() *gomock.Call { 98 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Timeout") 99 | } 100 | -------------------------------------------------------------------------------- /pmgomock/pipe.go: -------------------------------------------------------------------------------- 1 | // Automatically generated by MockGen. DO NOT EDIT! 2 | // Source: /home/karl/golang/src/github.com/percona/pmgo/pipe.go 3 | 4 | package pmgomock 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | . "github.com/percona/pmgo" 9 | mgo_v2 "gopkg.in/mgo.v2" 10 | ) 11 | 12 | // Mock of PipeManager interface 13 | type MockPipeManager struct { 14 | ctrl *gomock.Controller 15 | recorder *_MockPipeManagerRecorder 16 | } 17 | 18 | // Recorder for MockPipeManager (not exported) 19 | type _MockPipeManagerRecorder struct { 20 | mock *MockPipeManager 21 | } 22 | 23 | func NewMockPipeManager(ctrl *gomock.Controller) *MockPipeManager { 24 | mock := &MockPipeManager{ctrl: ctrl} 25 | mock.recorder = &_MockPipeManagerRecorder{mock} 26 | return mock 27 | } 28 | 29 | func (_m *MockPipeManager) EXPECT() *_MockPipeManagerRecorder { 30 | return _m.recorder 31 | } 32 | 33 | func (_m *MockPipeManager) All(result interface{}) error { 34 | ret := _m.ctrl.Call(_m, "All", result) 35 | ret0, _ := ret[0].(error) 36 | return ret0 37 | } 38 | 39 | func (_mr *_MockPipeManagerRecorder) All(arg0 interface{}) *gomock.Call { 40 | return _mr.mock.ctrl.RecordCall(_mr.mock, "All", arg0) 41 | } 42 | 43 | func (_m *MockPipeManager) AllowDiskUse() PipeManager { 44 | ret := _m.ctrl.Call(_m, "AllowDiskUse") 45 | ret0, _ := ret[0].(PipeManager) 46 | return ret0 47 | } 48 | 49 | func (_mr *_MockPipeManagerRecorder) AllowDiskUse() *gomock.Call { 50 | return _mr.mock.ctrl.RecordCall(_mr.mock, "AllowDiskUse") 51 | } 52 | 53 | func (_m *MockPipeManager) Batch(n int) PipeManager { 54 | ret := _m.ctrl.Call(_m, "Batch", n) 55 | ret0, _ := ret[0].(PipeManager) 56 | return ret0 57 | } 58 | 59 | func (_mr *_MockPipeManagerRecorder) Batch(arg0 interface{}) *gomock.Call { 60 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Batch", arg0) 61 | } 62 | 63 | func (_m *MockPipeManager) Explain(result interface{}) error { 64 | ret := _m.ctrl.Call(_m, "Explain", result) 65 | ret0, _ := ret[0].(error) 66 | return ret0 67 | } 68 | 69 | func (_mr *_MockPipeManagerRecorder) Explain(arg0 interface{}) *gomock.Call { 70 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Explain", arg0) 71 | } 72 | 73 | func (_m *MockPipeManager) Iter() *mgo_v2.Iter { 74 | ret := _m.ctrl.Call(_m, "Iter") 75 | ret0, _ := ret[0].(*mgo_v2.Iter) 76 | return ret0 77 | } 78 | 79 | func (_mr *_MockPipeManagerRecorder) Iter() *gomock.Call { 80 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Iter") 81 | } 82 | 83 | func (_m *MockPipeManager) One(result interface{}) error { 84 | ret := _m.ctrl.Call(_m, "One", result) 85 | ret0, _ := ret[0].(error) 86 | return ret0 87 | } 88 | 89 | func (_mr *_MockPipeManagerRecorder) One(arg0 interface{}) *gomock.Call { 90 | return _mr.mock.ctrl.RecordCall(_mr.mock, "One", arg0) 91 | } 92 | -------------------------------------------------------------------------------- /pmgomock/pmgo.go: -------------------------------------------------------------------------------- 1 | // Automatically generated by MockGen. DO NOT EDIT! 2 | // Source: /home/karl/golang/src/github.com/percona/pmgo/pmgo.go 3 | 4 | package pmgomock 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | . "github.com/percona/pmgo" 9 | time "time" 10 | ) 11 | 12 | // Mock of Dialer interface 13 | type MockDialer struct { 14 | ctrl *gomock.Controller 15 | recorder *_MockDialerRecorder 16 | } 17 | 18 | // Recorder for MockDialer (not exported) 19 | type _MockDialerRecorder struct { 20 | mock *MockDialer 21 | } 22 | 23 | func NewMockDialer(ctrl *gomock.Controller) *MockDialer { 24 | mock := &MockDialer{ctrl: ctrl} 25 | mock.recorder = &_MockDialerRecorder{mock} 26 | return mock 27 | } 28 | 29 | func (_m *MockDialer) EXPECT() *_MockDialerRecorder { 30 | return _m.recorder 31 | } 32 | 33 | func (_m *MockDialer) Dial(_param0 string) (SessionManager, error) { 34 | ret := _m.ctrl.Call(_m, "Dial", _param0) 35 | ret0, _ := ret[0].(SessionManager) 36 | ret1, _ := ret[1].(error) 37 | return ret0, ret1 38 | } 39 | 40 | func (_mr *_MockDialerRecorder) Dial(arg0 interface{}) *gomock.Call { 41 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Dial", arg0) 42 | } 43 | 44 | func (_m *MockDialer) DialWithInfo(_param0 *DialInfo) (SessionManager, error) { 45 | ret := _m.ctrl.Call(_m, "DialWithInfo", _param0) 46 | ret0, _ := ret[0].(SessionManager) 47 | ret1, _ := ret[1].(error) 48 | return ret0, ret1 49 | } 50 | 51 | func (_mr *_MockDialerRecorder) DialWithInfo(arg0 interface{}) *gomock.Call { 52 | return _mr.mock.ctrl.RecordCall(_mr.mock, "DialWithInfo", arg0) 53 | } 54 | 55 | func (_m *MockDialer) DialWithTimeout(_param0 string, _param1 time.Duration) (SessionManager, error) { 56 | ret := _m.ctrl.Call(_m, "DialWithTimeout", _param0, _param1) 57 | ret0, _ := ret[0].(SessionManager) 58 | ret1, _ := ret[1].(error) 59 | return ret0, ret1 60 | } 61 | 62 | func (_mr *_MockDialerRecorder) DialWithTimeout(arg0, arg1 interface{}) *gomock.Call { 63 | return _mr.mock.ctrl.RecordCall(_mr.mock, "DialWithTimeout", arg0, arg1) 64 | } 65 | -------------------------------------------------------------------------------- /pmgomock/query.go: -------------------------------------------------------------------------------- 1 | // Automatically generated by MockGen. DO NOT EDIT! 2 | // Source: /home/karl/golang/src/github.com/percona/pmgo/query.go 3 | 4 | package pmgomock 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | . "github.com/percona/pmgo" 9 | mgo_v2 "gopkg.in/mgo.v2" 10 | time "time" 11 | ) 12 | 13 | // Mock of QueryManager interface 14 | type MockQueryManager struct { 15 | ctrl *gomock.Controller 16 | recorder *_MockQueryManagerRecorder 17 | } 18 | 19 | // Recorder for MockQueryManager (not exported) 20 | type _MockQueryManagerRecorder struct { 21 | mock *MockQueryManager 22 | } 23 | 24 | func NewMockQueryManager(ctrl *gomock.Controller) *MockQueryManager { 25 | mock := &MockQueryManager{ctrl: ctrl} 26 | mock.recorder = &_MockQueryManagerRecorder{mock} 27 | return mock 28 | } 29 | 30 | func (_m *MockQueryManager) EXPECT() *_MockQueryManagerRecorder { 31 | return _m.recorder 32 | } 33 | 34 | func (_m *MockQueryManager) All(result interface{}) error { 35 | ret := _m.ctrl.Call(_m, "All", result) 36 | ret0, _ := ret[0].(error) 37 | return ret0 38 | } 39 | 40 | func (_mr *_MockQueryManagerRecorder) All(arg0 interface{}) *gomock.Call { 41 | return _mr.mock.ctrl.RecordCall(_mr.mock, "All", arg0) 42 | } 43 | 44 | func (_m *MockQueryManager) Apply(change mgo_v2.Change, result interface{}) (*mgo_v2.ChangeInfo, error) { 45 | ret := _m.ctrl.Call(_m, "Apply", change, result) 46 | ret0, _ := ret[0].(*mgo_v2.ChangeInfo) 47 | ret1, _ := ret[1].(error) 48 | return ret0, ret1 49 | } 50 | 51 | func (_mr *_MockQueryManagerRecorder) Apply(arg0, arg1 interface{}) *gomock.Call { 52 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Apply", arg0, arg1) 53 | } 54 | 55 | func (_m *MockQueryManager) Batch(n int) QueryManager { 56 | ret := _m.ctrl.Call(_m, "Batch", n) 57 | ret0, _ := ret[0].(QueryManager) 58 | return ret0 59 | } 60 | 61 | func (_mr *_MockQueryManagerRecorder) Batch(arg0 interface{}) *gomock.Call { 62 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Batch", arg0) 63 | } 64 | 65 | func (_m *MockQueryManager) Comment(comment string) QueryManager { 66 | ret := _m.ctrl.Call(_m, "Comment", comment) 67 | ret0, _ := ret[0].(QueryManager) 68 | return ret0 69 | } 70 | 71 | func (_mr *_MockQueryManagerRecorder) Comment(arg0 interface{}) *gomock.Call { 72 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Comment", arg0) 73 | } 74 | 75 | func (_m *MockQueryManager) Count() (int, error) { 76 | ret := _m.ctrl.Call(_m, "Count") 77 | ret0, _ := ret[0].(int) 78 | ret1, _ := ret[1].(error) 79 | return ret0, ret1 80 | } 81 | 82 | func (_mr *_MockQueryManagerRecorder) Count() *gomock.Call { 83 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Count") 84 | } 85 | 86 | func (_m *MockQueryManager) Distinct(key string, result interface{}) error { 87 | ret := _m.ctrl.Call(_m, "Distinct", key, result) 88 | ret0, _ := ret[0].(error) 89 | return ret0 90 | } 91 | 92 | func (_mr *_MockQueryManagerRecorder) Distinct(arg0, arg1 interface{}) *gomock.Call { 93 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Distinct", arg0, arg1) 94 | } 95 | 96 | func (_m *MockQueryManager) Explain(result interface{}) error { 97 | ret := _m.ctrl.Call(_m, "Explain", result) 98 | ret0, _ := ret[0].(error) 99 | return ret0 100 | } 101 | 102 | func (_mr *_MockQueryManagerRecorder) Explain(arg0 interface{}) *gomock.Call { 103 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Explain", arg0) 104 | } 105 | 106 | func (_m *MockQueryManager) For(result interface{}, f func() error) error { 107 | ret := _m.ctrl.Call(_m, "For", result, f) 108 | ret0, _ := ret[0].(error) 109 | return ret0 110 | } 111 | 112 | func (_mr *_MockQueryManagerRecorder) For(arg0, arg1 interface{}) *gomock.Call { 113 | return _mr.mock.ctrl.RecordCall(_mr.mock, "For", arg0, arg1) 114 | } 115 | 116 | func (_m *MockQueryManager) Hint(indexKey ...string) QueryManager { 117 | _s := []interface{}{} 118 | for _, _x := range indexKey { 119 | _s = append(_s, _x) 120 | } 121 | ret := _m.ctrl.Call(_m, "Hint", _s...) 122 | ret0, _ := ret[0].(QueryManager) 123 | return ret0 124 | } 125 | 126 | func (_mr *_MockQueryManagerRecorder) Hint(arg0 ...interface{}) *gomock.Call { 127 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Hint", arg0...) 128 | } 129 | 130 | func (_m *MockQueryManager) Iter() *mgo_v2.Iter { 131 | ret := _m.ctrl.Call(_m, "Iter") 132 | ret0, _ := ret[0].(*mgo_v2.Iter) 133 | return ret0 134 | } 135 | 136 | func (_mr *_MockQueryManagerRecorder) Iter() *gomock.Call { 137 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Iter") 138 | } 139 | 140 | func (_m *MockQueryManager) Limit(n int) QueryManager { 141 | ret := _m.ctrl.Call(_m, "Limit", n) 142 | ret0, _ := ret[0].(QueryManager) 143 | return ret0 144 | } 145 | 146 | func (_mr *_MockQueryManagerRecorder) Limit(arg0 interface{}) *gomock.Call { 147 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Limit", arg0) 148 | } 149 | 150 | func (_m *MockQueryManager) LogReplay() QueryManager { 151 | ret := _m.ctrl.Call(_m, "LogReplay") 152 | ret0, _ := ret[0].(QueryManager) 153 | return ret0 154 | } 155 | 156 | func (_mr *_MockQueryManagerRecorder) LogReplay() *gomock.Call { 157 | return _mr.mock.ctrl.RecordCall(_mr.mock, "LogReplay") 158 | } 159 | 160 | func (_m *MockQueryManager) MapReduce(job *mgo_v2.MapReduce, result interface{}) (*mgo_v2.MapReduceInfo, error) { 161 | ret := _m.ctrl.Call(_m, "MapReduce", job, result) 162 | ret0, _ := ret[0].(*mgo_v2.MapReduceInfo) 163 | ret1, _ := ret[1].(error) 164 | return ret0, ret1 165 | } 166 | 167 | func (_mr *_MockQueryManagerRecorder) MapReduce(arg0, arg1 interface{}) *gomock.Call { 168 | return _mr.mock.ctrl.RecordCall(_mr.mock, "MapReduce", arg0, arg1) 169 | } 170 | 171 | func (_m *MockQueryManager) One(result interface{}) error { 172 | ret := _m.ctrl.Call(_m, "One", result) 173 | ret0, _ := ret[0].(error) 174 | return ret0 175 | } 176 | 177 | func (_mr *_MockQueryManagerRecorder) One(arg0 interface{}) *gomock.Call { 178 | return _mr.mock.ctrl.RecordCall(_mr.mock, "One", arg0) 179 | } 180 | 181 | func (_m *MockQueryManager) Prefetch(p float64) QueryManager { 182 | ret := _m.ctrl.Call(_m, "Prefetch", p) 183 | ret0, _ := ret[0].(QueryManager) 184 | return ret0 185 | } 186 | 187 | func (_mr *_MockQueryManagerRecorder) Prefetch(arg0 interface{}) *gomock.Call { 188 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Prefetch", arg0) 189 | } 190 | 191 | func (_m *MockQueryManager) Select(selector interface{}) QueryManager { 192 | ret := _m.ctrl.Call(_m, "Select", selector) 193 | ret0, _ := ret[0].(QueryManager) 194 | return ret0 195 | } 196 | 197 | func (_mr *_MockQueryManagerRecorder) Select(arg0 interface{}) *gomock.Call { 198 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Select", arg0) 199 | } 200 | 201 | func (_m *MockQueryManager) SetMaxScan(n int) QueryManager { 202 | ret := _m.ctrl.Call(_m, "SetMaxScan", n) 203 | ret0, _ := ret[0].(QueryManager) 204 | return ret0 205 | } 206 | 207 | func (_mr *_MockQueryManagerRecorder) SetMaxScan(arg0 interface{}) *gomock.Call { 208 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetMaxScan", arg0) 209 | } 210 | 211 | func (_m *MockQueryManager) SetMaxTime(d time.Duration) QueryManager { 212 | ret := _m.ctrl.Call(_m, "SetMaxTime", d) 213 | ret0, _ := ret[0].(QueryManager) 214 | return ret0 215 | } 216 | 217 | func (_mr *_MockQueryManagerRecorder) SetMaxTime(arg0 interface{}) *gomock.Call { 218 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetMaxTime", arg0) 219 | } 220 | 221 | func (_m *MockQueryManager) Skip(n int) QueryManager { 222 | ret := _m.ctrl.Call(_m, "Skip", n) 223 | ret0, _ := ret[0].(QueryManager) 224 | return ret0 225 | } 226 | 227 | func (_mr *_MockQueryManagerRecorder) Skip(arg0 interface{}) *gomock.Call { 228 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Skip", arg0) 229 | } 230 | 231 | func (_m *MockQueryManager) Snapshot() QueryManager { 232 | ret := _m.ctrl.Call(_m, "Snapshot") 233 | ret0, _ := ret[0].(QueryManager) 234 | return ret0 235 | } 236 | 237 | func (_mr *_MockQueryManagerRecorder) Snapshot() *gomock.Call { 238 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Snapshot") 239 | } 240 | 241 | func (_m *MockQueryManager) Sort(fields ...string) QueryManager { 242 | _s := []interface{}{} 243 | for _, _x := range fields { 244 | _s = append(_s, _x) 245 | } 246 | ret := _m.ctrl.Call(_m, "Sort", _s...) 247 | ret0, _ := ret[0].(QueryManager) 248 | return ret0 249 | } 250 | 251 | func (_mr *_MockQueryManagerRecorder) Sort(arg0 ...interface{}) *gomock.Call { 252 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Sort", arg0...) 253 | } 254 | 255 | func (_m *MockQueryManager) Tail(timeout time.Duration) IterManager { 256 | ret := _m.ctrl.Call(_m, "Tail", timeout) 257 | ret0, _ := ret[0].(IterManager) 258 | return ret0 259 | } 260 | 261 | func (_mr *_MockQueryManagerRecorder) Tail(arg0 interface{}) *gomock.Call { 262 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Tail", arg0) 263 | } 264 | -------------------------------------------------------------------------------- /pmgomock/session.go: -------------------------------------------------------------------------------- 1 | // Automatically generated by MockGen. DO NOT EDIT! 2 | // Source: /home/karl/golang/src/github.com/percona/pmgo/session.go 3 | 4 | package pmgomock 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | . "github.com/percona/pmgo" 9 | mgo_v2 "gopkg.in/mgo.v2" 10 | bson "gopkg.in/mgo.v2/bson" 11 | time "time" 12 | ) 13 | 14 | // Mock of SessionManager interface 15 | type MockSessionManager struct { 16 | ctrl *gomock.Controller 17 | recorder *_MockSessionManagerRecorder 18 | } 19 | 20 | // Recorder for MockSessionManager (not exported) 21 | type _MockSessionManagerRecorder struct { 22 | mock *MockSessionManager 23 | } 24 | 25 | func NewMockSessionManager(ctrl *gomock.Controller) *MockSessionManager { 26 | mock := &MockSessionManager{ctrl: ctrl} 27 | mock.recorder = &_MockSessionManagerRecorder{mock} 28 | return mock 29 | } 30 | 31 | func (_m *MockSessionManager) EXPECT() *_MockSessionManagerRecorder { 32 | return _m.recorder 33 | } 34 | 35 | func (_m *MockSessionManager) BuildInfo() (mgo_v2.BuildInfo, error) { 36 | ret := _m.ctrl.Call(_m, "BuildInfo") 37 | ret0, _ := ret[0].(mgo_v2.BuildInfo) 38 | ret1, _ := ret[1].(error) 39 | return ret0, ret1 40 | } 41 | 42 | func (_mr *_MockSessionManagerRecorder) BuildInfo() *gomock.Call { 43 | return _mr.mock.ctrl.RecordCall(_mr.mock, "BuildInfo") 44 | } 45 | 46 | func (_m *MockSessionManager) Clone() SessionManager { 47 | ret := _m.ctrl.Call(_m, "Clone") 48 | ret0, _ := ret[0].(SessionManager) 49 | return ret0 50 | } 51 | 52 | func (_mr *_MockSessionManagerRecorder) Clone() *gomock.Call { 53 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Clone") 54 | } 55 | 56 | func (_m *MockSessionManager) Close() { 57 | _m.ctrl.Call(_m, "Close") 58 | } 59 | 60 | func (_mr *_MockSessionManagerRecorder) Close() *gomock.Call { 61 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Close") 62 | } 63 | 64 | func (_m *MockSessionManager) Copy() SessionManager { 65 | ret := _m.ctrl.Call(_m, "Copy") 66 | ret0, _ := ret[0].(SessionManager) 67 | return ret0 68 | } 69 | 70 | func (_mr *_MockSessionManagerRecorder) Copy() *gomock.Call { 71 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Copy") 72 | } 73 | 74 | func (_m *MockSessionManager) DB(name string) DatabaseManager { 75 | ret := _m.ctrl.Call(_m, "DB", name) 76 | ret0, _ := ret[0].(DatabaseManager) 77 | return ret0 78 | } 79 | 80 | func (_mr *_MockSessionManagerRecorder) DB(arg0 interface{}) *gomock.Call { 81 | return _mr.mock.ctrl.RecordCall(_mr.mock, "DB", arg0) 82 | } 83 | 84 | func (_m *MockSessionManager) DatabaseNames() ([]string, error) { 85 | ret := _m.ctrl.Call(_m, "DatabaseNames") 86 | ret0, _ := ret[0].([]string) 87 | ret1, _ := ret[1].(error) 88 | return ret0, ret1 89 | } 90 | 91 | func (_mr *_MockSessionManagerRecorder) DatabaseNames() *gomock.Call { 92 | return _mr.mock.ctrl.RecordCall(_mr.mock, "DatabaseNames") 93 | } 94 | 95 | func (_m *MockSessionManager) EnsureSafe(safe *mgo_v2.Safe) { 96 | _m.ctrl.Call(_m, "EnsureSafe", safe) 97 | } 98 | 99 | func (_mr *_MockSessionManagerRecorder) EnsureSafe(arg0 interface{}) *gomock.Call { 100 | return _mr.mock.ctrl.RecordCall(_mr.mock, "EnsureSafe", arg0) 101 | } 102 | 103 | func (_m *MockSessionManager) FindRef(ref *mgo_v2.DBRef) QueryManager { 104 | ret := _m.ctrl.Call(_m, "FindRef", ref) 105 | ret0, _ := ret[0].(QueryManager) 106 | return ret0 107 | } 108 | 109 | func (_mr *_MockSessionManagerRecorder) FindRef(arg0 interface{}) *gomock.Call { 110 | return _mr.mock.ctrl.RecordCall(_mr.mock, "FindRef", arg0) 111 | } 112 | 113 | func (_m *MockSessionManager) Fsync(async bool) error { 114 | ret := _m.ctrl.Call(_m, "Fsync", async) 115 | ret0, _ := ret[0].(error) 116 | return ret0 117 | } 118 | 119 | func (_mr *_MockSessionManagerRecorder) Fsync(arg0 interface{}) *gomock.Call { 120 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Fsync", arg0) 121 | } 122 | 123 | func (_m *MockSessionManager) FsyncLock() error { 124 | ret := _m.ctrl.Call(_m, "FsyncLock") 125 | ret0, _ := ret[0].(error) 126 | return ret0 127 | } 128 | 129 | func (_mr *_MockSessionManagerRecorder) FsyncLock() *gomock.Call { 130 | return _mr.mock.ctrl.RecordCall(_mr.mock, "FsyncLock") 131 | } 132 | 133 | func (_m *MockSessionManager) FsyncUnlock() error { 134 | ret := _m.ctrl.Call(_m, "FsyncUnlock") 135 | ret0, _ := ret[0].(error) 136 | return ret0 137 | } 138 | 139 | func (_mr *_MockSessionManagerRecorder) FsyncUnlock() *gomock.Call { 140 | return _mr.mock.ctrl.RecordCall(_mr.mock, "FsyncUnlock") 141 | } 142 | 143 | func (_m *MockSessionManager) LiveServers() []string { 144 | ret := _m.ctrl.Call(_m, "LiveServers") 145 | ret0, _ := ret[0].([]string) 146 | return ret0 147 | } 148 | 149 | func (_mr *_MockSessionManagerRecorder) LiveServers() *gomock.Call { 150 | return _mr.mock.ctrl.RecordCall(_mr.mock, "LiveServers") 151 | } 152 | 153 | func (_m *MockSessionManager) Login(cred *mgo_v2.Credential) error { 154 | ret := _m.ctrl.Call(_m, "Login", cred) 155 | ret0, _ := ret[0].(error) 156 | return ret0 157 | } 158 | 159 | func (_mr *_MockSessionManagerRecorder) Login(arg0 interface{}) *gomock.Call { 160 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Login", arg0) 161 | } 162 | 163 | func (_m *MockSessionManager) LogoutAll() { 164 | _m.ctrl.Call(_m, "LogoutAll") 165 | } 166 | 167 | func (_mr *_MockSessionManagerRecorder) LogoutAll() *gomock.Call { 168 | return _mr.mock.ctrl.RecordCall(_mr.mock, "LogoutAll") 169 | } 170 | 171 | func (_m *MockSessionManager) Mode() mgo_v2.Mode { 172 | ret := _m.ctrl.Call(_m, "Mode") 173 | ret0, _ := ret[0].(mgo_v2.Mode) 174 | return ret0 175 | } 176 | 177 | func (_mr *_MockSessionManagerRecorder) Mode() *gomock.Call { 178 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Mode") 179 | } 180 | 181 | func (_m *MockSessionManager) New() SessionManager { 182 | ret := _m.ctrl.Call(_m, "New") 183 | ret0, _ := ret[0].(SessionManager) 184 | return ret0 185 | } 186 | 187 | func (_mr *_MockSessionManagerRecorder) New() *gomock.Call { 188 | return _mr.mock.ctrl.RecordCall(_mr.mock, "New") 189 | } 190 | 191 | func (_m *MockSessionManager) Ping() error { 192 | ret := _m.ctrl.Call(_m, "Ping") 193 | ret0, _ := ret[0].(error) 194 | return ret0 195 | } 196 | 197 | func (_mr *_MockSessionManagerRecorder) Ping() *gomock.Call { 198 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Ping") 199 | } 200 | 201 | func (_m *MockSessionManager) Refresh() { 202 | _m.ctrl.Call(_m, "Refresh") 203 | } 204 | 205 | func (_mr *_MockSessionManagerRecorder) Refresh() *gomock.Call { 206 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Refresh") 207 | } 208 | 209 | func (_m *MockSessionManager) ResetIndexCache() { 210 | _m.ctrl.Call(_m, "ResetIndexCache") 211 | } 212 | 213 | func (_mr *_MockSessionManagerRecorder) ResetIndexCache() *gomock.Call { 214 | return _mr.mock.ctrl.RecordCall(_mr.mock, "ResetIndexCache") 215 | } 216 | 217 | func (_m *MockSessionManager) Run(cmd interface{}, result interface{}) error { 218 | ret := _m.ctrl.Call(_m, "Run", cmd, result) 219 | ret0, _ := ret[0].(error) 220 | return ret0 221 | } 222 | 223 | func (_mr *_MockSessionManagerRecorder) Run(arg0, arg1 interface{}) *gomock.Call { 224 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Run", arg0, arg1) 225 | } 226 | 227 | func (_m *MockSessionManager) Safe() *mgo_v2.Safe { 228 | ret := _m.ctrl.Call(_m, "Safe") 229 | ret0, _ := ret[0].(*mgo_v2.Safe) 230 | return ret0 231 | } 232 | 233 | func (_mr *_MockSessionManagerRecorder) Safe() *gomock.Call { 234 | return _mr.mock.ctrl.RecordCall(_mr.mock, "Safe") 235 | } 236 | 237 | func (_m *MockSessionManager) SelectServers(tags ...bson.D) { 238 | _s := []interface{}{} 239 | for _, _x := range tags { 240 | _s = append(_s, _x) 241 | } 242 | _m.ctrl.Call(_m, "SelectServers", _s...) 243 | } 244 | 245 | func (_mr *_MockSessionManagerRecorder) SelectServers(arg0 ...interface{}) *gomock.Call { 246 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SelectServers", arg0...) 247 | } 248 | 249 | func (_m *MockSessionManager) SetBatch(n int) { 250 | _m.ctrl.Call(_m, "SetBatch", n) 251 | } 252 | 253 | func (_mr *_MockSessionManagerRecorder) SetBatch(arg0 interface{}) *gomock.Call { 254 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetBatch", arg0) 255 | } 256 | 257 | func (_m *MockSessionManager) SetBypassValidation(bypass bool) { 258 | _m.ctrl.Call(_m, "SetBypassValidation", bypass) 259 | } 260 | 261 | func (_mr *_MockSessionManagerRecorder) SetBypassValidation(arg0 interface{}) *gomock.Call { 262 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetBypassValidation", arg0) 263 | } 264 | 265 | func (_m *MockSessionManager) SetCursorTimeout(d time.Duration) { 266 | _m.ctrl.Call(_m, "SetCursorTimeout", d) 267 | } 268 | 269 | func (_mr *_MockSessionManagerRecorder) SetCursorTimeout(arg0 interface{}) *gomock.Call { 270 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetCursorTimeout", arg0) 271 | } 272 | 273 | func (_m *MockSessionManager) SetMode(consistency mgo_v2.Mode, refresh bool) { 274 | _m.ctrl.Call(_m, "SetMode", consistency, refresh) 275 | } 276 | 277 | func (_mr *_MockSessionManagerRecorder) SetMode(arg0, arg1 interface{}) *gomock.Call { 278 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetMode", arg0, arg1) 279 | } 280 | 281 | func (_m *MockSessionManager) SetPoolLimit(limit int) { 282 | _m.ctrl.Call(_m, "SetPoolLimit", limit) 283 | } 284 | 285 | func (_mr *_MockSessionManagerRecorder) SetPoolLimit(arg0 interface{}) *gomock.Call { 286 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetPoolLimit", arg0) 287 | } 288 | 289 | func (_m *MockSessionManager) SetPrefetch(p float64) { 290 | _m.ctrl.Call(_m, "SetPrefetch", p) 291 | } 292 | 293 | func (_mr *_MockSessionManagerRecorder) SetPrefetch(arg0 interface{}) *gomock.Call { 294 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetPrefetch", arg0) 295 | } 296 | 297 | func (_m *MockSessionManager) SetSafe(safe *mgo_v2.Safe) { 298 | _m.ctrl.Call(_m, "SetSafe", safe) 299 | } 300 | 301 | func (_mr *_MockSessionManagerRecorder) SetSafe(arg0 interface{}) *gomock.Call { 302 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetSafe", arg0) 303 | } 304 | 305 | func (_m *MockSessionManager) SetSocketTimeout(d time.Duration) { 306 | _m.ctrl.Call(_m, "SetSocketTimeout", d) 307 | } 308 | 309 | func (_mr *_MockSessionManagerRecorder) SetSocketTimeout(arg0 interface{}) *gomock.Call { 310 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetSocketTimeout", arg0) 311 | } 312 | 313 | func (_m *MockSessionManager) SetSyncTimeout(d time.Duration) { 314 | _m.ctrl.Call(_m, "SetSyncTimeout", d) 315 | } 316 | 317 | func (_mr *_MockSessionManagerRecorder) SetSyncTimeout(arg0 interface{}) *gomock.Call { 318 | return _mr.mock.ctrl.RecordCall(_mr.mock, "SetSyncTimeout", arg0) 319 | } 320 | -------------------------------------------------------------------------------- /query.go: -------------------------------------------------------------------------------- 1 | package pmgo 2 | 3 | import ( 4 | "time" 5 | 6 | mgo "gopkg.in/mgo.v2" 7 | ) 8 | 9 | type QueryManager interface { 10 | All(result interface{}) error 11 | Apply(change mgo.Change, result interface{}) (info *mgo.ChangeInfo, err error) 12 | Batch(n int) QueryManager 13 | Comment(comment string) QueryManager 14 | Count() (n int, err error) 15 | Distinct(key string, result interface{}) error 16 | Explain(result interface{}) error 17 | For(result interface{}, f func() error) error 18 | Hint(indexKey ...string) QueryManager 19 | Iter() *mgo.Iter 20 | Limit(n int) QueryManager 21 | LogReplay() QueryManager 22 | MapReduce(job *mgo.MapReduce, result interface{}) (info *mgo.MapReduceInfo, err error) 23 | One(result interface{}) (err error) 24 | Prefetch(p float64) QueryManager 25 | Select(selector interface{}) QueryManager 26 | SetMaxScan(n int) QueryManager 27 | SetMaxTime(d time.Duration) QueryManager 28 | Skip(n int) QueryManager 29 | Snapshot() QueryManager 30 | Sort(fields ...string) QueryManager 31 | Tail(timeout time.Duration) IterManager 32 | } 33 | type Query struct { 34 | query *mgo.Query 35 | } 36 | 37 | func NewQueryManager(q *mgo.Query) QueryManager { 38 | return &Query{ 39 | query: q, 40 | } 41 | } 42 | 43 | func (q *Query) All(result interface{}) error { 44 | return q.query.All(result) 45 | } 46 | 47 | func (q *Query) Apply(change mgo.Change, result interface{}) (info *mgo.ChangeInfo, err error) { 48 | return q.query.Apply(change, result) 49 | } 50 | 51 | func (q *Query) Batch(n int) QueryManager { 52 | return &Query{q.query.Batch(n)} 53 | } 54 | 55 | func (q *Query) Comment(comment string) QueryManager { 56 | return &Query{q.query.Comment(comment)} 57 | } 58 | 59 | func (q *Query) Count() (int, error) { 60 | return q.query.Count() 61 | } 62 | 63 | func (q *Query) Distinct(key string, result interface{}) error { 64 | return q.query.Distinct(key, result) 65 | } 66 | 67 | func (q *Query) Explain(result interface{}) error { 68 | return q.query.Explain(result) 69 | } 70 | 71 | func (q *Query) For(result interface{}, f func() error) error { 72 | return q.query.For(result, f) 73 | } 74 | 75 | func (q *Query) Hint(indexKey ...string) QueryManager { 76 | return &Query{q.query.Hint(indexKey...)} 77 | } 78 | 79 | func (q *Query) Iter() *mgo.Iter { 80 | return q.query.Iter() 81 | } 82 | 83 | func (q *Query) Limit(n int) QueryManager { 84 | return &Query{q.query.Limit(n)} 85 | } 86 | 87 | func (q *Query) LogReplay() QueryManager { 88 | return &Query{q.query.LogReplay()} 89 | } 90 | 91 | func (q *Query) MapReduce(job *mgo.MapReduce, result interface{}) (info *mgo.MapReduceInfo, err error) { 92 | return q.query.MapReduce(job, result) 93 | } 94 | 95 | func (q *Query) One(result interface{}) error { 96 | return q.query.One(result) 97 | } 98 | 99 | func (q *Query) Prefetch(p float64) QueryManager { 100 | return &Query{q.query.Prefetch(p)} 101 | } 102 | func (q *Query) Select(selector interface{}) QueryManager { 103 | return &Query{q.query.Select(selector)} 104 | } 105 | 106 | func (q *Query) SetMaxScan(n int) QueryManager { 107 | return &Query{q.query.SetMaxScan(n)} 108 | } 109 | 110 | func (q *Query) SetMaxTime(d time.Duration) QueryManager { 111 | return &Query{q.query.SetMaxTime(d)} 112 | } 113 | 114 | func (q *Query) Skip(n int) QueryManager { 115 | return &Query{q.query.Skip(n)} 116 | } 117 | 118 | func (q *Query) Snapshot() QueryManager { 119 | return &Query{q.query.Snapshot()} 120 | } 121 | 122 | func (q *Query) Sort(fields ...string) QueryManager { 123 | return &Query{q.query.Sort(fields...)} 124 | } 125 | 126 | func (q *Query) Tail(timeout time.Duration) IterManager { 127 | return q.query.Tail(timeout) 128 | } 129 | -------------------------------------------------------------------------------- /session.go: -------------------------------------------------------------------------------- 1 | package pmgo 2 | 3 | import ( 4 | "time" 5 | 6 | mgo "gopkg.in/mgo.v2" 7 | "gopkg.in/mgo.v2/bson" 8 | ) 9 | 10 | type SessionManager interface { 11 | BuildInfo() (info mgo.BuildInfo, err error) 12 | Clone() SessionManager 13 | Close() 14 | Copy() SessionManager 15 | DB(name string) DatabaseManager 16 | DatabaseNames() (names []string, err error) 17 | EnsureSafe(safe *mgo.Safe) 18 | FindRef(ref *mgo.DBRef) QueryManager 19 | Fsync(async bool) error 20 | FsyncLock() error 21 | FsyncUnlock() error 22 | LiveServers() (addrs []string) 23 | Login(cred *mgo.Credential) error 24 | LogoutAll() 25 | Mode() mgo.Mode 26 | New() SessionManager 27 | Ping() error 28 | Refresh() 29 | ResetIndexCache() 30 | Run(cmd interface{}, result interface{}) error 31 | Safe() (safe *mgo.Safe) 32 | SelectServers(tags ...bson.D) 33 | SetBatch(n int) 34 | SetBypassValidation(bypass bool) 35 | SetCursorTimeout(d time.Duration) 36 | SetMode(consistency mgo.Mode, refresh bool) 37 | SetPoolLimit(limit int) 38 | SetPrefetch(p float64) 39 | SetSafe(safe *mgo.Safe) 40 | SetSocketTimeout(d time.Duration) 41 | SetSyncTimeout(d time.Duration) 42 | } 43 | 44 | type Session struct { 45 | session *mgo.Session 46 | } 47 | 48 | // This methos allows to use mgo's dbtest.DBServer in pmgo tests. 49 | // Example: 50 | // var Server dbtest.DBServer 51 | // tempDir, _ := ioutil.TempDir("", "testing") 52 | // Server.SetPath(tempDir) 53 | // session := NewSessionManager(Server.Session()) 54 | func NewSessionManager(s *mgo.Session) SessionManager { 55 | return &Session{ 56 | session: s, 57 | } 58 | } 59 | 60 | func (s *Session) BuildInfo() (info mgo.BuildInfo, err error) { 61 | return s.session.BuildInfo() 62 | } 63 | 64 | func (s *Session) Close() { 65 | s.session.Close() 66 | } 67 | 68 | func (s *Session) Clone() SessionManager { 69 | return &Session{ 70 | session: s.session.Clone(), 71 | } 72 | } 73 | 74 | func (s *Session) Copy() SessionManager { 75 | return &Session{ 76 | session: s.session.Copy(), 77 | } 78 | } 79 | 80 | func (s *Session) DB(name string) DatabaseManager { 81 | d := &Database{ 82 | db: s.session.DB(name), 83 | } 84 | return d 85 | } 86 | 87 | func (s *Session) DatabaseNames() (names []string, err error) { 88 | return s.session.DatabaseNames() 89 | } 90 | 91 | func (s *Session) EnsureSafe(safe *mgo.Safe) { 92 | s.session.EnsureSafe(safe) 93 | } 94 | 95 | func (s *Session) FindRef(ref *mgo.DBRef) QueryManager { 96 | return &Query{s.session.FindRef(ref)} 97 | } 98 | 99 | func (s *Session) Fsync(async bool) error { 100 | return s.session.Fsync(async) 101 | } 102 | 103 | func (s *Session) FsyncLock() error { 104 | return s.session.FsyncLock() 105 | } 106 | 107 | func (s *Session) FsyncUnlock() error { 108 | return s.session.FsyncUnlock() 109 | } 110 | 111 | func (s *Session) LiveServers() (addrs []string) { 112 | return s.session.LiveServers() 113 | } 114 | 115 | func (s *Session) Login(cred *mgo.Credential) error { 116 | return s.session.Login(cred) 117 | } 118 | 119 | func (s *Session) LogoutAll() { 120 | s.session.LogoutAll() 121 | } 122 | 123 | func (s *Session) Mode() mgo.Mode { 124 | return s.session.Mode() 125 | } 126 | 127 | func (s *Session) New() SessionManager { 128 | return &Session{s.session.New()} 129 | } 130 | 131 | func (s *Session) Run(cmd interface{}, result interface{}) error { 132 | return s.session.Run(cmd, result) 133 | } 134 | 135 | func (s *Session) Safe() (safe *mgo.Safe) { 136 | return s.session.Safe() 137 | } 138 | 139 | func (s *Session) SelectServers(tags ...bson.D) { 140 | s.session.SelectServers(tags...) 141 | } 142 | 143 | func (s *Session) SetBatch(n int) { 144 | s.session.SetBatch(n) 145 | } 146 | 147 | func (s *Session) SetBypassValidation(bypass bool) { 148 | s.session.SetBypassValidation(bypass) 149 | } 150 | 151 | func (s *Session) SetCursorTimeout(d time.Duration) { 152 | s.session.SetCursorTimeout(d) 153 | } 154 | 155 | func (s *Session) Ping() error { 156 | return s.session.Ping() 157 | } 158 | 159 | func (s *Session) Refresh() { 160 | s.session.Refresh() 161 | } 162 | 163 | func (s *Session) ResetIndexCache() { 164 | s.session.ResetIndexCache() 165 | } 166 | 167 | func (s *Session) SetMode(consistency mgo.Mode, refresh bool) { 168 | s.session.SetMode(consistency, refresh) 169 | } 170 | func (s *Session) SetPoolLimit(limit int) { 171 | s.session.SetPoolLimit(limit) 172 | } 173 | 174 | func (s *Session) SetPrefetch(p float64) { 175 | s.session.SetPrefetch(p) 176 | } 177 | 178 | func (s *Session) SetSafe(safe *mgo.Safe) { 179 | s.session.SetSafe(safe) 180 | } 181 | 182 | func (s *Session) SetSocketTimeout(d time.Duration) { 183 | s.session.SetSocketTimeout(d) 184 | } 185 | func (s *Session) SetSyncTimeout(d time.Duration) { 186 | s.session.SetSyncTimeout(d) 187 | } 188 | --------------------------------------------------------------------------------