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: 16 Imported by: 0

Documentation

Overview

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

import reader_test "github.com/arsham/expvastic/reader/testing"

func TestExpvar(t *testing.T) {
	reader_testing.TestReader(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 TestReader added in v0.7.0

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

TestReader runs all essential tests on object construction.

Types

type Config added in v0.7.0

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

Config is used for instantiating a mock reader

func NewConfig added in v0.7.0

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

NewConfig returns a mocked version of the Config

func (*Config) Backoff added in v0.7.0

func (c *Config) Backoff() int

Backoff returns the backoff

func (*Config) Endpoint added in v0.7.0

func (c *Config) Endpoint() string

Endpoint returns the endpoint

func (*Config) Interval added in v0.7.0

func (c *Config) Interval() time.Duration

Interval returns the interval

func (*Config) Logger added in v0.7.0

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

Logger returns the logger

func (*Config) Name added in v0.7.0

func (c *Config) Name() string

Name returns the name

func (*Config) NewInstance added in v0.7.0

func (c *Config) NewInstance(ctx context.Context) (reader.DataReader, error)

NewInstance returns a mocked version of the config

func (*Config) RoutePath added in v0.7.0

func (c *Config) RoutePath() string

RoutePath returns the routepath

func (*Config) Timeout added in v0.7.0

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

Timeout returns the timeout

func (*Config) TypeName added in v0.7.0

func (c *Config) TypeName() string

TypeName returns the typename

type Constructor added in v0.7.0

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

	// SetTypename is for setting the Typename
	SetTypename(string)

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

	// SetInterval is for setting the Interval
	SetInterval(time.Duration)

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

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

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

	// Object should return the instantiated object
	Object() (reader.DataReader, error)
}

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

type Reader added in v0.7.0

type Reader struct {
	ReadFunc func(*token.Context) (*reader.Result, error)
	Pinged   bool
	// contains filtered or unexported fields
}

Reader is useful for testing purposes.

func GetReader added in v0.7.0

func GetReader(url string) *Reader

GetReader provides a SimpleReader for using in the example.

func New added in v0.7.0

func New(log logrus.FieldLogger, endpoint string, name, typeName string, interval, timeout time.Duration, backoff int) (*Reader, error)

New is a reader for using in tests

func (*Reader) Interval added in v0.7.0

func (s *Reader) Interval() time.Duration

Interval returns the interval

func (*Reader) Mapper added in v0.7.0

func (s *Reader) Mapper() datatype.Mapper

Mapper returns the mapper

func (*Reader) Name added in v0.7.0

func (s *Reader) Name() string

Name returns the name

func (*Reader) Ping added in v0.7.0

func (s *Reader) Ping() error

Ping pings the endpoint and return nil if was successful.

func (*Reader) Read added in v0.7.0

func (s *Reader) Read(job *token.Context) (*reader.Result, error)

Read executes the ReadFunc if defined, otherwise continues normally

func (*Reader) Timeout added in v0.7.0

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

Timeout returns the timeout

func (*Reader) TypeName added in v0.7.0

func (s *Reader) TypeName() string

TypeName returns the type name

Jump to

Keyboard shortcuts

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