test

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 23 Imported by: 0

README

Description

This directory contains pinner's integration tests.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func LoadTestConfig() (conf.Config, error)

LoadTestConfig temporarily replaces environment variables with their test values, loads the configuration with these test values and then restores the original environment.

func NewDatabase

func NewDatabase(ctx context.Context, dbName string) (*database.DB, error)

NewDatabase returns a new DB connection based on the passed parameters.

func NewDiscardLogger

func NewDiscardLogger() *logrus.Logger

NewDiscardLogger returns a new logger that sends all output to io.Discard.

func RandomSkylink() skymodules.Skylink

RandomSkylink generates a random skylink

func SanitizeName

func SanitizeName(s string) string

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

func NewTester(dbName string) (*Tester, error)

NewTester creates and starts a new Tester service. Use the Close method for a graceful shutdown.

func (*Tester) Close

func (t *Tester) Close() error

Close performs a graceful shutdown of the Tester service.

func (*Tester) HealthGET

func (t *Tester) HealthGET() (api.HealthGET, int, error)

HealthGET checks the health of the service.

func (*Tester) ListServersGET added in v0.6.1

func (t *Tester) ListServersGET(skylink string) ([]string, int, error)

ListServersGET lists all servers that pin a given skylink

func (*Tester) ListSkylinksGET added in v0.6.1

func (t *Tester) ListSkylinksGET(server string) ([]string, int, error)

ListSkylinksGET lists all skylinks pinned by a given server.

func (*Tester) PinPOST

func (t *Tester) PinPOST(sl string) (int, error)

PinPOST tells pinner that the current server is pinning a given skylink.

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

func (t *Tester) ServerRemovePOST(server string) (api.ServerRemoveResponse, int, error)

ServerRemovePOST removes a server as pinner.

func (*Tester) SetFollowRedirects

func (t *Tester) SetFollowRedirects(f bool)

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

func (t *Tester) SweepStatusGET() (sweeper.Status, int, error)

SweepStatusGET returns the status of the latest sweep.

func (*Tester) UnpinPOST

func (t *Tester) UnpinPOST(sl string) (int, error)

UnpinPOST tells pinner that no users are pinning this skylink and it should be unpinned by all servers.

Jump to

Keyboard shortcuts

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