Documentation ¶
Overview ¶
Package dbtest allows to temporarily add test data to the database.
Index ¶
- Constants
- func UserEmailWith(salt string) string
- func UserNameWith(salt string) string
- type Env
- func (self *Env) Close()
- func (self *Env) CreatePoll(title string, admin uint32, electorate db.Electorate) uint32
- func (self *Env) CreatePollWith(title string, admin uint32, electorate db.Electorate, alternatives []string) (pollId uint32)
- func (self *Env) CreateUser() uint32
- func (self *Env) CreateUserWith(salt string) (userId uint32)
- func (self *Env) Defer(fct func())
- func (self *Env) Must(t *testing.T)
- func (self *Env) NextRound(pollId uint32)
- func (self *Env) QuietExec(query string, args ...interface{})
- func (self *Env) Vote(pollId uint32, round uint8, userId uint32, alternative uint8)
- type WithDB
Constants ¶
const ( UserPasswd = "XYZ" PollSalt = 42 PollMaxNbRounds = 4 )
Variables ¶
This section is empty.
Functions ¶
func UserEmailWith ¶
UserNameWith returns the email address of the user created by CreateUserWith with the same salt.
func UserNameWith ¶
UserNameWith returns the name of the user created by CreateUserWith with the same salt.
Types ¶
type Env ¶
type Env struct { Error error // contains filtered or unexported fields }
Env provides methods to add temporary test data. It collects functions to remove these data. These functions are called by Close, hence a call to Close must be defered for each Env object.
Env's methods never return errors. Instead, the Error field is updated and checked by all methods (except Close).
func (*Env) Close ¶
func (self *Env) Close()
Close calls all collected functions, in reverse order, even if Error is not nil.
func (*Env) CreatePoll ¶
CreatePoll adds a poll to the database. The poll has Salt PollSalt, MaxNbRounds PollMaxNbRounds, and 2 alternatives 'No' and 'Yes' (in that order). The poll is deleted by Close.
func (*Env) CreatePollWith ¶
func (self *Env) CreatePollWith(title string, admin uint32, electorate db.Electorate, alternatives []string) (pollId uint32)
CreatePoll adds a poll to the database. The poll has Salt 42, MaxNbRounds 4, and the alternatives given as arguments. All alternatives have Cost 1. The poll is deleted by Close.
func (*Env) CreateUser ¶
CreateUser adds a user to the database. The user has name ' Test ' (mind the spaces), email address 'testTest@example.test', and password 'XYZ'. It is deleted by Close.
func (*Env) CreateUserWith ¶
CreateUser adds a user to the database. The user has name as returned by UserNameWith, email address as returned by UserEmailWith, and password is UserPasswd. It is deleted by Close.
func (*Env) Defer ¶
func (self *Env) Defer(fct func())
Defer adds a function to be called by Close. As other Env's method, nothing is added if Error is not nil.