mocks

package
v0.0.0-...-a385994 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: AGPL-3.0, AGPL-3.0-or-later Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger() cloudhub.Logger

NewLogger returns a mock logger that implements cloudhub.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 *cloudhub.Config
}

ConfigStore stores global application configuration

func (ConfigStore) All

func (c ConfigStore) All(ctx context.Context) ([]cloudhub.Config, error)

All ...

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

Update updates the whole global application configuration

type DashboardsStore

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

DashboardsStore mock allows all functions to be set for testing

func (*DashboardsStore) Add

Add ...

func (*DashboardsStore) All

All ...

func (*DashboardsStore) Delete

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

Delete ...

func (*DashboardsStore) Get

Get ...

func (*DashboardsStore) Update

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

Update ...

type Databases

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

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

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

Databases mock allows all databases methods to be set for testing

func (*Databases) AllDB

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

AllDB lists all databases in the current data source

func (*Databases) AllRP

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

AllRP lists all retention policies in the current data source

func (*Databases) Connect

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

Connect connects to a database in the current data source

func (*Databases) CreateDB

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

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

GetMeasurements lists measurements in the current data source

func (*Databases) UpdateRP

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

KapaClient Client is a mock Kapacitor client

func (*KapaClient) CreateTask

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

CreateTask ...

func (*KapaClient) DeleteTask

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

DeleteTask ...

func (*KapaClient) ListTasks

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

ListTasks ...

func (*KapaClient) Task

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

Task ...

func (*KapaClient) UpdateTask

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

UpdateTask ...

type LayoutsStore

type LayoutsStore struct {
	AllF func(ctx context.Context) ([]cloudhub.Layout, error)
	GetF func(ctx context.Context, id string) (cloudhub.Layout, error)
}

LayoutsStore ...

func (*LayoutsStore) All

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

All ...

func (*LayoutsStore) Get

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

Get ...

type LogMessage

type LogMessage struct {
	Level string
	Body  string
}

LogMessage is for test

type MappingsStore

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

MappingsStore ...

func (*MappingsStore) Add

Add ...

func (*MappingsStore) All

All ...

func (*MappingsStore) Delete

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

Delete ...

func (*MappingsStore) Get

Get ...

func (*MappingsStore) Update

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

Update ...

type OrganizationConfigStore

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

OrganizationConfigStore ...

func (*OrganizationConfigStore) All

All ...

func (*OrganizationConfigStore) FindOrCreate

FindOrCreate ...

func (*OrganizationConfigStore) Put

Put ...

type OrganizationsStore

type OrganizationsStore struct {
	AllF                 func(context.Context) ([]cloudhub.Organization, error)
	AddF                 func(context.Context, *cloudhub.Organization) (*cloudhub.Organization, error)
	DeleteF              func(context.Context, *cloudhub.Organization) error
	GetF                 func(ctx context.Context, q cloudhub.OrganizationQuery) (*cloudhub.Organization, error)
	UpdateF              func(context.Context, *cloudhub.Organization) error
	CreateDefaultF       func(context.Context) error
	DefaultOrganizationF func(context.Context) (*cloudhub.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) (*cloudhub.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) ([]cloudhub.Protoboard, error)
	GetF func(ctx context.Context, id string) (cloudhub.Protoboard, error)
}

ProtoboardsStore ...

func (*ProtoboardsStore) All

All ...

func (*ProtoboardsStore) Get

Get ...

type Response

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

Response is a mocked cloudhub.Response

func NewResponse

func NewResponse(res string, err error) *Response

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

RolesStore mock allows all functions to be set for testing

func (*RolesStore) Add

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

Add a new Role in the RolesStore

func (*RolesStore) All

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

All lists all Roles from the RolesStore

func (*RolesStore) Delete

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

Delete the Role from the RolesStore

func (*RolesStore) Get

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

Get retrieves a Role if name exists.

func (*RolesStore) Update

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

Update the Role's permissions or users

type ServersStore

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

ServersStore mock allows all functions to be set for testing

func (*ServersStore) Add

Add ...

func (*ServersStore) All

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

All ...

func (*ServersStore) Delete

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

Delete ...

func (*ServersStore) Get

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

Get ...

func (*ServersStore) Update

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

Update ...

type SourcesStore

