dbtest

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package dbtest allows to temporarily add test data to the database.

Index

Constants

View Source
const (
	UserPasswd = "XYZ"

	PollSalt        = 42
	PollMaxNbRounds = 4

	// ImpossibleUserName is a user name which is guaranteed to not exist.
	ImpossibleUserName = "  "
)

Variables

View Source
var UserPasswdHash []byte

UserPasswdHash contains the hash of UserPasswd.

Functions

func UserEmailWith

func UserEmailWith(salt string) string

UserNameWith returns the email address of the user created by CreateUserWith with the same salt.

func UserNameWith

func UserNameWith(salt string) string

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

func (self *Env) CreatePoll(title string, admin uint32, electorate db.Electorate) uint32

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 PollSalt, MaxNbRounds PollMaxNbRounds, and the alternatives given as arguments. All alternatives have Cost 1. The poll is deleted by Close.

func (*Env) CreateUser

func (self *Env) CreateUser() uint32

CreateUser adds a user to the database. You should use CreateUserWith instead.

func (*Env) CreateUserWith

func (self *Env) CreateUserWith(salt string) (userId uint32)

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.

func (*Env) Must

func (self *Env) Must(t *testing.T)

Must makes the test fail is some error have happened.

func (*Env) NextRound

func (self *Env) NextRound(pollId uint32)

NextRound advances a poll to the next round.

func (*Env) QuietExec

func (self *Env) QuietExec(query string, args ...interface{})

QuietExec executes the query without returning anything. Like most other Env's methods, the query is not executed if an error previously occured.

func (*Env) Vote

func (self *Env) Vote(pollId uint32, round uint8, userId uint32, alternative uint8)

Vote submits a ballot. If the user does not participate yet in the poll, it is added to the participant. No other check is done.

type WithDB

type WithDB struct {
	DB Env
}

WithDB is a servertest.Test mixin providing a field of type Env.

func (*WithDB) Close

func (self *WithDB) Close()

Close closes the Env field, launching all defered functions.

Jump to

Keyboard shortcuts

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