Documentation
¶
Index ¶
- Variables
- func Contains[T comparable](haystack []T, needle T) bool
- func Context() (context.Context, context.CancelFunc)
- func DBTestCredentials() database.DBCredentials
- func LoadTestConfig() (conf.Config, error)
- func NewDatabase(ctx context.Context, dbName string) (*database.DB, error)
- func NewDiscardLogger() *logrus.Logger
- func RandomSkylink() skymodules.Skylink
- func SanitizeName(s string) string
- type Tester
- func (t *Tester) Close() error
- func (t *Tester) HealthGET() (api.HealthGET, int, error)
- func (t *Tester) ListServersGET(skylink string) ([]string, int, error)
- func (t *Tester) ListSkylinksGET(server string) ([]string, int, error)
- func (t *Tester) PinPOST(sl string) (int, error)
- func (t *Tester) Request(method string, endpoint string, queryParams url.Values, body []byte, ...) (*http.Response, error)
- func (t *Tester) ServerRemovePOST(server string) (api.ServerRemoveResponse, int, error)
- func (t *Tester) SetFollowRedirects(f bool)
- func (t *Tester) SweepPOST() (api.SweepPOSTResponse, int, error)
- func (t *Tester) SweepStatusGET() (sweeper.Status, int, error)
- func (t *Tester) UnpinPOST(sl string) (int, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ServerName is what we'll use for ServerName during testing. We want // to have it in a separate variable, so we can set it in different tests // without worrying about them choosing different names. ServerName = "test.server.name" )
Functions ¶
func Contains ¶ added in v0.1.0
func Contains[T comparable](haystack []T, needle T) bool
Contains checks whether the given slice contains the given element.
func Context ¶ added in v0.6.0
func Context() (context.Context, context.CancelFunc)
Context returns a context with default timeout. We should use this in most tests, so the CI doesn't run into timeouts.
func DBTestCredentials ¶
func DBTestCredentials() database.DBCredentials
DBTestCredentials sets the environment variables to what we have defined in Makefile.
func LoadTestConfig ¶
LoadTestConfig temporarily replaces environment variables with their test values, loads the configuration with these test values and then restores the original environment.
func NewDatabase ¶
NewDatabase returns a new DB connection based on the passed parameters.
func NewDiscardLogger ¶
NewDiscardLogger returns a new logger that sends all output to io.Discard.
func RandomSkylink ¶
func RandomSkylink() skymodules.Skylink
RandomSkylink generates a random skylink
func SanitizeName ¶
SanitizeName sanitizes the input for all kinds of unwanted characters and replaces those with underscores. See https://docs.mongodb.com/manual/reference/limits/#naming-restrictions
Types ¶
type Tester ¶
type Tester struct { Ctx context.Context DB *database.DB FollowRedirects bool Logger logger.Logger ServerName string SkydClient skyd.Client // contains filtered or unexported fields }
Tester is a simple testing kit. It starts a testing instance of the service and provides simplified ways to call the handlers.
func NewTester ¶
NewTester creates and starts a new Tester service. Use the Close method for a graceful shutdown.
func (*Tester) ListServersGET ¶ added in v0.6.1
ListServersGET lists all servers that pin a given skylink
func (*Tester) ListSkylinksGET ¶ added in v0.6.1
ListSkylinksGET lists all skylinks pinned by a given server.
func (*Tester) Request ¶
func (t *Tester) Request(method string, endpoint string, queryParams url.Values, body []byte, headers map[string]string, obj interface{}) (*http.Response, error)
Request is a helper method that puts together and executes an HTTP Request. It attaches the current cookie, if one exists.
NOTE: The Body of the returned response is already read and closed.
func (*Tester) ServerRemovePOST ¶ added in v0.6.0
ServerRemovePOST removes a server as pinner.
func (*Tester) SetFollowRedirects ¶
SetFollowRedirects configures the tester to either follow HTTP redirects or not. The default is to follow them.
func (*Tester) SweepPOST ¶ added in v0.1.0
func (t *Tester) SweepPOST() (api.SweepPOSTResponse, int, error)
SweepPOST kicks off a background process which gets all files pinned by skyd and marks them in the DB as pinned by the current server. It also goes over all files in the DB that are marked as pinned by the local skyd and unmarks those which are not in the list reported by skyd.
func (*Tester) SweepStatusGET ¶ added in v0.1.0
SweepStatusGET returns the status of the latest sweep.