mocks

package
v0.0.0-...-0184392 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: AGPL-3.0, AGPL-3.0-or-later Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger() cmp.Logger

NewLogger returns a mock logger that implements cmp.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 CellService

type CellService struct {
	CreateCellF   func(context.Context, *platform.Cell) error
	FindCellByIDF func(context.Context, platform.ID) (*platform.Cell, error)
	FindCellsF    func(context.Context, platform.CellFilter) ([]*platform.Cell, int, error)
	UpdateCellF   func(context.Context, platform.ID, platform.CellUpdate) (*platform.Cell, error)
	DeleteCellF   func(context.Context, platform.ID) error
}

func (*CellService) CreateCell

func (s *CellService) CreateCell(ctx context.Context, b *platform.Cell) error

func (*CellService) DeleteCell

func (s *CellService) DeleteCell(ctx context.Context, id platform.ID) error

func (*CellService) FindCellByID

func (s *CellService) FindCellByID(ctx context.Context, id platform.ID) (*platform.Cell, error)

func (*CellService) FindCells

func (s *CellService) FindCells(ctx context.Context, filter platform.CellFilter) ([]*platform.Cell, int, error)

func (*CellService) UpdateCell

func (s *CellService) UpdateCell(ctx context.Context, id platform.ID, upd platform.CellUpdate) (*platform.Cell, error)

type ConfigStore

type ConfigStore struct {
	Config *cmp.Config
}

ConfigStore stores global application configuration

func (ConfigStore) Get

func (c ConfigStore) Get(ctx context.Context) (*cmp.Config, error)

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 *cmp.Config) error

Update updates the whole global application configuration

type DashboardService

type DashboardService struct {
	CreateDashboardF   func(context.Context, *platform.Dashboard) error
	FindDashboardByIDF func(context.Context, platform.ID) (*platform.Dashboard, error)
	FindDashboardsF    func(context.Context, platform.DashboardFilter) ([]*platform.Dashboard, int, error)
	UpdateDashboardF   func(context.Context, platform.ID, platform.DashboardUpdate) (*platform.Dashboard, error)
	DeleteDashboardF   func(context.Context, platform.ID) error
}

DashboardService ...

func (*DashboardService) CreateDashboard

func (s *DashboardService) CreateDashboard(ctx context.Context, b *platform.Dashboard) error

CreateDashboard ...

func (*DashboardService) DeleteDashboard

func (s *DashboardService) DeleteDashboard(ctx context.Context, id platform.ID) error

DeleteDashboard ...

func (*DashboardService) FindDashboardByID

func (s *DashboardService) FindDashboardByID(ctx context.Context, id platform.ID) (*platform.Dashboard, error)

FindDashboardByID ...

func (*DashboardService) FindDashboards

func (s *DashboardService) FindDashboards(ctx context.Context, filter platform.DashboardFilter) ([]*platform.Dashboard, int, error)

FindDashboards ...

func (*DashboardService) UpdateDashboard

UpdateDashboard ...

type DashboardsStore

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

DashboardsStore mock allows all functions to be set for testing

func (*DashboardsStore) Add

func (d *DashboardsStore) Add(ctx context.Context, newDashboard cmp.Dashboard) (cmp.Dashboard, error)

Add ...

func (*DashboardsStore) All

func (d *DashboardsStore) All(ctx context.Context) ([]cmp.Dashboard, error)

All ...

func (*DashboardsStore) Delete

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

Delete ...

func (*DashboardsStore) Get

Get ...

func (*DashboardsStore) Update

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

Update ...

type Databases

type Databases struct {
	AllDBF    func(context.Context) ([]cmp.Database, error)
	ConnectF  func(context.Context, *cmp.Source) error
	CreateDBF func(context.Context, *cmp.Database) (*cmp.Database, error)
	DropDBF   func(context.Context, string) error

	AllRPF    func(context.Context, string) ([]cmp.RetentionPolicy, error)
	CreateRPF func(context.Context, string, *cmp.RetentionPolicy) (*cmp.RetentionPolicy, error)
	UpdateRPF func(context.Context, string, string, *cmp.RetentionPolicy) (*cmp.RetentionPolicy, error)
	DropRPF   func(context.Context, string, string) error

	GetMeasurementsF func(ctx context.Context, db string, limit, offset int) ([]cmp.Measurement, error)
}

Databases mock allows all databases methods to be set for testing

func (*Databases) AllDB

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

AllDB lists all databases in the current data source

func (*Databases) AllRP

