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 platform.ID, perms ...[]influxdb.Permission) *influxdb.Authorization
- func MakeBucketPerm(bucketID platform.ID, actions ...influxdb.Action) []influxdb.Permission
- func MakeBucketRWPerm(bucketID platform.ID) []influxdb.Permission
- func MockCheck(name string, orgID, userID platform.ID) *influxhttp.Check
- func QueryRequestBody(flux string) *influxhttp.QueryRequest
- func ValidCustomNotificationEndpoint(org platform.ID, name string) influxdb.NotificationEndpoint
- func ValidNotificationEndpoint(org platform.ID) influxdb.NotificationEndpoint
- func ValidNotificationRule(org, endpoint platform.ID) influxdb.NotificationRule
- type Client
- func (c *Client) AddMember(user platform.ID, r influxdb.ResourceType, id platform.ID) error
- func (c *Client) AddOwner(user platform.ID, r influxdb.ResourceType, id platform.ID) error
- func (c *Client) AddURM(u platform.ID, typ influxdb.UserType, r influxdb.ResourceType, id platform.ID) error
- func (c *Client) Close() error
- func (c *Client) CreateLabelMapping(l platform.ID, r influxdb.ResourceType, id platform.ID) error
- func (c *Client) DeleteLabelMapping(l platform.ID, r influxdb.ResourceType, id platform.ID) error
- func (c *Client) DeleteResource(t *testing.T, r influxdb.ResourceType, id platform.ID) error
- func (c *Client) FindAll(t *testing.T, r influxdb.ResourceType) ([]platform.ID, error)
- func (c *Client) FindLabelMappings(r influxdb.ResourceType, id platform.ID) ([]platform.ID, error)
- func (c *Client) MustAddMember(t *testing.T, user platform.ID, r influxdb.ResourceType, id platform.ID)
- func (c *Client) MustAddOwner(t *testing.T, user platform.ID, r influxdb.ResourceType, id platform.ID)
- func (c *Client) MustCreateAuth(t *testing.T) platform.ID
- func (c *Client) MustCreateBucket(t *testing.T) platform.ID
- func (c *Client) MustCreateCheck(t *testing.T) platform.ID
- func (c *Client) MustCreateDBRPMapping(t *testing.T) platform.ID
- func (c *Client) MustCreateLabel(t *testing.T) platform.ID
- func (c *Client) MustCreateLabelMapping(t *testing.T, l platform.ID, r influxdb.ResourceType, id platform.ID)
- func (c *Client) MustCreateNotificationEndpoint(t *testing.T) platform.ID
- func (c *Client) MustCreateNotificationRule(t *testing.T) platform.ID
- func (c *Client) MustCreateOrg(t *testing.T) platform.ID
- func (c *Client) MustCreateResource(t *testing.T, r influxdb.ResourceType) platform.ID
- func (c *Client) MustCreateTelegraf(t *testing.T) platform.ID
- func (c *Client) MustCreateUser(t *testing.T) platform.ID
- func (c *Client) MustCreateVariable(t *testing.T) platform.ID
- func (c *Client) MustDeleteLabelMapping(t *testing.T, l platform.ID, r influxdb.ResourceType, id platform.ID)
- func (c *Client) MustDeleteResource(t *testing.T, r influxdb.ResourceType, id platform.ID)
- func (c *Client) MustFindAll(t *testing.T, r influxdb.ResourceType) []platform.ID
- func (c *Client) MustFindLabelMappings(t *testing.T, r influxdb.ResourceType, id platform.ID) []platform.ID
- func (c *Client) MustRemoveURM(t *testing.T, user, id platform.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 platform.ID) error
- func (c *Client) RemoveURM(user, id platform.ID) error
- func (c *Client) WriteBatch(points string) error
- type ClientConfig
- type DefaultPipeline
- type Pipeline
- func (p *Pipeline) BrowserFor(org, bucket platform.ID, username string) (*Client, platform.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 platform.ID, token string) *Client
- func (p *Pipeline) MustOpen()
- func (p *Pipeline) NewBrowserClient(org, bucket platform.ID, session *influxdb.Session) (*Client, error)
- func (p *Pipeline) Open() error
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 MakeBucketPerm ¶
func MakeBucketRWPerm ¶
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 ¶
ValidCustomNotificationEndpoint creates a NotificationEndpoint with a custom name
func ValidNotificationEndpoint ¶
ValidNotificationEndpoint returns a valid notification endpoint. This is the easiest way of "mocking" a influxdb.NotificationEndpoint.
func ValidNotificationRule ¶
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 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 ¶
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 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 ¶
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 platform.ID, r influxdb.ResourceType, id platform.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 platform.ID) []platform.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 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 ¶
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 ...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 ¶
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) 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.