type SourcesStore struct {
	AllF    func(context.Context) ([]cloudhub.Source, error)
	AddF    func(context.Context, cloudhub.Source) (cloudhub.Source, error)
	DeleteF func(context.Context, cloudhub.Source) error
	GetF    func(ctx context.Context, ID int) (cloudhub.Source, error)
	UpdateF func(context.Context, cloudhub.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

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

All returns all sources in the store

func (*SourcesStore) Delete

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

Delete the Source from the store

func (*SourcesStore) Get

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

Get retrieves Source if `ID` exists

func (*SourcesStore) Update

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

Update the Source in the store.

type Store

type Store struct {
	SourcesStore            cloudhub.SourcesStore
	MappingsStore           cloudhub.MappingsStore
	ServersStore            cloudhub.ServersStore
	LayoutsStore            cloudhub.LayoutsStore
	ProtoboardsStore        cloudhub.ProtoboardsStore
	UsersStore              cloudhub.UsersStore
	DashboardsStore         cloudhub.DashboardsStore
	OrganizationsStore      cloudhub.OrganizationsStore
	ConfigStore             cloudhub.ConfigStore
	OrganizationConfigStore cloudhub.OrganizationConfigStore
	VspheresStore           cloudhub.VspheresStore
}

Store is a server.DataStore

func (*Store) Config

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

Config ...

func (*Store) Dashboards

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

Dashboards ...

func (*Store) Layouts

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

Layouts ...

func (*Store) Mappings

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

Mappings ...

func (*Store) OrganizationConfig

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

OrganizationConfig ...

func (*Store) Organizations

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

Organizations ...

func (*Store) Protoboards

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

Protoboards ...

func (*Store) Servers

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

Servers ...

func (*Store) Sources

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

Sources ...

func (*Store) Users

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

Users ...

func (*Store) Vspheres

func (s *Store) Vspheres(ctx context.Context) cloudhub.VspheresStore

Vspheres ...

type TestLogger

type TestLogger struct {
	Messages []LogMessage
}

TestLogger is a cloudhub.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{}) cloudhub.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, *cloudhub.Source) error
	// Query retrieves time series data from the database.
	QueryF func(context.Context, cloudhub.Query) (cloudhub.Response, error)
	// Write records points into the TimeSeries
	WriteF func(context.Context, []cloudhub.Point) error
	// UsersStore represents the user accounts within the TimeSeries database
	UsersF func(context.Context) cloudhub.UsersStore
	// Permissions returns all valid names permissions in this database
	PermissionsF func(context.Context) cloudhub.Permissions
	// RolesF represents the roles. Roles group permissions and Users
	RolesF func(context.Context) (cloudhub.RolesStore, error)
}

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

func (*TimeSeries) Connect

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

Permissions returns all valid names permissions in this database

func (*TimeSeries) Query

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

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 []cloudhub.Point) error

Write records a point into the time series

type UsersStore

type UsersStore struct {
	AllF    func(context.Context) ([]cloudhub.User, error)
	AddF    func(context.Context, *cloudhub.User) (*cloudhub.User, error)
	DeleteF func(context.Context, *cloudhub.User) error
	GetF    func(ctx context.Context, q cloudhub.UserQuery) (*cloudhub.User, error)
	UpdateF func(context.Context, *cloudhub.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 *cloudhub.User) (*cloudhub.User, error)

Add a new User in the UsersStore

func (*UsersStore) All

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

All lists all users from the UsersStore

func (*UsersStore) Delete

func (s *UsersStore) Delete(ctx context.Context, u *cloudhub.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 *cloudhub.User) error

Update the user's permissions or roles

type VspheresStore

type VspheresStore struct {
	AllF    func(context.Context) ([]cloudhub.Vsphere, error)
	AddF    func(context.Context, cloudhub.Vsphere) (cloudhub.Vsphere, error)
	DeleteF func(context.Context, cloudhub.Vsphere) error
	GetF    func(context.Context, string) (cloudhub.Vsphere, error)
	UpdateF func(context.Context, cloudhub.Vsphere) error
}

VspheresStore mock allows all functions to be set for testing

func (*VspheresStore) Add

Add ...

func (*VspheresStore) All

All ...

func (*VspheresStore) Delete

func (s *VspheresStore) Delete(ctx context.Context, vs cloudhub.Vsphere) error

Delete ...

func (*VspheresStore) Get

Get ...

func (*VspheresStore) Update

func (s *VspheresStore) Update(ctx context.Context, vs cloudhub.Vsphere) error

Update ...

Jump to

Keyboard shortcuts

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