test

package
v0.0.0-...-d450093 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package test contains helper functions to test the other packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmpIntSet

func CmpIntSet(a, b map[int]bool) bool

CmpIntSet returns true, if both sets have the smae entries.

func CmpIntSlice

func CmpIntSlice(a, b []int) bool

CmpIntSlice returns true, if both slices have the same values.

func CmpStrSlice

func CmpStrSlice(a, b []string) bool

CmpStrSlice returns true, if both slices have the same values.

func ExampleData

func ExampleData() map[string]json.RawMessage

ExampleData returns a full database with example data.

func ExpectEqualJSON

func ExpectEqualJSON(t *testing.T, a, b []byte)

ExpectEqualJSON tests, that a and b are the same json elements.

Types

type AutherMock

type AutherMock struct{}

AutherMock implements the autoupdate.Auther interface.

func (*AutherMock) Authenticate

func (a *AutherMock) Authenticate(r *http.Request) (context.Context, error)

Authenticate returns the request context.

type DatastoreMock

type DatastoreMock struct {
	FullData map[string]json.RawMessage

	Err error
	// contains filtered or unexported fields
}

DatastoreMock implements the autoupdate.Datastore interface.

func NewDatastoreMock

func NewDatastoreMock(startID int, closed <-chan struct{}) *DatastoreMock

NewDatastoreMock initializes a DatastoreMock.

func (*DatastoreMock) Change

func (d *DatastoreMock) Change(keys []string)

Change sends an update event for KeysChanged.

func (*DatastoreMock) ChangedKeys

func (d *DatastoreMock) ChangedKeys(from, to int) ([]string, error)

ChangedKeys does nothing...

func (*DatastoreMock) ConfigValue

func (d *DatastoreMock) ConfigValue(key string, value interface{}) error

ConfigValue sets v to the value of config value key.

func (*DatastoreMock) CurrentID

func (d *DatastoreMock) CurrentID() int

CurrentID returns the max id if the mock.

func (*DatastoreMock) Get

func (d *DatastoreMock) Get(collection string, id int, v interface{}) error

Get sets v to the decoded value of collection:id

func (*DatastoreMock) GetAll

func (d *DatastoreMock) GetAll() map[string]json.RawMessage

GetAll returns FullData.

func (*DatastoreMock) GetCollection

func (d *DatastoreMock) GetCollection(collection string) []json.RawMessage

GetCollection gets all elements of one collection.

func (*DatastoreMock) GetMany

func (d *DatastoreMock) GetMany(keys []string) map[string]json.RawMessage

GetMany returns the given keys from FullData.

func (*DatastoreMock) GetModels

func (d *DatastoreMock) GetModels(collection string, ids []int) []json.RawMessage

GetModels returns each element from collection that is in the ids slide.

func (*DatastoreMock) KeysChanged

func (d *DatastoreMock) KeysChanged() ([]string, int, error)

KeysChanged waits for Changes to be called.

func (*DatastoreMock) LowestID

func (d *DatastoreMock) LowestID() int

LowestID returns the max id if the mock.

func (*DatastoreMock) ProjectorData

func (d *DatastoreMock) ProjectorData(ctx context.Context, tid uint64) (uint64, map[int]json.RawMessage, error)

ProjectorData does currently nothing.

type HasPermMock

type HasPermMock struct {
	IsSuperuser bool
	Perms       []string
	Groups      map[int]bool
	Data        map[string]json.RawMessage
}

HasPermMock implements the restricter.HasPermer interface.

func (*HasPermMock) ConfigValue

func (h *HasPermMock) ConfigValue(key string, v interface{}) error

ConfigValue is currently a stub until it is actually needed by the tests

func (*HasPermMock) Get

func (h *HasPermMock) Get(collection string, id int, v interface{}) error

Get tells, if the given user has the ...

func (*HasPermMock) HasPerm

func (h *HasPermMock) HasPerm(_ int, perm string) bool

HasPerm returns true, if the given perm is in the list of Perms.

func (*HasPermMock) InGroups

func (h *HasPermMock) InGroups(_ int, groups []int) bool

InGroups checks if one of the id in groups is also in HasPermMock.Groups

func (*HasPermMock) IsSuperadmin

func (h *HasPermMock) IsSuperadmin(_ int) bool

IsSuperadmin returns, if the user is superadmin.

func (*HasPermMock) UserRequired

func (h *HasPermMock) UserRequired(uid int) []string

UserRequired checks for the given groups.

type ProjectorDataset

type ProjectorDataset struct {
	Name        string
	ElementName string
	Overwrite   map[string]json.RawMessage
	Expected    json.RawMessage
}

ProjectorDataset is a test case.

func ExampleProjector

func ExampleProjector() []ProjectorDataset

ExampleProjector returns test cases.

type RedisMock

type RedisMock struct {
	FD  map[string]json.RawMessage
	Min int
	Max int

	ChangedKeysResult []string
	// contains filtered or unexported fields
}

RedisMock implements the datastore.RedisConn interface.

func NewRedisMock

func NewRedisMock() *RedisMock

NewRedisMock initializes a RedisMock.

func (*RedisMock) ChangedKeys

func (r *RedisMock) ChangedKeys(from, to int) ([]string, error)

ChangedKeys returnes ChangedKeysResult.

func (*RedisMock) Data

func (r *RedisMock) Data(keys []string) (map[string]json.RawMessage, error)

Data returns the keys from FD.

func (*RedisMock) FullData

func (r *RedisMock) FullData() (data map[string]json.RawMessage, max int, min int, err error)

FullData returns the given values.

func (*RedisMock) Send

func (r *RedisMock) Send(value []byte)

Send sends a value that can be received with Update.

func (*RedisMock) Update

func (r *RedisMock) Update(closing <-chan struct{}) ([]byte, error)

Update waits for Send() to be called and returned the send data.

type RequiredUserDataset

type RequiredUserDataset struct {
	Name       string
	Collection string
	Element    json.RawMessage
	ExpectPerm string
	ExpectIDs  map[int]bool
}

RequiredUserDataset is a testcase.

func ExampleRequiredUser

func ExampleRequiredUser() []RequiredUserDataset

ExampleRequiredUser returns testcases to test required users.

type RestrictedDataset

type RestrictedDataset struct {
	Name       string
	UID        int
	Permer     *HasPermMock
	Collection string
	Element    json.RawMessage
	Expected   json.RawMessage
}

RestrictedDataset is a used for a test.

func ExampleRestrictedData

func ExampleRestrictedData() []RestrictedDataset

ExampleRestrictedData returns a list of Data for restricted data tests for an user.

type RestricterMock

type RestricterMock struct {
	Called bool
}

RestricterMock implements the autoupdate.Restrict interface.

func (*RestricterMock) Restrict

func (r *RestricterMock) Restrict(uid int, data map[string]json.RawMessage)

Restrict does nothing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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