mocks

package
v2.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger() chronograf.Logger

NewLogger returns a mock logger that implements chronograf.Logger

Types

type Authenticator

type Authenticator struct {
	Principal   oauth2.Principal
	ValidateErr error
	ExtendErr   error
	Serialized  string
}

Authenticator implements a OAuth2 authenticator

func (*Authenticator) Authorize

Authorize will grant privileges to a Principal

func (*Authenticator) Expire

func (a *Authenticator) Expire(http.ResponseWriter)

Expire revokes privileges from a Principal

func (*Authenticator) Extend

Extend will extend the lifetime of a already validated Principal

func (*Authenticator) Serialize

Serialize the serialized values stored on the Authenticator

func (*Authenticator) ValidAuthorization

func (a *Authenticator) ValidAuthorization(ctx context.Context, serializedAuthorization string) (oauth2.Principal, error)

ValidAuthorization returns the Principal

func (*Authenticator) Validate

Validate returns Principal associated with authenticated and authorized entity if successful.

type ConfigStore

type ConfigStore struct {
	Config *chronograf.Config
}

ConfigStore stores global application configuration

func (ConfigStore) Get

Get returns the whole global application configuration

func (ConfigStore) Initialize

func (c ConfigStore) Initialize(ctx context.Context) error

Initialize is noop in mocks store

func (ConfigStore) Update

func (c ConfigStore) Update(ctx context.Context, config *chronograf.Config) error

Update updates the whole global application configuration

type DashboardsStore

type DashboardsStore struct {
	AddF    func(ctx context.Context, newDashboard chronograf.Dashboard) (chronograf.Dashboard, error)
	AllF    func(ctx context.Context) ([]chronograf.Dashboard, error)
	DeleteF func(ctx context.Context, target chronograf.Dashboard) error
	GetF    func(ctx context.Context, id chronograf.DashboardID) (chronograf.Dashboard, error)
	UpdateF func(ctx context.Context, target chronograf.Dashboard) error
}

func (*DashboardsStore) Add

func (*DashboardsStore) All

func (*DashboardsStore) Delete

func (d *DashboardsStore) Delete(ctx context.Context, target chronograf.Dashboard) error

func (*DashboardsStore) Get

func (*DashboardsStore) Update

func (d *DashboardsStore) Update(ctx context.Context, target chronograf.Dashboard) error

type Databases

Databases mock allows all databases methods to be set for testing

func (*Databases) AllDB

func (d *Databases) AllDB(ctx context.Context) ([]chronograf.Database, error)

AllDB lists all databases in the current data source

func (*Databases) AllRP

AllRP lists all retention policies in the current data source

func (*Databases) Connect

func (d *Databases) Connect(ctx context.Context, src *chronograf.Source) error

Connect connects to a database in the current data source

func (*Databases) CreateDB

CreateDB creates a database in the current data source

func (*Databases) CreateRP

CreateRP creates a retention policy in the current data source

func (*Databases) DropDB

func (d *Databases) DropDB(ctx context.Context, db string) error

DropDB drops a database in the current data source

func (*Databases) DropRP

func (d *Databases) DropRP(ctx context.Context, rpX string, rpY string) error

DropRP drops a retention policy in the current data source

func (*Databases) GetMeasurements

func (d *Databases) GetMeasurements(ctx context.Context, db string, limit, offset int) ([]chronograf.Measurement, error)

GetMeasurements lists measurements in the current data source

func (*Databases) UpdateRP

UpdateRP updates a retention policy in the current data source

type LayoutsStore

type LayoutsStore struct {
	AddF    func(ctx context.Context, layout chronograf.Layout) (chronograf.Layout, error)
	AllF    func(ctx context.Context) ([]chronograf.Layout, error)
	DeleteF func(ctx context.Context, layout chronograf.Layout) error
	GetF    func(ctx context.Context, id string) (chronograf.Layout, error)
	UpdateF func(ctx context.Context, layout chronograf.Layout) error
}

func (*LayoutsStore) Add

func (*LayoutsStore) All

func (*LayoutsStore) Delete

func (s *LayoutsStore) Delete(ctx context.Context, layout chronograf.Layout) error

func (*LayoutsStore) Get

func (*LayoutsStore) Update

func (s *LayoutsStore) Update(ctx context.Context, layout chronograf.Layout) error

type LogMessage

type LogMessage struct {
	Level string
	Body  string
}

type MappingsStore

type MappingsStore struct {
	AddF    func(context.Context, *chronograf.Mapping) (*chronograf.Mapping, error)
	AllF    func(context.Context) ([]chronograf.Mapping, error)
	DeleteF func(context.Context, *chronograf.Mapping) error
	UpdateF func(context.Context, *chronograf.Mapping) error
	GetF    func(context.Context, string) (*chronograf.Mapping, error)
}

func (*MappingsStore) Add

func (*MappingsStore) All

func (*MappingsStore) Delete

func (s *MappingsStore) Delete(ctx context.Context, m *chronograf.Mapping) error