func (d *Databases) AllRP(ctx context.Context, rpX string) ([]cmp.RetentionPolicy, error)

AllRP lists all retention policies in the current data source

func (*Databases) Connect

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

Connect connects to a database in the current data source

func (*Databases) CreateDB

func (d *Databases) CreateDB(ctx context.Context, db *cmp.Database) (*cmp.Database, error)

CreateDB creates a database in the current data source

func (*Databases) CreateRP

func (d *Databases) CreateRP(ctx context.Context, rpX string, rp *cmp.RetentionPolicy) (*cmp.RetentionPolicy, error)

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) ([]cmp.Measurement, error)

GetMeasurements lists measurements in the current data source

func (*Databases) UpdateRP

func (d *Databases) UpdateRP(ctx context.Context, rpX string, rpY string, rp *cmp.RetentionPolicy) (*cmp.RetentionPolicy, error)

UpdateRP updates a retention policy in the current data source

type KapaClient

type KapaClient struct {
	CreateTaskF func(opts client.CreateTaskOptions) (client.Task, error)
	DeleteTaskF func(link client.Link) error
	ListTasksF  func(opts *client.ListTasksOptions) ([]client.Task, error)
	TaskF       func(link client.Link, opts *client.TaskOptions) (client.Task, error)
	UpdateTaskF func(link client.Link, opts client.UpdateTaskOptions) (client.Task, error)
}

Client is a mock Kapacitor client

func (*KapaClient) CreateTask

func (p *KapaClient) CreateTask(opts client.CreateTaskOptions) (client.Task, error)

func (*KapaClient) DeleteTask

func (p *KapaClient) DeleteTask(link client.Link) error

func (*KapaClient) ListTasks

func (p *KapaClient) ListTasks(opts *client.ListTasksOptions) ([]client.Task, error)

func (*KapaClient) Task

func (p *KapaClient) Task(link client.Link, opts *client.TaskOptions) (client.Task, error)

func (*KapaClient) UpdateTask

func (p *KapaClient) UpdateTask(link client.Link, opts client.UpdateTaskOptions) (client.Task, error)

type LayoutsStore

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

func (*LayoutsStore) Add

func (s *LayoutsStore) Add(ctx context.Context, layout cmp.Layout) (cmp.Layout, error)

func (*LayoutsStore) All

func (s *LayoutsStore) All(ctx context.Context) ([]cmp.Layout, error)

func (*LayoutsStore) Delete

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

func (*LayoutsStore) Get

func (s *LayoutsStore) Get(ctx context.Context, id string) (cmp.Layout, error)

func (*LayoutsStore) Update

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

type LogMessage

type LogMessage struct {
	Level string
	Body  string
}

LogMessage is for test

type MappingsStore

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

func (*MappingsStore) Add

func (s *MappingsStore) Add(ctx context.Context, m *cmp.Mapping) (*cmp.Mapping, error)

func (*MappingsStore) All

func (s *MappingsStore) All(ctx context.Context) ([]cmp.Mapping, error)

func (*MappingsStore) Delete

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

func (*MappingsStore) Get

func (s *MappingsStore) Get(ctx context.Context, id string) (*cmp.Mapping, error)

func (*MappingsStore) Update

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

type OrganizationConfigStore

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

func (*OrganizationConfigStore) FindOrCreate

func (*OrganizationConfigStore) Put

type OrganizationsStore

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

OrganizationsStore ...

func (*OrganizationsStore) Add

Add ...

func (*OrganizationsStore) All

All ...

func (*OrganizationsStore) CreateDefault

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

CreateDefault ...

func (*OrganizationsStore) DefaultOrganization

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

DefaultOrganization ...

func (*OrganizationsStore) Delete

Delete ...

func (*OrganizationsStore) Get

Get ...

func (*OrganizationsStore) Update

Update ...

type ProtoboardsStore

type ProtoboardsStore struct {
	AllF func(ctx context.Context) ([]cmp.Protoboard, error)
	GetF func(ctx context.Context, id string) (cmp.Protoboard, error)
}

func (*ProtoboardsStore) All

func (*ProtoboardsStore) Get

type Response

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

Response is a mocked cmp.Response

func NewResponse

func NewResponse(res string, err error) *Response

NewResponse returns a mocked cmp.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) ([]cmp.Role, error)
	AddF    func(context.Context, *cmp.Role) (*cmp.Role, error)
	DeleteF func(context.Context, *cmp.Role) error
	GetF    func(ctx context.Context, name string) (*cmp.Role, error)
	UpdateF func(context.Context, *cmp.Role) error
}

