tests

package
v2.7.6 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package tests contains a set of integration tests, which run in-memory versions of various 2.0 services. They're not intended to be full end-to-end tests, but are a suitable place to write tests that need to flex the logic of multiple 2.0 components.

Index

Constants

View Source
const (
	DefaultOrgName = "myorg"

	DefaultBucketName = "db/rp" // Since we can only write data via 1.x path we need to have a 1.x bucket name

	DefaultUsername = "admin"
	DefaultPassword = "password"

	// OperToken has permissions to do anything.
	OperToken = "opertoken"
)

Default values created when calling NewPipeline.

View Source
const (

	// This is the only namespace for documents present after init.
	DefaultDocumentsNamespace = "templates"
)

Variables

View Source
var VeryVerbose bool

VeryVerbose when set to true, will enable very verbose logging of services.

Functions

func MakeAuthorization

func MakeAuthorization(org, userID platform.ID, perms ...[]influxdb.Permission) *influxdb.Authorization

func MakeBucketPerm

func MakeBucketPerm(bucketID platform.ID, actions ...influxdb.Action) []influxdb.Permission

func MakeBucketRWPerm

func MakeBucketRWPerm(bucketID platform.ID) []influxdb.Permission

func MockCheck

func MockCheck(name string, orgID, userID platform.ID) *influxhttp.Check

MockCheck returns a valid check to be used in tests.

func QueryRequestBody

func QueryRequestBody(flux string) *influxhttp.QueryRequest

QueryRequestBody creates a body for a flux query using common CSV output params. Headers are included, but, annotations are not.

func ValidCustomNotificationEndpoint

func ValidCustomNotificationEndpoint(org platform.ID, name string) influxdb.NotificationEndpoint

ValidCustomNotificationEndpoint creates a NotificationEndpoint with a custom name

func ValidNotificationEndpoint

func ValidNotificationEndpoint(org platform.ID) influxdb.NotificationEndpoint

ValidNotificationEndpoint returns a valid notification endpoint. This is the easiest way of "mocking" a influxdb.NotificationEndpoint.

func ValidNotificationRule

func ValidNotificationRule(org, endpoint platform.ID) influxdb.NotificationRule

ValidNotificationRule returns a valid Notification Rule of type HTTP for testing

Types

type Client

Client provides an API for writing, querying, and interacting with resources like authorizations, buckets, and organizations.

func NewClient

func NewClient(endpoint string, config ClientConfig) (*Client, error)

NewClient initialises a new Client which is ready to write points to the HTTP write endpoint.

func (*Client) AddMember

func (c *Client) AddMember(user platform.ID, r influxdb.ResourceType, id platform.ID) error

AddMember associates the user as member of the resource.

func (*Client) AddOwner

func (c *Client) AddOwner(user platform.ID, r influxdb.ResourceType, id platform.ID) error

AddOwner associates the user as owner of the resource.

func (*Client) AddURM

func (c *Client) AddURM(u platform.ID, typ influxdb.UserType, r influxdb.ResourceType, id platform.ID) error

func (*Client) Close

func (c *Client) Close() error

Close closes the client

func (*Client) CreateLabelMapping

func (c *Client) CreateLabelMapping(l platform.ID, r influxdb.ResourceType, id platform.ID) error

CreateLabelMapping creates a label mapping for label `l` to the resource with `id`.

func (*Client) DeleteLabelMapping

func (c *Client) DeleteLabelMapping(l platform.ID, r influxdb.ResourceType, id platform.ID) error

DeleteLabelMapping deletes the label for the specified resource.

func (*Client) DeleteResource

func (c *Client) DeleteResource(t *testing.T, r influxdb.ResourceType, id platform.ID) error

DeleteResource will remove a resource using the API.

func (*Client) FindAll

func (c *Client) FindAll(t *testing.T, r influxdb.ResourceType) ([]platform.ID, error)

FindAll returns all the IDs of a specific resource type.

func (*Client) FindLabelMappings

func (c *Client) FindLabelMappings(r influxdb.ResourceType, id platform.ID) ([]platform.ID, error)

FindLabelMappings finds the labels for the specified resource.

func (*Client) MustAddMember

func (c *Client) MustAddMember(t *testing.T, user platform.ID, r influxdb.ResourceType, id platform.ID)

MustAddMember requires that the user is associated with the resource or the test will be stopped fatally.

