Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import (
"go.mongodb.org/mongo-driver/mongo/readpref"
)

//go:generate mockgen -source=./database.go -destination=./mocks/database.go -package=mock_colt DatabaseIface
type DatabaseIface interface {
Client() *mongo.Client
Connect(connectionString string, dbName string) error
Ping() error
Disconnect() error
}

type Database struct {
db *mongo.Database
client *mongo.Client
Expand All @@ -35,6 +43,10 @@ func (db *Database) connect(options *options.ClientOptions, dbName string) error
return nil
}

func (db *Database) Client() *mongo.Client {
return db.client
}

func (db *Database) Connect(connectionString string, dbName string) error {
options := options.Client().ApplyURI(connectionString)
err := db.connect(options, dbName)
Expand Down
97 changes: 97 additions & 0 deletions mocks/database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.