func (*MappingsStore) Get

func (*MappingsStore) Update

func (s *MappingsStore) Update(ctx context.Context, m *chronograf.Mapping) error

type OrganizationConfigStore

type OrganizationConfigStore struct {
	FindOrCreateF func(ctx context.Context, id string) (*chronograf.OrganizationConfig, error)
	PutF          func(ctx context.Context, c *chronograf.OrganizationConfig) error
}

func (*OrganizationConfigStore) FindOrCreate

func (*OrganizationConfigStore) Put

type OrganizationsStore

type OrganizationsStore struct {
	AllF                 func(context.Context) ([]chronograf.Organization, error)
	AddF                 func(context.Context, *chronograf.Organization) (*chronograf.Organization, error)
	DeleteF              func(context.Context, *chronograf.Organization) error
	GetF                 func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error)
	UpdateF              func(context.Context, *chronograf.Organization) error
	CreateDefaultF       func(context.Context) error
	DefaultOrganizationF func(context.Context) (*chronograf.Organization, error)
}

func (*OrganizationsStore) Add

func (*OrganizationsStore) All

func (*OrganizationsStore) CreateDefault

func (s *OrganizationsStore) CreateDefault(ctx context.Context) error

func (*OrganizationsStore) DefaultOrganization

func (s *OrganizationsStore) DefaultOrganization(ctx context.Context) (*chronograf.Organization, error)

func (*OrganizationsStore) Delete

func (*OrganizationsStore) Get

func (*OrganizationsStore) Update

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response is a mocked chronograf.Response

func NewResponse

func NewResponse(res string, err error) *Response

NewResponse returns a mocked chronograf.Response

func (*Response) MarshalJSON

func (r *Response) MarshalJSON() ([]byte, error)

MarshalJSON returns the res and err as the fake response.

type RolesStore

type RolesStore struct {
	AllF    func(context.Context) ([]chronograf.Role, error)
	AddF    func(context.Context, *chronograf.Role) (*chronograf.Role, error)
	DeleteF func(context.Context, *chronograf.Role) error
	GetF    func(ctx context.Context, name string) (*chronograf.Role, error)
	UpdateF func(context.Context, *chronograf.Role) error
}

RolesStore mock allows all functions to be set for testing

func (*RolesStore) Add

Add a new Role in the RolesStore

func (*RolesStore) All

func (s *RolesStore) All(ctx context.Context) ([]chronograf.Role, error)

All lists all Roles from the RolesStore

func (*RolesStore) Delete

func (s *RolesStore) Delete(ctx context.Context, u *chronograf.Role) error

Delete the Role from the RolesStore

func (*RolesStore) Get

func (s *RolesStore) Get(ctx context.Context, name string) (*chronograf.Role, error)

Get retrieves a Role if name exists.

func (*RolesStore) Update

func (s *RolesStore) Update(ctx context.Context, u *chronograf.Role) error

Update the Role's permissions or users

type ServersStore

type ServersStore struct {
	AllF    func(context.Context) ([]chronograf.Server, error)
	AddF    func(context.Context, chronograf.Server) (chronograf.Server, error)
	DeleteF func(context.Context, chronograf.Server) error
	GetF    func(ctx context.Context, ID int) (chronograf.Server, error)
	UpdateF func(context.Context, chronograf.Server) error
}

ServersStore mock allows all functions to be set for testing

func (*ServersStore) Add

func (*ServersStore) All

func (*ServersStore) Delete

func (s *ServersStore) Delete(ctx context.Context, srv chronograf.Server) error

func (*ServersStore) Get

func (s *ServersStore) Get(ctx context.Context, id int) (chronograf.Server, error)

func (*ServersStore) Update

func (s *ServersStore) Update(ctx context.Context, srv chronograf.Server) error

type SourcesStore

type SourcesStore struct {
	AllF    func(context.Context) ([]chronograf.Source, error)
	AddF    func(context.Context, chronograf.Source) (chronograf.Source, error)
	DeleteF func(context.Context, chronograf.Source) error
	GetF    func(ctx context.Context, ID int) (chronograf.Source, error)
	UpdateF func(context.Context, chronograf.Source) error
}

SourcesStore mock allows all functions to be set for testing

func (*SourcesStore) Add

Add creates a new source in the SourcesStore and returns Source with ID

func (*SourcesStore) All

All returns all sources in the store

func (*SourcesStore) Delete

func (s *SourcesStore) Delete(ctx context.Context, src chronograf.Source) error

Delete the Source from the store

func (*SourcesStore) Get

func (s *SourcesStore) Get(ctx context.Context, ID int) (chronograf.Source, error)

Get retrieves Source if `ID` exists

func (*SourcesStore) Update

func (s *SourcesStore) Update(ctx context.Context, src chronograf.Source) error

Update the Source in the store.

type Store