func (*Client) MustAddOwner

func (c *Client) MustAddOwner(t *testing.T, user platform.ID, r influxdb.ResourceType, id platform.ID)

MustAddOwner requires that the user is associated with the resource or the test will be stopped fatally.

func (*Client) MustCreateAuth

func (c *Client) MustCreateAuth(t *testing.T) platform.ID

MustCreateAuth creates an auth or is a fatal error. Used in tests where the content of the bucket does not matter.

This authorization token is an operator token for the default organization for the default user.

func (*Client) MustCreateBucket

func (c *Client) MustCreateBucket(t *testing.T) platform.ID

MustCreateBucket creates a bucket or is a fatal error. Used in tests where the content of the bucket does not matter.

func (*Client) MustCreateCheck

func (c *Client) MustCreateCheck(t *testing.T) platform.ID

MustCreateCheck creates a check or is a fatal error. Used in tests where the content of the check does not matter.

func (*Client) MustCreateDBRPMapping

func (c *Client) MustCreateDBRPMapping(t *testing.T) platform.ID

MustCreateDBRPMapping creates a DBRP Mapping or is a fatal error. Used in tests where the content of the mapping does not matter. The created mapping points to the user's default bucket.

func (*Client) MustCreateLabel

func (c *Client) MustCreateLabel(t *testing.T) platform.ID

MustCreateLabel creates a label or is a fatal error. Used in tests where the content of the label does not matter.

func (*Client) MustCreateLabelMapping

func (c *Client) MustCreateLabelMapping(t *testing.T, l platform.ID, r influxdb.ResourceType, id platform.ID)

MustCreateLabelMapping requires that the label is associated with the resource or the test will be stopped fatally.

func (*Client) MustCreateNotificationEndpoint

func (c *Client) MustCreateNotificationEndpoint(t *testing.T) platform.ID

MustCreateNotificationEndpoint creates a notification endpoint or is a fatal error. Used in tests where the content of the notification endpoint does not matter.

func (*Client) MustCreateNotificationRule

func (c *Client) MustCreateNotificationRule(t *testing.T) platform.ID

MustCreateNotificationRule creates a Notification Rule or is a fatal error Used in tests where the content of the notification rule does not matter

func (*Client) MustCreateOrg

func (c *Client) MustCreateOrg(t *testing.T) platform.ID

MustCreateOrg creates an org or is a fatal error. Used in tests where the content of the org does not matter.

func (*Client) MustCreateResource

func (c *Client) MustCreateResource(t *testing.T, r influxdb.ResourceType) platform.ID

MustCreateResource will create a generic resource via the API. Used in tests where the content of the resource does not matter.

// Create one of each org resource
for _, r := range influxdb.OrgResourceTypes {
    client.MustCreateResource(t, r)
}

// Create a variable:
id := client.MustCreateResource(t, influxdb.VariablesResourceType)
defer client.MustDeleteResource(t, influxdb.VariablesResourceType, id)

func (*Client) MustCreateTelegraf

func (c *Client) MustCreateTelegraf(t *testing.T) platform.ID

MustCreateTelegraf creates a telegraf config or is a fatal error. Used in tests where the content of the telegraf config does not matter.

func (*Client) MustCreateUser

func (c *Client) MustCreateUser(t *testing.T) platform.ID

MustCreateUser creates a user or is a fatal error. Used in tests where the content of the user does not matter.

func (*Client) MustCreateVariable

func (c *Client) MustCreateVariable(t *testing.T) platform.ID

MustCreateVariable creates a variable or is a fatal error. Used in tests where the content of the variable does not matter.

func (*Client) MustDeleteLabelMapping

func (c *Client) MustDeleteLabelMapping(t *testing.T, l platform.ID, r influxdb.ResourceType, id platform.ID)

MustDeleteLabelMapping makes the test fail if an error is found.

func (*Client) MustDeleteResource

func (c *Client) MustDeleteResource(t *testing.T, r influxdb.ResourceType, id platform.ID)

MustDeleteResource requires no error when deleting a resource.

func (*Client) MustFindAll

func (c *Client) MustFindAll(t *testing.T, r influxdb.ResourceType) []platform.ID

MustFindAll returns all the IDs of a specific resource type; any error is fatal.

func (*Client) MustFindLabelMappings

func (c *Client) MustFindLabelMappings(t *testing.T, r influxdb.ResourceType, id platform.ID) []platform.ID

