test

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConfigFile is the name of the config file for a server.
	ConfigFile = "dendrite.yaml"
	// ServerKeyFile is the name of the file holding the matrix server private key.
	ServerKeyFile = "server_key.pem"
	// TLSCertFile is the name of the file holding the TLS certificate used for federation.
	TLSCertFile = "tls_cert.pem"
	// TLSKeyFile is the name of the file holding the TLS key used for federation.
	TLSKeyFile = "tls_key.pem"
	// MediaDir is the name of the directory used to store media.
	MediaDir = "media"
)

Variables

This section is empty.

Functions

func CanonicalJSONInput

func CanonicalJSONInput(jsonData []string) []string

CanonicalJSONInput canonicalises a slice of JSON strings Useful for test input

func CreateBackgroundCommand

func CreateBackgroundCommand(command string, args []string) (*exec.Cmd, chan error)

CreateBackgroundCommand creates an executable command The Cmd being executed is returned. A channel is also returned, which will have any termination errors sent down it, followed immediately by the channel being closed.

func CreateDatabase

func CreateDatabase(command string, args []string, database string) error

CreateDatabase creates a new database, dropping it first if it exists

func Defaulting

func Defaulting(value, defaultValue string) string

Defaulting allows assignment of string variables with a fallback default value Useful for use with os.Getenv() for example

func InitDatabase

func InitDatabase(postgresDatabase, postgresContainerName string, databases []string)

InitDatabase creates the database and config file needed for the server to run

func ListenAndServe

func ListenAndServe(t *testing.T, router http.Handler, useTLS bool) (apiURL string, cancel func())

ListenAndServe will listen on a random high-numbered port and attach the given router. Returns the base URL to send requests to. Call `cancel` to shutdown the server, which will block until it has closed.

func MakeConfig

func MakeConfig(configDir, kafkaURI, database, host string, startPort int) (*config.Dendrite, int, error)

MakeConfig makes a config suitable for running integration tests. Generates new matrix and TLS keys for the server.

func NewMatrixKey

func NewMatrixKey(matrixKeyPath string) (err error)

NewMatrixKey generates a new ed25519 matrix server key and writes it to a file.

func NewTLSKey

func NewTLSKey(tlsKeyPath, tlsCertPath string) error

NewTLSKey generates a new RSA TLS key and certificate and writes it to a file.

func NewTLSKeyWithAuthority added in v0.6.1

func NewTLSKeyWithAuthority(serverName, tlsKeyPath, tlsCertPath, authorityKeyPath, authorityCertPath string) error

func StartProxy

func StartProxy(bindAddr string, cfg *config.Dendrite) (*exec.Cmd, chan error)

StartProxy creates a reverse proxy

func UnsortedStringSliceEqual

func UnsortedStringSliceEqual(first, second []string) bool

UnsortedStringSliceEqual returns true if the slices have same length & elements. Does not modify the given slice.

func WriteConfig

func WriteConfig(cfg *config.Dendrite, configDir string) error

WriteConfig writes the config file to the directory.

Types

type KafkaExecutor

type KafkaExecutor struct {
	// The location of Zookeeper. Typically this is `localhost:2181`.
	ZookeeperURI string
	// The directory where Kafka is installed to. Used to locate kafka scripts.
	KafkaDirectory string
	// The location of the Kafka logs. Typically this is `localhost:9092`.
	KafkaURI string
	// Where stdout and stderr should be written to. Typically this is `os.Stderr`.
	OutputWriter io.Writer
}

KafkaExecutor executes kafka scripts.

func (*KafkaExecutor) CreateTopic

func (e *KafkaExecutor) CreateTopic(topic string) error

CreateTopic creates a new kafka topic. This is created with a single partition.

func (*KafkaExecutor) DeleteTopic

func (e *KafkaExecutor) DeleteTopic(topic string) error

DeleteTopic deletes a given kafka topic if it exists.

func (*KafkaExecutor) WriteToTopic

func (e *KafkaExecutor) WriteToTopic(topic string, data []string) error

WriteToTopic writes data to a kafka topic.

type LastRequestErr

type LastRequestErr struct {
	sync.Mutex
	Err error
}

LastRequestErr is a synchronised error wrapper Useful for obtaining the last error from a set of requests

func (*LastRequestErr) Get

func (r *LastRequestErr) Get() error

Get gets the error

func (*LastRequestErr) Set

func (r *LastRequestErr) Set(err error)

Set sets the error

type NopJSONVerifier

type NopJSONVerifier struct {
}

NopJSONVerifier is a JSONVerifier that verifies nothing and returns no errors.

func (*NopJSONVerifier) VerifyJSONs

type Request

type Request struct {
	Req              *http.Request
	WantedBody       string
	WantedStatusCode int
	LastErr          *LastRequestErr
}

Request contains the information necessary to issue a request and test its result

func (*Request) Do

func (r *Request) Do() (err error)

Do issues a request and checks the status code and body of the response

func (*Request) DoUntilSuccess

func (r *Request) DoUntilSuccess(done chan error)

DoUntilSuccess blocks and repeats the same request until the response returns the desired status code and body. It then closes the given channel and returns.

func (*Request) Run

func (r *Request) Run(label string, timeout time.Duration, serverCmdChan chan error)

Run repeatedly issues a request until success, error or a timeout is reached

Jump to

Keyboard shortcuts

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