type Store struct {
	SourcesStore            chronograf.SourcesStore
	MappingsStore           chronograf.MappingsStore
	ServersStore            chronograf.ServersStore
	LayoutsStore            chronograf.LayoutsStore
	UsersStore              chronograf.UsersStore
	DashboardsStore         chronograf.DashboardsStore
	OrganizationsStore      chronograf.OrganizationsStore
	ConfigStore             chronograf.ConfigStore
	OrganizationConfigStore chronograf.OrganizationConfigStore
}

Store is a server.DataStore

func (*Store) Config

func (s *Store) Config(ctx context.Context) chronograf.ConfigStore

func (*Store) Dashboards

func (s *Store) Dashboards(ctx context.Context) chronograf.DashboardsStore

func (*Store) Layouts

func (s *Store) Layouts(ctx context.Context) chronograf.LayoutsStore

func (*Store) Mappings

func (s *Store) Mappings(ctx context.Context) chronograf.MappingsStore

func (*Store) OrganizationConfig

func (s *Store) OrganizationConfig(ctx context.Context) chronograf.OrganizationConfigStore

func (*Store) Organizations

func (s *Store) Organizations(ctx context.Context) chronograf.OrganizationsStore

func (*Store) Servers

func (s *Store) Servers(ctx context.Context) chronograf.ServersStore

func (*Store) Sources

func (s *Store) Sources(ctx context.Context) chronograf.SourcesStore

func (*Store) Users

func (s *Store) Users(ctx context.Context) chronograf.UsersStore

type TestLogger

type TestLogger struct {
	Messages []LogMessage
}

TestLogger is a chronograf.Logger which allows assertions to be made on the contents of its messages.

func (*TestLogger) Debug

func (tl *TestLogger) Debug(args ...interface{})

func (*TestLogger) Dump

func (tl *TestLogger) Dump(t *testing.T)

Dump dumps out logs into a given testing.T's logs

func (*TestLogger) Error

func (tl *TestLogger) Error(args ...interface{})

func (*TestLogger) HasMessage

func (tl *TestLogger) HasMessage(level string, body string) bool

HasMessage will return true if the TestLogger has been called with an exact match of a particular log message at a particular log level

func (*TestLogger) Info

func (tl *TestLogger) Info(args ...interface{})

func (*TestLogger) WithField

func (tl *TestLogger) WithField(key string, value interface{}) chronograf.Logger

func (*TestLogger) Writer

func (tl *TestLogger) Writer() *io.PipeWriter

type TimeSeries

type TimeSeries struct {
	// Connect will connect to the time series using the information in `Source`.
	ConnectF func(context.Context, *chronograf.Source) error
	// Query retrieves time series data from the database.
	QueryF func(context.Context, chronograf.Query) (chronograf.Response, error)
	// Write records points into the TimeSeries
	WriteF func(context.Context, []chronograf.Point) error
	// UsersStore represents the user accounts within the TimeSeries database
	UsersF func(context.Context) chronograf.UsersStore
	// Permissions returns all valid names permissions in this database
	PermissionsF func(context.Context) chronograf.Permissions
	// RolesF represents the roles. Roles group permissions and Users
	RolesF func(context.Context) (chronograf.RolesStore, error)
}

TimeSeries is a mockable chronograf time series by overriding the functions.

func (*TimeSeries) Connect

func (t *TimeSeries) Connect(ctx context.Context, src *chronograf.Source) error

Connect will connect to the time series using the information in `Source`.

func (*TimeSeries) New

New implements TimeSeriesClient

func (*TimeSeries) Permissions

func (t *TimeSeries) Permissions(ctx context.Context) chronograf.Permissions

Permissions returns all valid names permissions in this database

func (*TimeSeries) Query

Query retrieves time series data from the database.

func (*TimeSeries) Roles

Roles represents the roles. Roles group permissions and Users

func (*TimeSeries) Users

Users represents the user accounts within the TimeSeries database

func (*TimeSeries) Write

func (t *TimeSeries) Write(ctx context.Context, points []chronograf.Point) error

Write records a point into the time series

type UsersStore

type UsersStore struct {
	AllF    func(context.Context) ([]chronograf.User, error)
	AddF    func(context.Context, *chronograf.User) (*chronograf.User, error)
	DeleteF func(context.Context, *chronograf.User) error
	GetF    func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error)
	UpdateF func(context.Context, *chronograf.User) error
	NumF    func(context.Context) (int, error)
}

UsersStore mock allows all functions to be set for testing

func (*UsersStore) Add

Add a new User in the UsersStore

func (*UsersStore) All

func (s *UsersStore) All(ctx context.Context) ([]chronograf.User, error)

All lists all users from the UsersStore

func (*UsersStore) Delete

func (s *UsersStore) Delete(ctx context.Context, u *chronograf.User) error

Delete the User from the UsersStore

func (*UsersStore) Get

Get retrieves a user if name exists.

func (*UsersStore) Num

func (s *UsersStore) Num(ctx context.Context) (int, error)

Num returns the number of users in the UsersStore

func (*UsersStore) Update

func (s *UsersStore) Update(ctx context.Context, u *chronograf.User) error

Update the user's permissions or roles

Jump to

Keyboard shortcuts

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