MustFindLabelMappings makes the test fail if an error is found.

func (*Client) MustRemoveURM

func (c *Client) MustRemoveURM(t *testing.T, user, id platform.ID)

MustRemoveURM requires that the user is removed as owner/member from the resource.

func (*Client) MustWriteBatch

func (c *Client) MustWriteBatch(points string)

MustWriteBatch calls WriteBatch, panicking if an error is encountered.

func (*Client) Open

func (c *Client) Open() error

Open opens the client

func (*Client) QueryFlux

func (c *Client) QueryFlux(org, query string) (string, error)

Query returns the CSV response from a flux query to the HTTP API.

This also remove all the \r to make it easier to write tests.

func (*Client) RemoveSpecificURM

func (c *Client) RemoveSpecificURM(rt influxdb.ResourceType, ut influxdb.UserType, user, id platform.ID) error

RemoveSpecificURM gets around a client issue where deletes doesn't have enough context to remove a urm from a specific resource type

func (*Client) RemoveURM

func (c *Client) RemoveURM(user, id platform.ID) error

RemoveURM removes association of the user to the resource. Interestingly the URM service does not make difference on the user type. I.e. removing an URM from a user to a resource, will delete every URM of every type from that user to that resource. Or, put in another way, there can only be one resource mapping from a user to a resource at a time: either you are a member, or an owner (in that case you are a member too).

func (*Client) WriteBatch

func (c *Client) WriteBatch(points string) error

WriteBatch writes the current batch of points to the HTTP endpoint.

type ClientConfig

type ClientConfig struct {
	UserID             platform.ID
	OrgID              platform.ID
	BucketID           platform.ID
	DocumentsNamespace string

	// If Session is provided, Token is ignored.
	Token   string
	Session *influxdb.Session
}

type DefaultPipeline

type DefaultPipeline struct {
	*Pipeline
}

DefaultPipeline is a wrapper for Pipeline and is retained for compatibility with cloud tests.

func NewDefaultPipeline

func NewDefaultPipeline(t *testing.T, opts ...launcher.OptSetter) *DefaultPipeline

NewDefaultPipeline creates a Pipeline with default values.

It is retained for compatibility with cloud tests.

type Pipeline

type Pipeline struct {
	Launcher *launcher.TestLauncher

	DefaultOrgID    platform.ID
	DefaultBucketID platform.ID
	DefaultUserID   platform.ID
}

A Pipeline is responsible for configuring launcher.TestLauncher with default values so it may be used for end-to-end integration tests.

func NewPipeline

func NewPipeline(tb testing.TB, opts ...launcher.OptSetter) *Pipeline

NewPipeline returns a pipeline with the given options applied to the configuration as appropriate.

A single user, org, bucket and token are created.

func (*Pipeline) BrowserFor

func (p *Pipeline) BrowserFor(org, bucket platform.ID, username string) (*Client, platform.ID, error)

BrowserFor will create a user, session, and browser client. The generated browser points to the given org and bucket.

The user and session are inserted directly into the backing store.

func (*Pipeline) Close

func (p *Pipeline) Close() error

Close closes all the components of the pipeline.

func (*Pipeline) Flush

func (p *Pipeline) Flush()

Flush is a no-op and retained for compatibility with tests from cloud.

func (*Pipeline) MustClose

func (p *Pipeline) MustClose()

MustClose closes the pipeline, panicking if any error is encountered.

func (*Pipeline) MustNewAdminClient

func (p *Pipeline) MustNewAdminClient() *Client

MustNewAdminClient returns a default client that will direct requests to Launcher.

The operator token is authorized to do anything in the system.

func (*Pipeline) MustNewClient

func (p *Pipeline) MustNewClient(org, bucket platform.ID, token string) *Client

MustNewClient returns a client that will direct requests to Launcher.

func (*Pipeline) MustOpen

func (p *Pipeline) MustOpen()

MustOpen opens the pipeline, panicking if any error is encountered.

func (*Pipeline) NewBrowserClient

func (p *Pipeline) NewBrowserClient(org, bucket platform.ID, session *influxdb.Session) (*Client, error)

NewBrowserClient returns a client with a cookie session that will direct requests to Launcher.

func (*Pipeline) Open

func (p *Pipeline) Open() error

Open opens all the components of the pipeline.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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