dbtest

package
v0.0.0-...-1d6169c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2024 License: Apache-2.0, BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBServer

type DBServer struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

DBServer controls a MongoDB server process to be used within test suites.

The test server is started when Client is called the first time and should remain running for the duration of all tests, with the Wipe method being called between tests (before each of them) to clear stored data. After all tests are done, the Stop method should be called to stop the test server.

Before the DBServer is used the SetPath method must be called to define the location for the database files to be stored.

func (*DBServer) CTX

func (dbs *DBServer) CTX() context.Context

func (*DBServer) Client

func (dbs *DBServer) Client() *mongo.Client

Client returns a new client to the server. The returned client must be disconnected after the tests are finished.

The first call to Client will start the DBServer.

func (*DBServer) SetPath

func (dbs *DBServer) SetPath(dbpath string)

SetPath defines the path to the directory where the database files will be stored if it is started. The directory path itself is not created or removed by the test helper.

func (*DBServer) SetRegistry

func (dbs *DBServer) SetRegistry(reg *bsoncodec.Registry)

func (*DBServer) SetTimeout

func (dbs *DBServer) SetTimeout(timeout int)

func (*DBServer) Stop

func (dbs *DBServer) Stop()

Stop stops the test server process, if it is running.

It's okay to call Stop multiple times. After the test server is stopped it cannot be restarted.

All database clients must be closed before or while the Stop method is running. Otherwise Stop will panic after a timeout informing that there is a client leak.

func (*DBServer) Wipe

func (dbs *DBServer) Wipe()

Wipe drops all created databases and their data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL