dbtest

package
v0.0.13 Latest Latest
Warning

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

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

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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, publicity uint8) uint32

CreatePoll adds a poll to the database. The poll has Salt 42, MaxNbRounds 3, and 2 alternatives 'No' and 'Yes' (in that order). The poll is deleted by Close.

func (*Env) CreatePollWith added in v0.0.4

func (self *Env) CreatePollWith(title string, admin uint32, publicity uint8,
	alternatives []string) (pollId uint32)

CreatePoll adds a poll to the database. The poll has Salt 42, MaxNbRounds 3, 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. The user has name ' Test ' (mind the spaces), email address 'test@example.test', and password 'XYZ'. It is deleted by Close.

func (*Env) CreateUserWith added in v0.0.4

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

CreateUser adds a user to the database. The user has name ' Test<salt> ' (mind the spaces), email address 'test<salt>@example.test', and password 'XYZ'. 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 done if Error is not nil.

func (*Env) Must added in v0.0.4

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

func (*Env) NextRound added in v0.0.4

func (self *Env) NextRound(pollId uint32)

NextRound advances a poll to the next round.

func (*Env) QuietExec added in v0.0.13

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 added in v0.0.4

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.

Jump to

Keyboard shortcuts

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