RolesStore mock allows all functions to be set for testing

func (*RolesStore) Add

func (s *RolesStore) Add(ctx context.Context, u *cmp.Role) (*cmp.Role, error)

Add a new Role in the RolesStore

func (*RolesStore) All

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

All lists all Roles from the RolesStore

func (*RolesStore) Delete

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

Delete the Role from the RolesStore

func (*RolesStore) Get

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

Get retrieves a Role if name exists.

func (*RolesStore) Update

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

Update the Role's permissions or users

type ServersStore

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

ServersStore mock allows all functions to be set for testing

func (*ServersStore) Add

func (s *ServersStore) Add(ctx context.Context, srv cmp.Server) (cmp.Server, error)

Add ...

func (*ServersStore) All

func (s *ServersStore) All(ctx context.Context) ([]cmp.Server, error)

All ...

func (*ServersStore) Delete

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

Delete ...

func (*ServersStore) Get

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

Get ...

func (*ServersStore) Update

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

Update ...

type SourcesStore

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

SourcesStore mock allows all functions to be set for testing

func (*SourcesStore) Add

func (s *SourcesStore) Add(ctx context.Context, src cmp.Source) (cmp.Source, error)

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

func (*SourcesStore) All

func (s *SourcesStore) All(ctx context.Context) ([]cmp.Source, error)

All returns all sources in the store

func (*SourcesStore) Delete

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

Delete the Source from the store

func (*SourcesStore) Get

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

Get retrieves Source if `ID` exists

func (*SourcesStore) Update

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

Update the Source in the store.

type Store

type Store struct {
	SourcesStore            cmp.SourcesStore
	MappingsStore           cmp.MappingsStore
	ServersStore            cmp.ServersStore
	LayoutsStore            cmp.LayoutsStore
	ProtoboardsStore        cmp.ProtoboardsStore
	UsersStore              cmp.UsersStore
	DashboardsStore         cmp.DashboardsStore
	OrganizationsStore      cmp.OrganizationsStore
	ConfigStore             cmp.ConfigStore
	OrganizationConfigStore cmp.OrganizationConfigStore
	CellService             platform.CellService
	DashboardService        platform.DashboardService
}

Store is a server.DataStore

func (*Store) Cells

func (s *Store) Cells(ctx context.Context) platform.CellService

func (*Store) Config

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

func (*Store) Dashboards

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

func (*Store) DashboardsV2

func (s *Store) DashboardsV2(ctx context.Context) platform.DashboardService

func (*Store) Layouts

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

func (*Store) Mappings

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

func (*Store) OrganizationConfig

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

func (*Store) Organizations

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

func (*Store) Protoboards

func (s *Store) Protoboards(ctx context.Context) cmp.ProtoboardsStore

func (*Store) Servers

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

func (*Store) Sources

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

func (*Store) Users

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

type TestLogger

type TestLogger struct {
	Messages []LogMessage
}

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

func (*TestLogger) Debug

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

Debug is for test

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{})

Error is for test

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{})

Info is for test

func (*TestLogger) WithField

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

WithField is for test

func (*TestLogger) Writer

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

Writer is for test

type TimeSeries

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

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

func (*TimeSeries) Connect

func (t *TimeSeries) Connect(ctx context.Context, src *cmp.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) cmp.Permissions

Permissions returns all valid names permissions in this database

func (*TimeSeries) Query

func (t *TimeSeries) Query(ctx context.Context, query cmp.Query) (cmp.Response, error)

Query retrieves time series data from the database.

func (*TimeSeries) Roles

func (t *TimeSeries) Roles(ctx context.Context) (cmp.RolesStore, error)

Roles represents the roles. Roles group permissions and Users

func (*TimeSeries) Users

func (t *TimeSeries) Users(ctx context.Context) cmp.UsersStore

Users represents the user accounts within the TimeSeries database

func (*TimeSeries) Write

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

Write records a point into the time series

type UsersStore

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

UsersStore mock allows all functions to be set for testing

func (*UsersStore) Add

func (s *UsersStore) Add(ctx context.Context, u *cmp.User) (*cmp.User, error)

Add a new User in the UsersStore

func (*UsersStore) All

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

All lists all users from the UsersStore

func (*UsersStore) Delete

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

Delete the User from the UsersStore

func (*UsersStore) Get

func (s *UsersStore) Get(ctx context.Context, q cmp.UserQuery) (*cmp.User, error)

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 *cmp.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