dbtest

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2020 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Run MongoDB as local process
	LocalProcess = 0
	// Run MongoDB within a docker container
	Docker = 1
)

Constants to define how the DB test instance should be executed

View Source
const (
	StartupState = iota
	PrimaryState
	SecondaryState
	RecoveringState
	FatalState
	Startup2State
	UnknownState
	ArbiterState
	DownState
	RollbackState
	ShunnedState
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name            string   `bson:"_id"`
	Version         int      `bson:"version"`
	ProtocolVersion int      `bson:"protocolVersion,omitempty"`
	Members         []Member `bson:"members"`
}

Code From https://github.com/juju/replicaset To Start MongoDB in replica Set Configuration Config is the document stored in mongodb that defines the servers in the replica set

type DBServer

type DBServer struct {
	// contains filtered or unexported fields
}

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

The test server is started when Session 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) GetContainerIpAddr

func (dbs *DBServer) GetContainerIpAddr() (string, error)

GetContainerIpAddr returns the IP address of the test Mongo instance The client should connect directly on the docker bridge network (such as when the client is also running in a container), then client should connect to port 27017.

func (*DBServer) GetContainerName

func (dbs *DBServer) GetContainerName() string

GetContainerName returns the name of the container, when running the Mongo UT instance in a container.

func (*DBServer) GetHostName

func (dbs *DBServer) GetHostName() string

Returns the host name of the Mongo test instance. If the test instance runs as a container, it returns the IP address of the container. If the test instance runs in the host, returns the host name.

func (*DBServer) Initiate

func (dbs *DBServer) Initiate() error

func (*DBServer) Session

func (dbs *DBServer) Session() *mgo.Session

Session returns a new session to the server. The returned session must be closed after the test is done with it.

The first Session obtained from a DBServer will start it.

func (*DBServer) SessionWithTimeout

func (dbs *DBServer) SessionWithTimeout(timeout time.Duration) *mgo.Session

Session returns a new session to the server. The returned session must be closed after the test is done with it.

The first Session obtained from a DBServer will start it.

func (*DBServer) SetContainerName

func (dbs *DBServer) SetContainerName(containerName string)

SetContainerName sets the name of the docker container when the DB instance is started within a container.

func (*DBServer) SetDebug

func (dbs *DBServer) SetDebug(enableDebug bool)

func (*DBServer) SetExecType

func (dbs *DBServer) SetExecType(execType int)

SetExecType specifies if the DB instance should run locally or as a container.

func (*DBServer) SetExposePort

func (dbs *DBServer) SetExposePort(exposePort bool)

SetExposePort sets whether the container port should be exposed to the host OS.

func (*DBServer) SetNetwork

func (dbs *DBServer) SetNetwork(network string)

SetNetwork sets the name of the docker network to which the UT container should be attached.

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) SetReplicaSetName

func (dbs *DBServer) SetReplicaSetName(rsName string)

SetReplicaSetName sets whether the mongod is started as a replica set

func (*DBServer) SetVersion

func (dbs *DBServer) SetVersion(version string)

SetVersion defines the desired MongoDB version to run within a container. The attribute is ignored when running MongoDB outside a container.

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 sessions must be closed before or while the Stop method is running. Otherwise Stop will panic after a timeout informing that there is a session leak.

func (*DBServer) Wipe

func (dbs *DBServer) Wipe()

Wipe drops all created databases and their data.

The MongoDB server remains running if it was prevoiusly running, or stopped if it was previously stopped.

All database sessions must be closed before or while the Wipe method is running. Otherwise Wipe will panic after a timeout informing that there is a session leak.

type Member

type Member struct {
	// Id is a unique id for a member in a set.
	Id int `bson:"_id"`

	// Address holds the network address of the member,
	// in the form hostname:port.
	Address string `bson:"host"`
}

Member holds configuration information for a replica set member.

See http://docs.mongodb.org/manual/reference/replica-configuration/ for more details

type MemberState

type MemberState int

func (MemberState) String

func (state MemberState) String() string

String returns a string describing the state.

type MemberStatus

type MemberStatus struct {
	// Id holds the replica set id of the member that the status is describing.
	Id int `bson:"_id"`

	// Address holds address of the member that the status is describing.
	Address string `bson:"name"`

	// Self holds whether this is the status for the member that
	// the session is connected to.
	Self bool `bson:"self"`

	// ErrMsg holds the most recent error or status message received
	// from the member.
	ErrMsg string `bson:"errmsg"`

	// Healthy reports whether the member is up. It is true for the
	// member that the request was made to.
	Healthy bool `bson:"health"`

	// State describes the current state of the member.
	State MemberState `bson:"state"`
}

Status holds the status of a replica set member returned from replSetGetStatus.

type Status

type Status struct {
	Name    string         `bson:"set"`
	Members []MemberStatus `bson:"members"`
}

Status holds data about the status of members of the replica set returned from replSetGetStatus

See http://docs.mongodb.org/manual/reference/command/replSetGetStatus/#dbcmd.replSetGetStatus

Jump to

Keyboard shortcuts

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