testing

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package testing is a test suit for recorders. They should provide an object that implements the Constructor interface then run:

import recorder_test "github.com/arsham/expvastic/recorder/testing"

func TestElasticsearch(t *testing.T) {
	recorder_testing.TestRecorder(t, &Construct{})
}

The test suit will pick it up and does all the tests.

Important Note

You need to write the edge cases if they are not covered in this section.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestRecorder added in v0.7.0

func TestRecorder(t *testing.T, cons Constructor)

TestRecorder runs all essential tests on object construction.

Types

type Config added in v0.7.0

type Config struct {
	MockName      string
	MockEndpoint  string
	MockTimeout   time.Duration
	MockBackoff   int
	MockIndexName string
	MockLogger    logrus.FieldLogger
}

Config holds the necessary configuration for setting up an elasticsearch reader endpoint.

func NewConfig added in v0.7.0

func NewConfig(name string, log logrus.FieldLogger, endpoint string, timeout time.Duration, backoff int, indexName string) (*Config, error)

NewConfig returns a mocked object

func (*Config) Backoff added in v0.7.0

func (m *Config) Backoff() int

Backoff is the mocked version

func (*Config) Endpoint added in v0.7.0

func (m *Config) Endpoint() string

Endpoint is the mocked version

func (*Config) IndexName added in v0.7.0

func (m *Config) IndexName() string

IndexName is the mocked version

func (*Config) Logger added in v0.7.0

func (m *Config) Logger() logrus.FieldLogger

Logger is the mocked version

func (*Config) Name added in v0.7.0

func (m *Config) Name() string

Name is the mocked version

func (*Config) NewInstance added in v0.7.0

func (m *Config) NewInstance(ctx context.Context) (recorder.DataRecorder, error)

NewInstance returns a mocked object

func (*Config) RoutePath added in v0.7.0

func (m *Config) RoutePath() string

RoutePath is the mocked version

func (*Config) Timeout added in v0.7.0

func (m *Config) Timeout() time.Duration

Timeout is the mocked version

type Constructor added in v0.7.0

type Constructor interface {
	// SetName is for setting the Name
	SetName(string)

	// SetIndexName is for setting the IndexName
	SetIndexName(string)

	// SetEndpoint is for setting the Endpoint
	SetEndpoint(string)

	// SetTimeout is for setting the Timeout
	SetTimeout(time.Duration)

	// SetBackoff is for setting the Backoff
	SetBackoff(int)

	// ValidEndpoints should return a list of valid endpoints
	ValidEndpoints() []string

	// InvalidEndpoints should return a list of invalid endpoints
	InvalidEndpoints() []string

	// TestServer should return a ready to use test server
	TestServer() *httptest.Server

	// Object should return the instantiated object
	Object() (recorder.DataRecorder, error)
}

Constructor is an interface for setting up an object for testing.

type Recorder added in v0.7.0

type Recorder struct {
	ErrorFunc func() error

	Smu        sync.RWMutex
	RecordFunc func(context.Context, *recorder.Job) error
	Pinged     bool
	// contains filtered or unexported fields
}

Recorder is designed to be used in tests.

func GetRecorder added in v0.7.0

func GetRecorder(ctx context.Context, url string) *Recorder

GetRecorder provides a SimpleRecorder for using in the example.

func New added in v0.7.0

func New(ctx context.Context, log logrus.FieldLogger, name, endpoint, indexName string, timeout time.Duration, backoff int) (*Recorder, error)

New returns a Recorder instance.

func (*Recorder) IndexName added in v0.7.0

func (s *Recorder) IndexName() string

IndexName returns the indexname

func (*Recorder) Name added in v0.7.0

func (s *Recorder) Name() string

Name returns the name

func (*Recorder) Ping added in v0.7.0

func (s *Recorder) Ping() error

Ping pings the endpoint and return nil if was successful.

func (*Recorder) Record added in v0.7.0

func (s *Recorder) Record(ctx context.Context, job *recorder.Job) error

Record calls the RecordFunc if exists, otherwise continues as normal

func (*Recorder) Timeout added in v0.7.0

func (s *Recorder) Timeout() time.Duration

Timeout returns the timeout

Jump to

Keyboard shortcuts

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