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
- Variables
- func MakeAuthorization(org, userID influxdb.ID, perms ...[]influxdb.Permission) *influxdb.Authorization
- func MakeBucketPerm(bucketID influxdb.ID, actions ...influxdb.Action) []influxdb.Permission
- func MakeBucketRWPerm(bucketID influxdb.ID) []influxdb.Permission
- func MockCheck(name string, orgID, userID influxdb.ID) *influxhttp.Check
- func QueryRequestBody(flux string) *influxhttp.QueryRequest
- func ValidCustomNotificationEndpoint(org influxdb.ID, name string) influxdb.NotificationEndpoint
- func ValidNotificationEndpoint(org influxdb.ID) influxdb.NotificationEndpoint
- func ValidNotificationRule(org, endpoint influxdb.ID) influxdb.NotificationRule
- type Client
- func (c *Client) AddMember(user influxdb.ID, r influxdb.ResourceType, id influxdb.ID) error
- func (c *Client) AddOwner(user influxdb.ID, r influxdb.ResourceType, id influxdb.ID) error
- func (c *Client) AddURM(u influxdb.ID, typ influxdb.UserType, r influxdb.ResourceType, id influxdb.ID) error
- func (c *Client) Close() error
- func (c *Client) CreateLabelMapping(l influxdb.ID, r influxdb.ResourceType, id influxdb.ID) error
- func (c *Client) DeleteLabelMapping(l influxdb.ID, r influxdb.ResourceType, id influxdb.ID) error
- func (c *Client) DeleteResource(t *testing.T, r influxdb.ResourceType, id influxdb.ID) error
- func (c *Client) FindAll(t *testing.T, r influxdb.ResourceType) ([]influxdb.ID, error)
- func (c *Client) FindLabelMappings(r influxdb.ResourceType, id influxdb.ID) ([]influxdb.ID, error)
- func (c *Client) MustAddMember(t *testing.T, user influxdb.ID, r influxdb.ResourceType, id influxdb.ID)
- func (c *Client) MustAddOwner(t *testing.T, user influxdb.ID, r influxdb.ResourceType, id influxdb.ID)
- func (c *Client) MustCreateAuth(t *testing.T) influxdb.ID
- func (c *Client) MustCreateBucket(t *testing.T) influxdb.ID
- func (c *Client) MustCreateCheck(t *testing.T) influxdb.ID
- func (c *Client) MustCreateDBRPMapping(t *testing.T) influxdb.ID
- func (c *Client) MustCreateLabel(t *testing.T) influxdb.ID
- func (c *Client) MustCreateLabelMapping(t *testing.T, l influxdb.ID, r influxdb.ResourceType, id influxdb.ID)
- func (c *Client) MustCreateNotificationEndpoint(t *testing.T) influxdb.ID
- func (c *Client) MustCreateNotificationRule(t *testing.T) influxdb.ID
- func (c *Client) MustCreateOrg(t *testing.T) influxdb.ID
- func (c *Client) MustCreateResource(t *testing.T, r influxdb.ResourceType) influxdb.ID
- func (c *Client) MustCreateTelegraf(t *testing.T) influxdb.ID
- func (c *Client) MustCreateUser(t *testing.T) influxdb.ID
- func (c *Client) MustCreateVariable(t *testing.T) influxdb.ID
- func (c *Client) MustDeleteLabelMapping(t *testing.T, l influxdb.ID, r influxdb.ResourceType, id influxdb.ID)
- func (c *Client) MustDeleteResource(t *testing.T, r influxdb.ResourceType, id influxdb.ID)
- func (c *Client) MustFindAll(t *testing.T, r influxdb.ResourceType) []influxdb.ID
- func (c *Client) MustFindLabelMappings(t *testing.T, r influxdb.ResourceType, id influxdb.ID) []influxdb.ID
- func (c *Client) MustRemoveURM(t *testing.T, user, id influxdb.ID)
- func (c *Client) MustWriteBatch(points string)
- func (c *Client) Open() error
- func (c *Client) QueryFlux(org, query string) (string, error)
- func (c *Client) RemoveSpecificURM(rt influxdb.ResourceType, ut influxdb.UserType, user, id influxdb.ID) error
- func (c *Client) RemoveURM(user, id influxdb.ID) error
- func (c *Client) WriteBatch(points string) error
- type ClientConfig
- type DefaultPipeline
- type Pipeline
- func (p *Pipeline) BrowserFor(org, bucket influxdb.ID, username string) (*Client, influxdb.ID, error)
- func (p *Pipeline) Close() error
- func (p *Pipeline) Flush()
- func (p *Pipeline) MustClose()
- func (p *Pipeline) MustNewAdminClient() *Client
- func (p *Pipeline) MustNewClient(org, bucket influxdb.ID, token string) *Client
- func (p *Pipeline) MustOpen()
- func (p *Pipeline) NewBrowserClient(org, bucket influxdb.ID, session *influxdb.Session) (*Client, error)
- func (p *Pipeline) Open() error
- type PipelineOption
Constants ¶
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.
const (
// This is the only namespace for documents present after init.
DefaultDocumentsNamespace = "templates"
)
Variables ¶
var VeryVerbose bool
VeryVerbose when set to true, will enable very verbose logging of services.
Functions ¶
func MakeAuthorization ¶
func MakeAuthorization(org, userID influxdb.ID, perms ...[]influxdb.Permission) *influxdb.Authorization
func MakeBucketPerm ¶
func MakeBucketPerm(bucketID influxdb.ID, actions ...influxdb.Action) []influxdb.Permission
func MakeBucketRWPerm ¶
func MakeBucketRWPerm(bucketID influxdb.ID) []influxdb.Permission
func MockCheck ¶
func MockCheck(name string, orgID, userID influxdb.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 influxdb.ID, name string) influxdb.NotificationEndpoint
ValidCustomNotificationEndpoint creates a NotificationEndpoint with a custom name
func ValidNotificationEndpoint ¶
func ValidNotificationEndpoint(org influxdb.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 influxdb.ID) influxdb.NotificationRule
ValidNotificationRule returns a valid Notification Rule of type HTTP for testing
Types ¶
type Client ¶
type Client struct { Client *httpc.Client *influxhttp.Service *authorization.AuthorizationClientService *tenant.BucketClientService *tenant.OrgClientService *tenant.UserClientService ClientConfig }
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) CreateLabelMapping ¶
CreateLabelMapping creates a label mapping for label `l` to the resource with `id`.
func (*Client) DeleteLabelMapping ¶
DeleteLabelMapping deletes the label for the specified resource.
func (*Client) DeleteResource ¶
DeleteResource will remove a resource using the API.
func (*Client) FindLabelMappings ¶
FindLabelMappings finds the labels for the specified resource.
func (*Client) MustAddMember ¶
func (c *Client) MustAddMember(t *testing.T, user influxdb.ID, r influxdb.ResourceType, id influxdb.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 influxdb.ID, r influxdb.ResourceType, id influxdb.ID)
MustAddOwner requires that the user is associated with the resource or the test will be stopped fatally.
func (*Client) MustCreateAuth ¶
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 ¶
MustCreateBucket creates a bucket or is a fatal error. Used in tests where the content of the bucket does not matter.
func (*Client) MustCreateCheck ¶
MustCreateCheck creates a check or is a fatal error. Used in tests where the content of the check does not matter.
func (*Client) MustCreateDBRPMapping ¶
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 ¶
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 influxdb.ID, r influxdb.ResourceType, id influxdb.ID)
MustCreateLabelMapping requires that the label is associated with the resource or the test will be stopped fatally.
func (*Client) MustCreateNotificationEndpoint ¶
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 ¶
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 ¶
MustCreateOrg creates an org or is a fatal error. Used in tests where the content of the org does not matter.
func (*Client) MustCreateResource ¶
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 ¶
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 ¶
MustCreateUser creates a user or is a fatal error. Used in tests where the content of the user does not matter.
func (*Client) MustCreateVariable ¶
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 influxdb.ID, r influxdb.ResourceType, id influxdb.ID)
MustDeleteLabelMapping makes the test fail if an error is found.
func (*Client) MustDeleteResource ¶
MustDeleteResource requires no error when deleting a resource.
func (*Client) MustFindAll ¶
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 influxdb.ID) []influxdb.ID
MustFindLabelMappings makes the test fail if an error is found.
func (*Client) MustRemoveURM ¶
MustRemoveURM requires that the user is removed as owner/member from the resource.
func (*Client) MustWriteBatch ¶
MustWriteBatch calls WriteBatch, panicking if an error is encountered.
func (*Client) QueryFlux ¶
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 influxdb.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 ¶
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 ¶
WriteBatch writes the current batch of points to the HTTP endpoint.
type ClientConfig ¶
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 ...PipelineOption) *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 influxdb.ID DefaultBucketID influxdb.ID DefaultUserID influxdb.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 ...PipelineOption) *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 influxdb.ID, username string) (*Client, influxdb.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) 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 ¶
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 ¶
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 influxdb.ID, session *influxdb.Session) (*Client, error)
NewBrowserClient returns a client with a cookie session that will direct requests to Launcher.
type PipelineOption ¶
type PipelineOption interface {
// contains filtered or unexported methods
}
PipelineOption configures a pipeline.
func WithDefaults ¶
func WithDefaults() []PipelineOption
WithDefaults returns a slice of options for a default pipeline.
func WithInfluxQLMaxSelectBucketsN ¶
func WithInfluxQLMaxSelectBucketsN(n int) PipelineOption
WithInfluxQLMaxSelectBucketsN configures the maximum number of buckets returned by a select statement.
func WithInfluxQLMaxSelectSeriesN ¶
func WithInfluxQLMaxSelectSeriesN(n int) PipelineOption
WithInfluxQLMaxSelectSeriesN configures the maximum number of series returned by a select statement.
func WithLogger ¶
func WithLogger(logger *zap.Logger) PipelineOption
WithReplicas sets the number of replicas in the pipeline.