servicetest

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package servicetest provides tests to ensure that implementations of platform/task/backend.Store and platform/task/backend.LogReader meet the requirements of influxdb.TaskService.

Consumers of this package must import query/builtin. This package does not import it directly, to avoid requiring it too early.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestTaskService

func TestTaskService(t *testing.T, fn BackendComponentFactory, testCategory ...string)

TestTaskService should be called by consumers of the servicetest package. This will call fn once to create a single influxdb.TaskService used across all subtests in TestTaskService.

Types

type AuthorizationService

type AuthorizationService interface {
	CreateAuthorization(ctx context.Context, a *influxdb.Authorization) error
}

type BackendComponentFactory

type BackendComponentFactory func(t *testing.T) (*System, context.CancelFunc)

BackendComponentFactory is supplied by consumers of the adaptertest package, to provide the values required to constitute a PlatformAdapter. The provided context.CancelFunc is called after the test, and it is the implementer's responsibility to clean up after that is called.

If creating the System fails, the implementer should call t.Fatal.

type OrganizationService

type OrganizationService interface {
	CreateOrganization(ctx context.Context, b *influxdb.Organization) error
}

type System

type System struct {
	TaskControlService backend.TaskControlService

	// Used in the Creds function to create valid organizations, users, tokens, etc.
	OrganizationService        OrganizationService
	UserService                UserService
	UserResourceMappingService UserResourceMappingService
	AuthorizationService       AuthorizationService

	// Set this context, to be used in tests, so that any spawned goroutines watching Ctx.Done()
	// will clean up after themselves.
	Ctx context.Context

	// TaskService is the task service we would like to test
	TaskService influxdb.TaskService

	// Override for accessing credentials for an individual test.
	// Callers can leave this nil and the test will create its own random IDs for each test.
	// However, if the system needs to verify credentials,
	// the caller should set this value and return valid IDs and a valid token.
	// It is safe if this returns the same values every time it is called.
	CredsFunc func(*testing.T) (TestCreds, error)

	// Toggles behavior between KV and archive storage because FinishRun() deletes runs after completion
	CallFinishRun bool
}

System as in "system under test" encapsulates the required parts of a influxdb.TaskAdapter

type TestCreds

type TestCreds struct {
	OrgID, UserID, AuthorizationID influxdb.ID
	Org                            string
	Token                          string
}

TestCreds encapsulates credentials needed for a system to properly work with tasks.

func (TestCreds) Authorizer

func (tc TestCreds) Authorizer() influxdb.Authorizer

Authorizer returns an authorizer for the credentials in the struct

type UserResourceMappingService

type UserResourceMappingService interface {
	CreateUserResourceMapping(ctx context.Context, m *influxdb.UserResourceMapping) error
}

type UserService

type UserService interface {
	CreateUser(ctx context.Context, u *influxdb.User) error
}

Jump to

Keyboard shortcuts

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